1 /* $NetBSD: suff.c,v 1.247 2020/11/16 23:27:41 rillig Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * Copyright (c) 1989 by Berkeley Softworks
37 * All rights reserved.
39 * This code is derived from software contributed to Berkeley by
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * Maintain suffix lists and find implicit dependents using suffix
73 * transformation rules such as ".c.o".
76 * Suff_Init Initialize the module.
78 * Suff_End Clean up the module.
80 * Suff_DoPaths Extend the search path of each suffix to include the
81 * default search path.
84 * Clear out all the suffixes and transformations.
87 * See if the passed string is a transformation rule.
89 * Suff_AddSuffix Add the passed string as another known suffix.
91 * Suff_GetPath Return the search path for the given suffix.
94 * Mark the given suffix as denoting an include file.
96 * Suff_AddLib Mark the given suffix as denoting a library.
99 * Add another transformation to the suffix graph.
101 * Suff_SetNull Define the suffix to consider the suffix of
102 * any file that doesn't have a known one.
104 * Suff_FindDeps Find implicit sources for and the location of
105 * a target based on its suffix. Returns the
106 * bottom-most node added to the graph or NULL
107 * if the target had no implicit sources.
109 * Suff_FindPath Return the appropriate path to search in order to
116 /* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
117 MAKE_RCSID("$NetBSD: suff.c,v 1.247 2020/11/16 23:27:41 rillig Exp $");
119 #define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
120 #define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
121 #define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2)
123 typedef List SuffList;
124 typedef ListNode SuffListNode;
126 typedef List SrcList;
127 typedef ListNode SrcListNode;
129 static SuffList *sufflist; /* List of suffixes */
131 static SuffList *suffClean; /* List of suffixes to be cleaned */
133 static SrcList *srclist; /* List of sources */
135 /* List of transformation rules, such as ".c.o" */
136 static GNodeList *transforms;
138 static int sNum = 0; /* Counter for assigning suffix numbers */
140 typedef enum SuffFlags {
141 SUFF_INCLUDE = 0x01, /* One which is #include'd */
142 SUFF_LIBRARY = 0x02, /* One which contains a library */
143 SUFF_NULL = 0x04 /* The empty suffix */
144 /* XXX: Why is SUFF_NULL needed? Wouldn't nameLen == 0 mean the same? */
147 ENUM_FLAGS_RTTI_3(SuffFlags,
148 SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL);
150 typedef List SuffListList;
152 typedef struct Suff {
153 /* The suffix itself, such as ".c" */
155 /* Length of the name, to avoid strlen calls */
159 /* The path along which files of this suffix may be found */
160 SearchPath *searchPath;
161 /* The suffix number; TODO: document the purpose of this number */
163 /* Reference count of list membership and several other places */
165 /* Suffixes we have a transformation to */
167 /* Suffixes we have a transformation from */
170 /* Lists in which this suffix is referenced.
171 * XXX: These lists are used nowhere, they are just appended to, for no
172 * apparent reason. They do have the side effect of increasing refCount
178 * Structure used in the search for implied sources.
181 char *file; /* The file to look for */
182 char *pref; /* Prefix from which file was formed */
183 Suff *suff; /* The suffix on the file */
184 struct Src *parent; /* The Src for which this is a source */
185 GNode *node; /* The node describing the file */
186 int numChildren; /* Count of existing children (so we don't free
187 * this thing too early or never nuke it) */
189 SrcList *childrenList;
193 /* TODO: Document the difference between suffNull and emptySuff. */
194 /* The NULL suffix for this run */
195 static Suff *suffNull;
196 /* The empty suffix required for POSIX single-suffix transformation rules */
197 static Suff *emptySuff;
200 static void SuffFindDeps(GNode *, SrcList *);
201 static void SuffExpandWildcards(GNodeListNode *, GNode *);
204 * See if pref is a prefix of str.
205 * Return NULL if it ain't, pointer to character in str after prefix if so.
208 SuffStrIsPrefix(const char *pref, const char *str)
210 while (*str && *pref == *str) {
215 return *pref != '\0' ? NULL : str;
219 * See if suff is a suffix of name.
220 * Return NULL if it ain't, pointer to the start of suffix in name if it is.
223 SuffSuffGetSuffix(const Suff *s, size_t nameLen, const char *nameEnd)
225 const char *p1; /* Pointer into suffix name */
226 const char *p2; /* Pointer into string being examined */
228 if (nameLen < s->nameLen)
229 return NULL; /* this string is shorter than the suffix */
231 p1 = s->name + s->nameLen;
234 while (p1 >= s->name && *p1 == *p2) {
239 /* XXX: s->name - 1 invokes undefined behavior */
240 return p1 == s->name - 1 ? p2 + 1 : NULL;
244 SuffSuffIsSuffix(const Suff *suff, size_t nameLen, const char *nameEnd)
246 return SuffSuffGetSuffix(suff, nameLen, nameEnd) != NULL;
250 FindSuffByNameLen(const char *name, size_t nameLen)
254 for (ln = sufflist->first; ln != NULL; ln = ln->next) {
255 Suff *suff = ln->datum;
256 if (suff->nameLen == nameLen && memcmp(suff->name, name, nameLen) == 0)
263 FindSuffByName(const char *name)
265 return FindSuffByNameLen(name, strlen(name));
269 FindTransformByName(const char *name)
272 for (ln = transforms->first; ln != NULL; ln = ln->next) {
273 GNode *gn = ln->datum;
274 if (strcmp(gn->name, name) == 0)
281 SuffList_Unref(SuffList *list, Suff *suff)
283 SuffListNode *ln = Lst_FindDatum(list, suff);
285 Lst_Remove(list, ln);
290 /* Free up all memory associated with the given suffix structure. */
296 if (suff == suffNull)
299 if (suff == emptySuff)
303 /* We don't delete suffixes in order, so we cannot use this */
304 if (suff->refCount != 0)
305 Punt("Internal error deleting suffix `%s' with refcount = %d",
306 suff->name, suff->refCount);
310 Lst_Free(suff->children);
311 Lst_Free(suff->parents);
312 Lst_Destroy(suff->searchPath, Dir_Destroy);
318 /* Remove the suffix from the list, and free if it is otherwise unused. */
320 SuffList_Remove(SuffList *list, Suff *suff)
322 SuffList_Unref(list, suff);
323 if (suff->refCount == 0) {
324 /* XXX: can lead to suff->refCount == -1 */
325 SuffList_Unref(sufflist, suff);
330 /* Insert the suffix into the list, keeping the list ordered by suffix
333 SuffList_Insert(SuffList *list, Suff *suff)
336 Suff *listSuff = NULL;
338 for (ln = list->first; ln != NULL; ln = ln->next) {
339 listSuff = ln->datum;
340 if (listSuff->sNum >= suff->sNum)
345 SUFF_DEBUG2("inserting \"%s\" (%d) at end of list\n",
346 suff->name, suff->sNum);
347 Lst_Append(list, suff);
349 Lst_Append(suff->ref, list);
350 } else if (listSuff->sNum != suff->sNum) {
351 DEBUG4(SUFF, "inserting \"%s\" (%d) before \"%s\" (%d)\n",
352 suff->name, suff->sNum, listSuff->name, listSuff->sNum);
353 Lst_InsertBefore(list, ln, suff);
355 Lst_Append(suff->ref, list);
357 SUFF_DEBUG2("\"%s\" (%d) is already there\n", suff->name, suff->sNum);
362 SuffRelate(Suff *srcSuff, Suff *targSuff)
364 SuffList_Insert(targSuff->children, srcSuff);
365 SuffList_Insert(srcSuff->parents, targSuff);
369 SuffNew(const char *name)
371 Suff *suff = bmake_malloc(sizeof *suff);
373 suff->name = bmake_strdup(name);
374 suff->nameLen = strlen(suff->name);
375 suff->searchPath = Lst_New();
376 suff->children = Lst_New();
377 suff->parents = Lst_New();
378 suff->ref = Lst_New();
381 suff->refCount = 1; /* XXX: why 1? It's not assigned anywhere yet. */
387 * Nuke the list of suffixes but keep all transformation rules around. The
388 * transformation graph is destroyed in this process, but we leave the list
389 * of rules so when a new graph is formed, the rules will remain. This
390 * function is called when a line '.SUFFIXES:' with an empty suffixes list is
391 * encountered in a makefile.
394 Suff_ClearSuffixes(void)
397 Lst_MoveAll(suffClean, sufflist);
399 sufflist = Lst_New();
403 emptySuff = suffNull = SuffNew("");
405 Dir_Concat(suffNull->searchPath, dirSearchPath);
406 suffNull->flags = SUFF_NULL;
409 /* Parse a transformation string such as ".c.o" to find its two component
410 * suffixes (the source ".c" and the target ".o"). If there are no such
411 * suffixes, try a single-suffix transformation as well.
413 * Return TRUE if the string is a valid transformation.
416 SuffParseTransform(const char *str, Suff **out_src, Suff **out_targ)
419 Suff *singleSrc = NULL;
422 * Loop looking first for a suffix that matches the start of the
423 * string and then for one that exactly matches the rest of it. If
424 * we can find two that meet these criteria, we've successfully
427 for (ln = sufflist->first; ln != NULL; ln = ln->next) {
428 Suff *src = ln->datum;
430 if (SuffStrIsPrefix(src->name, str) == NULL)
433 if (str[src->nameLen] == '\0') {
436 Suff *targ = FindSuffByName(str + src->nameLen);
445 if (singleSrc != NULL) {
447 * Not so fast Mr. Smith! There was a suffix that encompassed
448 * the entire string, so we assume it was a transformation
449 * to the null suffix (thank you POSIX). We still prefer to
450 * find a double rule over a singleton, hence we leave this
451 * check until the end.
453 * XXX: Use emptySuff over suffNull?
455 *out_src = singleSrc;
456 *out_targ = suffNull;
462 /* Return TRUE if the given string is a transformation rule, that is, a
463 * concatenation of two known suffixes such as ".c.o" or a single suffix
466 Suff_IsTransform(const char *str)
470 return SuffParseTransform(str, &src, &targ);
473 /* Add the transformation rule to the list of rules and place the
474 * transformation itself in the graph.
476 * The transformation is linked to the two suffixes mentioned in the name.
479 * name must have the form ".from.to" or just ".from"
482 * The created or existing transformation node in the transforms list
485 Suff_AddTransform(const char *name)
490 GNode *gn = FindTransformByName(name);
493 * Make a new graph node for the transformation. It will be filled in
494 * by the Parse module.
496 gn = GNode_New(name);
497 Lst_Append(transforms, gn);
500 * New specification for transformation rule. Just nuke the old list
501 * of commands so they can be filled in again... We don't actually
502 * free the commands themselves, because a given command can be
503 * attached to several different transformations.
505 Lst_Free(gn->commands);
506 Lst_Free(gn->children);
507 gn->commands = Lst_New();
508 gn->children = Lst_New();
511 gn->type = OP_TRANSFORM;
514 Boolean ok = SuffParseTransform(name, &srcSuff, &targSuff);
520 * link the two together in the proper relationship and order
522 SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
523 srcSuff->name, targSuff->name);
524 SuffRelate(srcSuff, targSuff);
529 /* Handle the finish of a transformation definition, removing the
530 * transformation from the graph if it has neither commands nor sources.
532 * If the node has no commands or children, the children and parents lists
533 * of the affected suffixes are altered.
536 * gn Node for transformation
539 Suff_EndTransform(GNode *gn)
541 if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(gn->cohorts))
542 gn = gn->cohorts->last->datum;
544 if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) &&
545 Lst_IsEmpty(gn->children))
547 Suff *srcSuff, *targSuff;
550 * SuffParseTransform() may fail for special rules which are not
551 * actual transformation rules. (e.g. .DEFAULT)
553 if (SuffParseTransform(gn->name, &srcSuff, &targSuff)) {
556 * Remember parents since srcSuff could be deleted in
559 SuffList *srcSuffParents = srcSuff->parents;
561 SUFF_DEBUG2("deleting transformation from `%s' to `%s'\n",
562 srcSuff->name, targSuff->name);
564 SuffList_Remove(targSuff->children, srcSuff);
565 SuffList_Remove(srcSuffParents, targSuff);
567 } else if (gn->type & OP_TRANSFORM) {
568 SUFF_DEBUG1("transformation %s complete\n", gn->name);
572 /* Called from Suff_AddSuffix to search through the list of
573 * existing transformation rules and rebuild the transformation graph when
574 * it has been destroyed by Suff_ClearSuffixes. If the given rule is a
575 * transformation involving this suffix and another, existing suffix, the
576 * proper relationship is established between the two.
578 * The appropriate links will be made between this suffix and others if
579 * transformation rules exist for it.
582 * transform Transformation to test
583 * suff Suffix to rebuild
586 SuffRebuildGraph(GNode *transform, Suff *suff)
588 const char *name = transform->name;
589 size_t nameLen = strlen(name);
593 * First see if it is a transformation from this suffix.
595 toName = SuffStrIsPrefix(suff->name, name);
596 if (toName != NULL) {
597 Suff *to = FindSuffByName(toName);
599 /* Link in and return, since it can't be anything else. */
600 SuffRelate(suff, to);
606 * Not from, maybe to?
608 toName = SuffSuffGetSuffix(suff, nameLen, name + nameLen);
609 if (toName != NULL) {
610 Suff *from = FindSuffByNameLen(name, (size_t)(toName - name));
612 SuffRelate(from, suff);
616 /* During Suff_AddSuffix, search through the list of existing targets and find
617 * if any of the existing targets can be turned into a transformation rule.
619 * If such a target is found and the target is the current main target, the
620 * main target is set to NULL and the next target examined (if that exists)
621 * becomes the main target.
624 * TRUE iff a new main target has been selected.
627 SuffScanTargets(GNode *target, GNode **inout_main, Suff *gs_s, Boolean *gs_r)
629 Suff *srcSuff, *targSuff;
632 if (*inout_main == NULL && *gs_r && !(target->type & OP_NOTARGET)) {
633 *inout_main = target;
634 Targ_SetMain(target);
638 if (target->type == OP_TRANSFORM)
641 if ((ptr = strstr(target->name, gs_s->name)) == NULL ||
645 if (SuffParseTransform(target->name, &srcSuff, &targSuff)) {
646 if (*inout_main == target) {
651 Lst_Free(target->children);
652 target->children = Lst_New();
653 target->type = OP_TRANSFORM;
655 * link the two together in the proper relationship and order
657 SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
658 srcSuff->name, targSuff->name);
659 SuffRelate(srcSuff, targSuff);
664 /* Look at all existing targets to see if adding this suffix will make one
665 * of the current targets mutate into a suffix rule.
667 * This is ugly, but other makes treat all targets that start with a '.' as
670 UpdateTargets(GNode **inout_main, Suff *s)
674 for (ln = Targ_List()->first; ln != NULL; ln = ln->next) {
675 GNode *gn = ln->datum;
676 if (SuffScanTargets(gn, inout_main, s, &r))
681 /* Add the suffix to the end of the list of known suffixes.
682 * Should we restructure the suffix graph? Make doesn't...
684 * A GNode is created for the suffix and a Suff structure is created and
685 * added to the suffixes list unless the suffix was already known.
686 * The mainNode passed can be modified if a target mutated into a
687 * transform and that target happened to be the main target.
690 * name the name of the suffix to add
693 Suff_AddSuffix(const char *name, GNode **inout_main)
697 Suff *s = FindSuffByName(name);
702 Lst_Append(sufflist, s);
704 UpdateTargets(inout_main, s);
707 * Look for any existing transformations from or to this suffix.
708 * XXX: Only do this after a Suff_ClearSuffixes?
710 for (ln = transforms->first; ln != NULL; ln = ln->next)
711 SuffRebuildGraph(ln->datum, s);
714 /* Return the search path for the given suffix, or NULL. */
716 Suff_GetPath(const char *sname)
718 Suff *s = FindSuffByName(sname);
719 return s != NULL ? s->searchPath : NULL;
723 * Extend the search paths for all suffixes to include the default search
724 * path (dirSearchPath).
726 * The default search path can be defined using the special target '.PATH'.
727 * The search path of each suffix can be defined using the special target
730 * If paths were specified for the ".h" suffix, the directories are stuffed
731 * into a global variable called ".INCLUDES" with each directory preceded by
732 * '-I'. The same is done for the ".a" suffix, except the variable is called
733 * ".LIBS" and the flag is '-L'.
740 SearchPath *inIncludes; /* Cumulative .INCLUDES path */
741 SearchPath *inLibs; /* Cumulative .LIBS path */
743 inIncludes = Lst_New();
746 for (ln = sufflist->first; ln != NULL; ln = ln->next) {
748 if (!Lst_IsEmpty(s->searchPath)) {
750 if (s->flags & SUFF_INCLUDE)
751 Dir_Concat(inIncludes, s->searchPath);
754 if (s->flags & SUFF_LIBRARY)
755 Dir_Concat(inLibs, s->searchPath);
757 Dir_Concat(s->searchPath, dirSearchPath);
759 Lst_Destroy(s->searchPath, Dir_Destroy);
760 s->searchPath = Dir_CopyDirSearchPath();
764 Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
766 Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
769 Lst_Destroy(inIncludes, Dir_Destroy);
770 Lst_Destroy(inLibs, Dir_Destroy);
773 /* Add the given suffix as a type of file which gets included.
774 * Called from the parse module when a .INCLUDES line is parsed.
775 * The suffix must have already been defined.
776 * The SUFF_INCLUDE bit is set in the suffix's flags field.
779 * sname Name of the suffix to mark
782 Suff_AddInclude(const char *sname)
784 Suff *suff = FindSuffByName(sname);
786 suff->flags |= SUFF_INCLUDE;
789 /* Add the given suffix as a type of file which is a library.
790 * Called from the parse module when parsing a .LIBS line.
791 * The suffix must have been defined via .SUFFIXES before this is called.
792 * The SUFF_LIBRARY bit is set in the suffix's flags field.
795 * sname Name of the suffix to mark
798 Suff_AddLib(const char *sname)
800 Suff *suff = FindSuffByName(sname);
802 suff->flags |= SUFF_LIBRARY;
805 /********** Implicit Source Search Functions *********/
809 SrcList_PrintAddrs(SrcList *srcList)
812 for (ln = srcList->first; ln != NULL; ln = ln->next)
813 debug_printf(" %p", ln->datum);
819 SrcNew(char *name, char *pref, Suff *suff, Src *parent, GNode *gn)
821 Src *src = bmake_malloc(sizeof *src);
826 src->parent = parent;
828 src->numChildren = 0;
830 src->childrenList = Lst_New();
837 SuffAddSrc(Suff *suff, SrcList *srcList, Src *targ, char *srcName,
838 const char *debug_tag MAKE_ATTR_UNUSED)
840 Src *s2 = SrcNew(srcName, targ->pref, suff, targ, NULL);
843 Lst_Append(srcList, s2);
845 Lst_Append(targ->childrenList, s2);
846 debug_printf("%s add suff %p src %p to list %p:",
847 debug_tag, targ, s2, srcList);
848 SrcList_PrintAddrs(srcList);
852 /* Add a suffix as a Src structure to the given list with its parent
853 * being the given Src structure. If the suffix is the null suffix,
854 * the prefix is used unaltered as the filename in the Src structure.
857 * suff suffix for which to create a Src structure
858 * srcList list for the new Src
859 * targ parent for the new Src
862 SuffAddSources(Suff *suff, SrcList *srcList, Src *targ)
864 if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') {
866 * If the suffix has been marked as the NULL suffix, also create a Src
867 * structure for a file with no suffix attached. Two birds, and all
870 SuffAddSrc(suff, srcList, targ, bmake_strdup(targ->pref), "1");
872 SuffAddSrc(suff, srcList, targ, str_concat2(targ->pref, suff->name), "2");
875 /* Add all the children of targ to the list. */
877 SuffAddLevel(SrcList *srcs, Src *targ)
880 for (ln = targ->suff->children->first; ln != NULL; ln = ln->next) {
881 Suff *childSuff = ln->datum;
882 SuffAddSources(childSuff, srcs, targ);
886 /* Free the first Src in the list that is not referenced anymore.
887 * Return whether a Src was removed. */
889 SuffRemoveSrc(SrcList *l)
894 debug_printf("cleaning list %p:", l);
895 SrcList_PrintAddrs(l);
898 for (ln = l->first; ln != NULL; ln = ln->next) {
899 Src *src = ln->datum;
901 if (src->numChildren == 0) {
903 if (src->parent == NULL)
907 SrcListNode *ln2 = Lst_FindDatum(src->parent->childrenList, src);
909 Lst_Remove(src->parent->childrenList, ln2);
911 src->parent->numChildren--;
914 debug_printf("free: list %p src %p children %d\n",
915 l, src, src->children);
916 Lst_Free(src->childrenList);
924 debug_printf("keep: list %p src %p children %d:",
925 l, src, src->children);
926 SrcList_PrintAddrs(src->childrenList);
934 /* Find the first existing file/target in srcs. */
936 SuffFindThem(SrcList *srcs, SrcList *slst)
940 while (!Lst_IsEmpty(srcs)) {
941 Src *src = Lst_Dequeue(srcs);
943 SUFF_DEBUG1("\ttrying %s...", src->file);
946 * A file is considered to exist if either a node exists in the
947 * graph for it or the file actually exists.
949 if (Targ_FindNode(src->file) != NULL) {
951 debug_printf("remove from list %p src %p\n", srcs, src);
958 char *file = Dir_FindFile(src->file, src->suff->searchPath);
962 debug_printf("remove from list %p src %p\n", srcs, src);
969 SUFF_DEBUG0("not there\n");
971 SuffAddLevel(srcs, src);
972 Lst_Append(slst, src);
976 SUFF_DEBUG0("got it\n");
981 /* See if any of the children of the target in the Src structure is one from
982 * which the target can be transformed. If there is one, a Src structure is
983 * put together for it and returned.
986 * targ Src to play with
989 * The Src of the "winning" child, or NULL.
992 SuffFindCmds(Src *targ, SrcList *slst)
995 GNode *tgn; /* Target GNode */
996 GNode *sgn; /* Source GNode */
997 size_t prefLen; /* The length of the defined prefix */
998 Suff *suff; /* Suffix on matching beastie */
999 Src *ret; /* Return value */
1003 prefLen = strlen(targ->pref);
1005 for (gln = tgn->children->first; gln != NULL; gln = gln->next) {
1008 if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(tgn->commands)) {
1010 * We haven't looked to see if .OPTIONAL files exist yet, so
1011 * don't use one as the implicit source.
1012 * This allows us to use .OPTIONAL in .depend files so make won't
1013 * complain "don't know how to make xxx.h' when a dependent file
1014 * has been moved/deleted.
1019 cp = strrchr(sgn->name, '/');
1025 if (strncmp(cp, targ->pref, prefLen) != 0)
1027 /* The node matches the prefix ok, see if it has a known suffix. */
1028 suff = FindSuffByName(cp + prefLen);
1033 * It even has a known suffix, see if there's a transformation
1034 * defined between the node's suffix and the target's suffix.
1036 * XXX: Handle multi-stage transformations here, too.
1039 /* XXX: Can targ->suff be NULL here? */
1040 if (targ->suff != NULL &&
1041 Lst_FindDatum(suff->parents, targ->suff) != NULL)
1049 * Hot Damn! Create a new Src structure to describe
1050 * this transformation (making sure to duplicate the
1051 * source node's name so Suff_FindDeps can free it
1052 * again (ick)), and return the new structure.
1054 ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn);
1056 targ->numChildren++;
1058 debug_printf("3 add targ %p ret %p\n", targ, ret);
1059 Lst_Append(targ->childrenList, ret);
1061 Lst_Append(slst, ret);
1062 SUFF_DEBUG1("\tusing existing source %s\n", sgn->name);
1066 /* Expand the names of any children of a given node that contain variable
1067 * expressions or file wildcards into actual targets.
1069 * The expanded node is removed from the parent's list of children, and the
1070 * parent's unmade counter is decremented, but other nodes may be added.
1073 * cln Child to examine
1074 * pgn Parent node being processed
1077 SuffExpandChildren(GNodeListNode *cln, GNode *pgn)
1079 GNode *cgn = cln->datum;
1080 GNode *gn; /* New source 8) */
1081 char *cp; /* Expanded value */
1083 if (!Lst_IsEmpty(cgn->order_pred) || !Lst_IsEmpty(cgn->order_succ))
1084 /* It is all too hard to process the result of .ORDER */
1087 if (cgn->type & OP_WAIT)
1088 /* Ignore these (& OP_PHONY ?) */
1092 * First do variable expansion -- this takes precedence over
1093 * wildcard expansion. If the result contains wildcards, they'll be gotten
1094 * to later since the resulting words are tacked on to the end of
1095 * the children list.
1097 if (strchr(cgn->name, '$') == NULL) {
1098 SuffExpandWildcards(cln, pgn);
1102 SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
1103 (void)Var_Subst(cgn->name, pgn, VARE_WANTRES | VARE_UNDEFERR, &cp);
1104 /* TODO: handle errors */
1107 GNodeList *members = Lst_New();
1109 if (cgn->type & OP_ARCHV) {
1111 * Node was an archive(member) target, so we want to call
1112 * on the Arch module to find the nodes for us, expanding
1113 * variables in the parent's context.
1115 char *sacrifice = cp;
1117 (void)Arch_ParseArchive(&sacrifice, members, pgn);
1120 * Break the result into a vector of strings whose nodes
1121 * we can find, then add those nodes to the members list.
1122 * Unfortunately, we can't use Str_Words because it
1123 * doesn't understand about variable specifications with
1127 char *initcp = cp; /* For freeing... */
1130 pp_skip_hspace(&start);
1132 while (*cp != '\0') {
1133 if (*cp == ' ' || *cp == '\t') {
1135 * White-space -- terminate element, find the node,
1136 * add it, skip any further spaces.
1139 gn = Targ_GetNode(start);
1140 Lst_Append(members, gn);
1141 pp_skip_hspace(&cp);
1142 start = cp; /* Continue at the next non-space. */
1143 } else if (*cp == '$') {
1145 * Start of a variable spec -- contact variable module
1146 * to find the end so we can skip over it.
1148 const char *nested_p = cp;
1152 /* XXX: Why VARE_WANTRES when the result is not used? */
1153 (void)Var_Parse(&nested_p, pgn,
1154 VARE_WANTRES | VARE_UNDEFERR,
1156 /* TODO: handle errors */
1157 if (junk == var_Error) {
1158 Parse_Error(PARSE_FATAL,
1159 "Malformed variable expression at \"%s\"",
1163 cp += nested_p - cp;
1167 } else if (cp[0] == '\\' && cp[1] != '\0') {
1169 * Escaped something -- skip over it
1171 /* XXX: In other places, escaping at this syntactical
1172 * position is done by a '$', not a '\'. The '\' is only
1173 * used in variable modifiers. */
1182 * Stuff left over -- add it to the list too
1184 gn = Targ_GetNode(start);
1185 Lst_Append(members, gn);
1188 * Point cp back at the beginning again so the variable value
1195 * Add all elements of the members list to the parent node.
1197 while(!Lst_IsEmpty(members)) {
1198 gn = Lst_Dequeue(members);
1200 SUFF_DEBUG1("%s...", gn->name);
1201 /* Add gn to the parents child list before the original child */
1202 Lst_InsertBefore(pgn->children, cln, gn);
1203 Lst_Append(gn->parents, pgn);
1205 /* Expand wildcards on new node */
1206 SuffExpandWildcards(cln->prev, pgn);
1219 * Now the source is expanded, remove it from the list of children to
1220 * keep it from being processed.
1223 Lst_Remove(pgn->children, cln);
1224 Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
1228 SuffExpandWildcards(GNodeListNode *cln, GNode *pgn)
1230 GNode *cgn = cln->datum;
1231 StringList *expansions;
1233 if (!Dir_HasWildcards(cgn->name))
1237 * Expand the word along the chosen path
1239 expansions = Lst_New();
1240 Dir_Expand(cgn->name, Suff_FindPath(cgn), expansions);
1242 while (!Lst_IsEmpty(expansions)) {
1245 * Fetch next expansion off the list and find its GNode
1247 char *cp = Lst_Dequeue(expansions);
1249 SUFF_DEBUG1("%s...", cp);
1250 gn = Targ_GetNode(cp);
1252 /* Add gn to the parents child list before the original child */
1253 Lst_InsertBefore(pgn->children, cln, gn);
1254 Lst_Append(gn->parents, pgn);
1258 Lst_Free(expansions);
1263 * Now the source is expanded, remove it from the list of children to
1264 * keep it from being processed.
1267 Lst_Remove(pgn->children, cln);
1268 Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
1271 /* Find a path along which to expand the node.
1273 * If the node has a known suffix, use that path.
1274 * If it has no known suffix, use the default system search path.
1277 * gn Node being examined
1280 * The appropriate path to search for the GNode.
1283 Suff_FindPath(GNode* gn)
1285 Suff *suff = gn->suffix;
1288 char *name = gn->name;
1289 size_t nameLen = strlen(gn->name);
1291 for (ln = sufflist->first; ln != NULL; ln = ln->next)
1292 if (SuffSuffIsSuffix(ln->datum, nameLen, name + nameLen))
1295 SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
1298 /* XXX: Here we can save the suffix so we don't have to do this again */
1302 SUFF_DEBUG1("suffix is \"%s\"...\n", suff->name);
1303 return suff->searchPath;
1306 return dirSearchPath; /* Use default search path */
1310 /* Apply a transformation rule, given the source and target nodes and
1313 * The source and target are linked and the commands from the transformation
1314 * are added to the target node's commands list. The target also inherits all
1315 * the sources for the transformation rule.
1318 * TRUE if successful, FALSE if not.
1321 SuffApplyTransform(GNode *tgn, GNode *sgn, Suff *tsuff, Suff *ssuff)
1324 char *tname; /* Name of transformation rule */
1325 GNode *gn; /* Node for same */
1328 * Form the proper links between the target and source.
1330 Lst_Append(tgn->children, sgn);
1331 Lst_Append(sgn->parents, tgn);
1335 * Locate the transformation rule itself
1337 tname = str_concat2(ssuff->name, tsuff->name);
1338 gn = FindTransformByName(tname);
1342 /* This can happen when linking an OP_MEMBER and OP_ARCHV node. */
1346 DEBUG3(SUFF,"\tapplying %s -> %s to \"%s\"\n",
1347 ssuff->name, tsuff->name, tgn->name);
1349 /* Record last child; Make_HandleUse may add child nodes. */
1350 ln = tgn->children->last;
1352 /* Apply the rule. */
1353 Make_HandleUse(gn, tgn);
1355 /* Deal with wildcards and variables in any acquired sources. */
1356 ln = ln != NULL ? ln->next : NULL;
1357 while (ln != NULL) {
1358 GNodeListNode *nln = ln->next;
1359 SuffExpandChildren(ln, tgn);
1364 * Keep track of another parent to which this node is transformed so
1365 * the .IMPSRC variable can be set correctly for the parent.
1367 Lst_Append(sgn->implicitParents, tgn);
1373 /* Locate dependencies for an OP_ARCHV node.
1376 * gn Node for which to locate dependencies
1379 * Same as Suff_FindDeps
1382 SuffFindArchiveDeps(GNode *gn, SrcList *slst)
1384 char *eoarch; /* End of archive portion */
1385 char *eoname; /* End of member portion */
1386 GNode *mem; /* Node for member */
1387 SuffListNode *ln, *nln; /* Next suffix node to check */
1388 Suff *ms; /* Suffix descriptor for member */
1389 char *name; /* Start of member's name */
1392 * The node is an archive(member) pair. so we must find a
1393 * suffix for both of them.
1395 eoarch = strchr(gn->name, '(');
1396 eoname = strchr(eoarch, ')');
1399 * Caller guarantees the format `libname(member)', via
1400 * Arch_ParseArchive.
1402 assert(eoarch != NULL);
1403 assert(eoname != NULL);
1405 *eoname = '\0'; /* Nuke parentheses during suffix search */
1406 *eoarch = '\0'; /* So a suffix can be found */
1411 * To simplify things, call Suff_FindDeps recursively on the member now,
1412 * so we can simply compare the member's .PREFIX and .TARGET variables
1413 * to locate its suffix. This allows us to figure out the suffix to
1414 * use for the archive without having to do a quadratic search over the
1415 * suffix list, backtracking for each one...
1417 mem = Targ_GetNode(name);
1418 SuffFindDeps(mem, slst);
1421 * Create the link between the two nodes right off
1423 Lst_Append(gn->children, mem);
1424 Lst_Append(mem->parents, gn);
1428 * Copy in the variables from the member node to this one.
1430 Var_Set(PREFIX, GNode_VarPrefix(mem), gn);
1431 Var_Set(TARGET, GNode_VarTarget(mem), gn);
1434 if (ms == NULL) { /* Didn't know what it was. */
1435 SUFF_DEBUG0("using null suffix\n");
1441 * Set the other two local variables required for this target.
1443 Var_Set(MEMBER, name, gn);
1444 Var_Set(ARCHIVE, gn->name, gn);
1447 * Set $@ for compatibility with other makes
1449 Var_Set(TARGET, gn->name, gn);
1452 * Now we've got the important local variables set, expand any sources
1453 * that still contain variables or wildcards in their names.
1455 for (ln = gn->children->first; ln != NULL; ln = nln) {
1457 SuffExpandChildren(ln, gn);
1462 * Member has a known suffix, so look for a transformation rule from
1463 * it to a possible suffix of the archive. Rather than searching
1464 * through the entire list, we just look at suffixes to which the
1465 * member's suffix may be transformed...
1467 size_t nameLen = (size_t)(eoarch - gn->name);
1469 /* Use first matching suffix... */
1470 for (ln = ms->parents->first; ln != NULL; ln = ln->next)
1471 if (SuffSuffIsSuffix(ln->datum, nameLen, eoarch))
1476 * Got one -- apply it
1478 Suff *suff = ln->datum;
1479 if (!SuffApplyTransform(gn, mem, suff, ms)) {
1480 SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
1481 ms->name, suff->name);
1487 * Replace the opening and closing parens now we've no need of the separate
1494 * Pretend gn appeared to the left of a dependency operator so
1495 * the user needn't provide a transformation from the member to the
1498 if (!GNode_IsTarget(gn))
1499 gn->type |= OP_DEPENDS;
1502 * Flag the member as such so we remember to look in the archive for
1503 * its modification time. The OP_JOIN | OP_MADE is needed because this
1504 * target should never get made.
1506 mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
1510 SuffFindNormalDepsKnown(const char *name, size_t nameLen, GNode *gn,
1511 SrcList *srcs, SrcList *targs)
1517 for (ln = sufflist->first; ln != NULL; ln = ln->next) {
1518 Suff *suff = ln->datum;
1519 if (!SuffSuffIsSuffix(suff, nameLen, name + nameLen))
1522 pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen));
1523 targ = SrcNew(bmake_strdup(gn->name), pref, suff, NULL, gn);
1527 * Add nodes from which the target can be made
1529 SuffAddLevel(srcs, targ);
1532 * Record the target so we can nuke it
1534 Lst_Append(targs, targ);
1539 SuffFindNormalDepsUnknown(GNode *gn, const char *sopref,
1540 SrcList *srcs, SrcList *targs)
1544 if (!Lst_IsEmpty(targs) || suffNull == NULL)
1547 SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
1549 targ = SrcNew(bmake_strdup(gn->name), bmake_strdup(sopref),
1550 suffNull, NULL, gn);
1551 targ->suff->refCount++;
1554 * Only use the default suffix rules if we don't have commands
1555 * defined for this gnode; traditional make programs used to
1556 * not define suffix rules if the gnode had children but we
1557 * don't do this anymore.
1559 if (Lst_IsEmpty(gn->commands))
1560 SuffAddLevel(srcs, targ);
1562 SUFF_DEBUG0("not ");
1565 SUFF_DEBUG0("adding suffix rules\n");
1567 Lst_Append(targs, targ);
1571 * Deal with finding the thing on the default search path. We
1572 * always do that, not only if the node is only a source (not
1573 * on the lhs of a dependency operator or [XXX] it has neither
1574 * children or commands) as the old pmake did.
1577 SuffFindNormalDepsPath(GNode *gn, Src *targ)
1579 if (gn->type & (OP_PHONY | OP_NOPATH))
1583 gn->path = Dir_FindFile(gn->name,
1584 (targ == NULL ? dirSearchPath :
1585 targ->suff->searchPath));
1586 if (gn->path == NULL)
1589 Var_Set(TARGET, gn->path, gn);
1593 * Suffix known for the thing -- trim the suffix off
1594 * the path to form the proper .PREFIX variable.
1596 size_t savep = strlen(gn->path) - targ->suff->nameLen;
1601 gn->suffix->refCount--;
1602 gn->suffix = targ->suff;
1603 gn->suffix->refCount++;
1605 savec = gn->path[savep];
1606 gn->path[savep] = '\0';
1608 if ((ptr = strrchr(gn->path, '/')) != NULL)
1613 Var_Set(PREFIX, ptr, gn);
1615 gn->path[savep] = savec;
1619 /* The .PREFIX gets the full path if the target has no known suffix. */
1621 gn->suffix->refCount--;
1624 if ((ptr = strrchr(gn->path, '/')) != NULL)
1629 Var_Set(PREFIX, ptr, gn);
1633 /* Locate implicit dependencies for regular targets.
1636 * gn Node for which to find sources
1639 * Same as Suff_FindDeps
1642 SuffFindNormalDeps(GNode *gn, SrcList *slst)
1644 SrcList *srcs; /* List of sources at which to look */
1645 SrcList *targs; /* List of targets to which things can be
1646 * transformed. They all have the same file,
1647 * but different suff and pref fields */
1648 Src *bottom; /* Start of found transformation path */
1649 Src *src; /* General Src pointer */
1650 char *pref; /* Prefix to use */
1651 Src *targ; /* General Src target pointer */
1653 const char *name = gn->name;
1654 size_t nameLen = strlen(name);
1657 * Begin at the beginning...
1663 * We're caught in a catch-22 here. On the one hand, we want to use any
1664 * transformation implied by the target's sources, but we can't examine
1665 * the sources until we've expanded any variables/wildcards they may hold,
1666 * and we can't do that until we've set up the target's local variables
1667 * and we can't do that until we know what the proper suffix for the
1668 * target is (in case there are two suffixes one of which is a suffix of
1669 * the other) and we can't know that until we've found its implied
1670 * source, which we may not want to use if there's an existing source
1671 * that implies a different transformation.
1673 * In an attempt to get around this, which may not work all the time,
1674 * but should work most of the time, we look for implied sources first,
1675 * checking transformations to all possible suffixes of the target,
1676 * use what we find to set the target's local variables, expand the
1677 * children, then look for any overriding transformations they imply.
1678 * Should we find one, we discard the one we found before.
1683 if (!(gn->type & OP_PHONY)) {
1685 SuffFindNormalDepsKnown(name, nameLen, gn, srcs, targs);
1687 /* Handle target of unknown suffix... */
1688 SuffFindNormalDepsUnknown(gn, name, srcs, targs);
1691 * Using the list of possible sources built up from the target
1692 * suffix(es), try and find an existing file/target that matches.
1694 bottom = SuffFindThem(srcs, slst);
1696 if (bottom == NULL) {
1698 * No known transformations -- use the first suffix found
1699 * for setting the local variables.
1701 if (targs->first != NULL)
1702 targ = targs->first->datum;
1707 * Work up the transformation path to find the suffix of the
1708 * target to which the transformation was made.
1710 for (targ = bottom; targ->parent != NULL; targ = targ->parent)
1715 Var_Set(TARGET, GNode_Path(gn), gn);
1717 pref = targ != NULL ? targ->pref : gn->name;
1718 Var_Set(PREFIX, pref, gn);
1721 * Now we've got the important local variables set, expand any sources
1722 * that still contain variables or wildcards in their names.
1725 SuffListNode *ln, *nln;
1726 for (ln = gn->children->first; ln != NULL; ln = nln) {
1728 SuffExpandChildren(ln, gn);
1733 SUFF_DEBUG1("\tNo valid suffix on %s\n", gn->name);
1736 SuffFindNormalDepsPath(gn, targ);
1741 * If the suffix indicates that the target is a library, mark that in
1742 * the node's type field.
1744 if (targ->suff->flags & SUFF_LIBRARY)
1748 * Check for overriding transformation rule implied by sources
1750 if (!Lst_IsEmpty(gn->children)) {
1751 src = SuffFindCmds(targ, slst);
1755 * Free up all the Src structures in the transformation path
1756 * up to, but not including, the parent node.
1758 while (bottom != NULL && bottom->parent != NULL) {
1759 if (Lst_FindDatum(slst, bottom) == NULL)
1760 Lst_Append(slst, bottom);
1761 bottom = bottom->parent;
1767 if (bottom == NULL) {
1769 * No idea from where it can come -- return now.
1775 * We now have a list of Src structures headed by 'bottom' and linked via
1776 * their 'parent' pointers. What we do next is create links between
1777 * source and target nodes (which may or may not have been created)
1778 * and set the necessary local variables in each target. The
1779 * commands for each target are set from the commands of the
1780 * transformation rule used to get from the src suffix to the targ
1781 * suffix. Note that this causes the commands list of the original
1782 * node, gn, to be replaced by the commands of the final
1783 * transformation rule. Also, the unmade field of gn is incremented.
1786 if (bottom->node == NULL)
1787 bottom->node = Targ_GetNode(bottom->file);
1789 for (src = bottom; src->parent != NULL; src = src->parent) {
1792 if (src->node->suffix)
1793 src->node->suffix->refCount--;
1794 src->node->suffix = src->suff;
1795 src->node->suffix->refCount++;
1797 if (targ->node == NULL)
1798 targ->node = Targ_GetNode(targ->file);
1800 SuffApplyTransform(targ->node, src->node,
1801 targ->suff, src->suff);
1803 if (targ->node != gn) {
1805 * Finish off the dependency-search process for any nodes
1806 * between bottom and gn (no point in questing around the
1807 * filesystem for their implicit source when it's already
1808 * known). Note that the node can't have any sources that
1809 * need expanding, since SuffFindThem will stop on an existing
1810 * node, so all we need to do is set the standard variables.
1812 targ->node->type |= OP_DEPS_FOUND;
1813 Var_Set(PREFIX, targ->pref, targ->node);
1814 Var_Set(TARGET, targ->node->name, targ->node);
1818 if (gn->suffix != NULL)
1819 gn->suffix->refCount--;
1820 gn->suffix = src->suff;
1821 gn->suffix->refCount++;
1824 * Nuke the transformation path and the Src structures left over in the
1828 if (bottom != NULL && Lst_FindDatum(slst, bottom) == NULL)
1829 Lst_Append(slst, bottom);
1831 while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
1834 Lst_MoveAll(slst, srcs);
1835 Lst_MoveAll(slst, targs);
1839 /* Find implicit sources for the target.
1841 * Nodes are added to the graph below the passed-in node. The nodes are
1842 * marked to have their IMPSRC variable filled in. The PREFIX variable is set
1843 * for the given node and all its implied children.
1845 * The path found by this target is the shortest path in the transformation
1846 * graph, which may pass through non-existent targets, to an existing target.
1847 * The search continues on all paths from the root suffix until a file is
1848 * found. I.e. if there's a path .o -> .c -> .l -> .l,v from the root and the
1849 * .l,v file exists but the .c and .l files don't, the search will branch out
1850 * in all directions from .o and again from all the nodes on the next level
1851 * until the .l,v node is encountered.
1854 Suff_FindDeps(GNode *gn)
1857 SuffFindDeps(gn, srclist);
1858 while (SuffRemoveSrc(srclist))
1863 SuffFindDeps(GNode *gn, SrcList *slst)
1865 if (gn->type & OP_DEPS_FOUND)
1867 gn->type |= OP_DEPS_FOUND;
1870 * Make sure we have these set, may get revised below.
1872 Var_Set(TARGET, GNode_Path(gn), gn);
1873 Var_Set(PREFIX, gn->name, gn);
1875 SUFF_DEBUG1("SuffFindDeps (%s)\n", gn->name);
1877 if (gn->type & OP_ARCHV) {
1878 SuffFindArchiveDeps(gn, slst);
1879 } else if (gn->type & OP_LIB) {
1881 * If the node is a library, it is the arch module's job to find it
1882 * and set the TARGET variable accordingly. We merely provide the
1883 * search path, assuming all libraries end in ".a" (if the suffix
1884 * hasn't been defined, there's nothing we can do for it, so we just
1885 * set the TARGET variable to the node's name in order to give it a
1888 Suff *s = FindSuffByName(LIBSUFF);
1890 gn->suffix->refCount--;
1893 gn->suffix->refCount++;
1894 Arch_FindLib(gn, s->searchPath);
1897 Var_Set(TARGET, gn->name, gn);
1900 * Because a library (-lfoo) target doesn't follow the standard
1901 * filesystem conventions, we don't set the regular variables for
1902 * the thing. .PREFIX is simply made empty...
1904 Var_Set(PREFIX, "", gn);
1906 SuffFindNormalDeps(gn, slst);
1910 /* Define which suffix is the null suffix.
1912 * Need to handle the changing of the null suffix gracefully so the old
1913 * transformation rules don't just go away.
1916 * name Name of null suffix
1919 Suff_SetNull(const char *name)
1921 Suff *suff = FindSuffByName(name);
1923 Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
1928 if (suffNull != NULL)
1929 suffNull->flags &= ~(unsigned)SUFF_NULL;
1930 suff->flags |= SUFF_NULL;
1932 * XXX: Here's where the transformation mangling would take place
1937 /* Initialize the suffixes module. */
1942 suffClean = Lst_New();
1943 sufflist = Lst_New();
1945 srclist = Lst_New();
1946 transforms = Lst_New();
1949 * Create null suffix for single-suffix rules (POSIX). The thing doesn't
1950 * actually go on the suffix list or everyone will think that's its
1953 Suff_ClearSuffixes();
1957 /* Clean up the suffixes module. */
1962 Lst_Destroy(sufflist, SuffFree);
1963 Lst_Destroy(suffClean, SuffFree);
1967 Lst_Free(transforms);
1973 PrintSuffNames(const char *prefix, SuffList *suffs)
1977 debug_printf("#\t%s: ", prefix);
1978 for (ln = suffs->first; ln != NULL; ln = ln->next) {
1979 Suff *suff = ln->datum;
1980 debug_printf("%s ", suff->name);
1986 PrintSuff(Suff *suff)
1988 debug_printf("# \"%s\" (num %d, ref %d)",
1989 suff->name, suff->sNum, suff->refCount);
1990 if (suff->flags != 0) {
1991 char flags_buf[SuffFlags_ToStringSize];
1993 debug_printf(" (%s)",
1994 Enum_FlagsToString(flags_buf, sizeof flags_buf,
1995 suff->flags, SuffFlags_ToStringSpecs));
1999 PrintSuffNames("To", suff->parents);
2000 PrintSuffNames("From", suff->children);
2002 debug_printf("#\tSearch Path: ");
2003 Dir_PrintPath(suff->searchPath);
2008 PrintTransformation(GNode *t)
2010 debug_printf("%-16s:", t->name);
2011 Targ_PrintType(t->type);
2020 debug_printf("#*** Suffixes:\n");
2023 for (ln = sufflist->first; ln != NULL; ln = ln->next)
2024 PrintSuff(ln->datum);
2027 debug_printf("#*** Transformations:\n");
2030 for (ln = transforms->first; ln != NULL; ln = ln->next)
2031 PrintTransformation(ln->datum);