Module Name: src
Committed By: rillig
Date: Sat Dec 5 16:59:47 UTC 2020
Modified Files:
src/usr.bin/make: suff.c
Log Message:
make(1): indent suff.c with tabs instead of spaces
ExpandChildren is way too deeply nested.
To generate a diff of this commit:
cvs rdiff -u -r1.323 -r1.324 src/usr.bin/make/suff.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.323 src/usr.bin/make/suff.c:1.324
--- src/usr.bin/make/suff.c:1.323 Sun Nov 29 01:40:26 2020
+++ src/usr.bin/make/suff.c Sat Dec 5 16:59:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.323 2020/11/29 01:40:26 rillig Exp $ */
+/* $NetBSD: suff.c,v 1.324 2020/12/05 16:59:47 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -114,7 +114,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.323 2020/11/29 01:40:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.324 2020/12/05 16:59:47 rillig Exp $");
#define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
@@ -126,25 +126,54 @@ typedef ListNode SuffixListNode;
typedef List CandidateList;
typedef ListNode CandidateListNode;
-static SuffixList sufflist = LST_INIT; /* List of suffixes */
+/* The defined suffixes, such as '.c', '.o', '.l'. */
+static SuffixList sufflist = LST_INIT;
#ifdef CLEANUP
-static SuffixList suffClean = LST_INIT; /* List of suffixes to be cleaned */
+/* The suffixes to be cleaned up at the end. */
+static SuffixList suffClean = LST_INIT;
#endif
-/* List of transformation rules, such as ".c.o" */
+/*
+ * The transformation rules, such as '.c.o' to transform '.c' into '.o',
+ * or simply '.c' to transform 'file.c' into 'file'.
+ */
static GNodeList transforms = LST_INIT;
-static int sNum = 0; /* Counter for assigning suffix numbers */
+/*
+ * Counter for assigning suffix numbers.
+ * TODO: What are these suffix numbers used for?
+ */
+static int sNum = 0;
typedef enum SuffixFlags {
- SUFF_INCLUDE = 0x01, /* One which is #include'd */
- SUFF_LIBRARY = 0x02, /* One which contains a library */
- SUFF_NULL = 0x04 /* The empty suffix */
- /* XXX: Why is SUFF_NULL needed? Wouldn't nameLen == 0 mean the same? */
+
+ /*
+ * This suffix marks include files. Their search path ends up in the
+ * undocumented special variable '.INCLUDES'.
+ */
+ SUFF_INCLUDE = 1 << 0,
+
+ /*
+ * This suffix marks library files. Their search path ends up in the
+ * undocumented special variable '.LIBS'.
+ */
+ SUFF_LIBRARY = 1 << 1,
+
+ /*
+ * The empty suffix.
+ *
+ * XXX: What is the difference between the empty suffix and the null
+ * suffix?
+ *
+ * XXX: Why is SUFF_NULL needed at all? Wouldn't nameLen == 0 mean
+ * the same?
+ */
+ SUFF_NULL = 1 << 2
+
} SuffixFlags;
ENUM_FLAGS_RTTI_3(SuffixFlags,
- SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL);
+ SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL);
typedef List SuffixListList;
@@ -153,28 +182,29 @@ typedef List SuffixListList;
* such as ".c.o:".
*/
typedef struct Suffix {
- /* The suffix itself, such as ".c" */
- char *name;
- /* Length of the name, to avoid strlen calls */
- size_t nameLen;
- /* Type of suffix */
- SuffixFlags flags;
- /* The path along which files of this suffix may be found */
- SearchPath *searchPath;
- /* The suffix number; TODO: document the purpose of this number */
- int sNum;
- /* Reference count of list membership and several other places */
- int refCount;
- /* Suffixes we have a transformation to */
- SuffixList parents;
- /* Suffixes we have a transformation from */
- SuffixList children;
-
- /* Lists in which this suffix is referenced.
- * XXX: These lists are used nowhere, they are just appended to, for no
- * apparent reason. They do have the side effect of increasing refCount
- * though. */
- SuffixListList ref;
+ /* The suffix itself, such as ".c" */
+ char *name;
+ /* Length of the name, to avoid strlen calls */
+ size_t nameLen;
+ /* Type of suffix */
+ SuffixFlags flags;
+ /* The path along which files of this suffix may be found */
+ SearchPath *searchPath;
+ /* The suffix number; TODO: document the purpose of this number */
+ int sNum;
+ /* Reference count of list membership and several other places */
+ int refCount;
+ /* Suffixes we have a transformation to */
+ SuffixList parents;
+ /* Suffixes we have a transformation from */
+ SuffixList children;
+
+ /* Lists in which this suffix is referenced.
+ *
+ * XXX: These lists are used nowhere, they are just appended to, for
+ * no apparent reason. They do have the side effect of increasing
+ * refCount though. */
+ SuffixListList ref;
} Suffix;
/*
@@ -187,36 +217,36 @@ typedef struct Suffix {
* node is finally chosen to be made.
*/
typedef struct Candidate {
- /* The file or node to look for. */
- char *file;
- /* The prefix from which file was formed.
- * Its memory is shared among all candidates. */
- char *prefix;
- /* The suffix on the file. */
- Suffix *suff;
-
- /* The candidate that can be made from this,
- * or NULL for the top-level candidate. */
- struct Candidate *parent;
- /* The node describing the file. */
- GNode *node;
-
- /* Count of existing children, only used for memory management, so we
- * don't free this candidate too early or too late. */
- int numChildren;
+ /* The file or node to look for. */
+ char *file;
+ /* The prefix from which file was formed.
+ * Its memory is shared among all candidates. */
+ char *prefix;
+ /* The suffix on the file. */
+ Suffix *suff;
+
+ /* The candidate that can be made from this,
+ * or NULL for the top-level candidate. */
+ struct Candidate *parent;
+ /* The node describing the file. */
+ GNode *node;
+
+ /* Count of existing children, only used for memory management, so we
+ * don't free this candidate too early or too late. */
+ int numChildren;
#ifdef DEBUG_SRC
- CandidateList childrenList;
+ CandidateList childrenList;
#endif
} Candidate;
typedef struct CandidateSearcher {
- CandidateList list;
+ CandidateList list;
- /*
- * TODO: Add HashSet for seen entries, to avoid endless loops such as
- * in suff-transform-endless.mk.
- */
+ /*
+ * TODO: Add HashSet for seen entries, to avoid endless loops such as
+ * in suff-transform-endless.mk.
+ */
} CandidateSearcher;
@@ -231,27 +261,27 @@ static Suffix *emptySuff;
static Suffix *
Suffix_Ref(Suffix *suff)
{
- suff->refCount++;
- return suff;
+ suff->refCount++;
+ return suff;
}
/* Change the value of a Suffix variable, adjusting the reference counts. */
static void
Suffix_Reassign(Suffix **var, Suffix *suff)
{
- if (*var != NULL)
- (*var)->refCount--;
- *var = suff;
- suff->refCount++;
+ if (*var != NULL)
+ (*var)->refCount--;
+ *var = suff;
+ suff->refCount++;
}
/* Set a Suffix variable to NULL, adjusting the reference count. */
static void
Suffix_Unassign(Suffix **var)
{
- if (*var != NULL)
- (*var)->refCount--;
- *var = NULL;
+ if (*var != NULL)
+ (*var)->refCount--;
+ *var = NULL;
}
/*
@@ -261,12 +291,12 @@ Suffix_Unassign(Suffix **var)
static const char *
StrTrimPrefix(const char *pref, const char *str)
{
- while (*str && *pref == *str) {
- pref++;
- str++;
- }
+ while (*str && *pref == *str) {
+ pref++;
+ str++;
+ }
- return *pref != '\0' ? NULL : str;
+ return *pref != '\0' ? NULL : str;
}
/*
@@ -276,18 +306,18 @@ StrTrimPrefix(const char *pref, const ch
static const char *
StrTrimSuffix(const char *str, size_t strLen, const char *suff, size_t suffLen)
{
- const char *suffInStr;
- size_t i;
+ const char *suffInStr;
+ size_t i;
- if (strLen < suffLen)
- return NULL;
+ if (strLen < suffLen)
+ return NULL;
- suffInStr = str + strLen - suffLen;
- for (i = 0; i < suffLen; i++)
- if (suff[i] != suffInStr[i])
- return NULL;
+ suffInStr = str + strLen - suffLen;
+ for (i = 0; i < suffLen; i++)
+ if (suff[i] != suffInStr[i])
+ return NULL;
- return suffInStr;
+ return suffInStr;
}
/*
@@ -297,54 +327,57 @@ StrTrimSuffix(const char *str, size_t st
static const char *
Suffix_TrimSuffix(const Suffix *suff, size_t nameLen, const char *nameEnd)
{
- return StrTrimSuffix(nameEnd - nameLen, nameLen, suff->name, suff->nameLen);
+ return StrTrimSuffix(nameEnd - nameLen, nameLen,
+ suff->name, suff->nameLen);
}
static Boolean
Suffix_IsSuffix(const Suffix *suff, size_t nameLen, const char *nameEnd)
{
- return Suffix_TrimSuffix(suff, nameLen, nameEnd) != NULL;
+ return Suffix_TrimSuffix(suff, nameLen, nameEnd) != NULL;
}
static Suffix *
FindSuffixByNameLen(const char *name, size_t nameLen)
{
- SuffixListNode *ln;
+ SuffixListNode *ln;
- for (ln = sufflist.first; ln != NULL; ln = ln->next) {
- Suffix *suff = ln->datum;
- if (suff->nameLen == nameLen && memcmp(suff->name, name, nameLen) == 0)
- return suff;
- }
- return NULL;
+ for (ln = sufflist.first; ln != NULL; ln = ln->next) {
+ Suffix *suff = ln->datum;
+ if (suff->nameLen == nameLen &&
+ memcmp(suff->name, name, nameLen) == 0)
+ return suff;
+ }
+ return NULL;
}
static Suffix *
FindSuffixByName(const char *name)
{
- return FindSuffixByNameLen(name, strlen(name));
+ return FindSuffixByNameLen(name, strlen(name));
}
static GNode *
FindTransformByName(const char *name)
{
- GNodeListNode *ln;
- for (ln = transforms.first; ln != NULL; ln = ln->next) {
- GNode *gn = ln->datum;
- if (strcmp(gn->name, name) == 0)
- return gn;
- }
- return NULL;
+ GNodeListNode *ln;
+
+ for (ln = transforms.first; ln != NULL; ln = ln->next) {
+ GNode *gn = ln->datum;
+ if (strcmp(gn->name, name) == 0)
+ return gn;
+ }
+ return NULL;
}
static void
SuffixList_Unref(SuffixList *list, Suffix *suff)
{
- SuffixListNode *ln = Lst_FindDatum(list, suff);
- if (ln != NULL) {
- Lst_Remove(list, ln);
- suff->refCount--;
- }
+ SuffixListNode *ln = Lst_FindDatum(list, suff);
+ if (ln != NULL) {
+ Lst_Remove(list, ln);
+ suff->refCount--;
+ }
}
/* Free up all memory associated with the given suffix structure. */
@@ -352,45 +385,45 @@ static void
Suffix_Free(Suffix *suff)
{
- if (suff == nullSuff)
- nullSuff = NULL;
+ if (suff == nullSuff)
+ nullSuff = NULL;
- if (suff == emptySuff)
- emptySuff = NULL;
+ if (suff == emptySuff)
+ emptySuff = NULL;
#if 0
- /* We don't delete suffixes in order, so we cannot use this */
- if (suff->refCount != 0)
- Punt("Internal error deleting suffix `%s' with refcount = %d",
- suff->name, suff->refCount);
+ /* We don't delete suffixes in order, so we cannot use this */
+ if (suff->refCount != 0)
+ Punt("Internal error deleting suffix `%s' with refcount = %d",
+ suff->name, suff->refCount);
#endif
- Lst_Done(&suff->ref);
- Lst_Done(&suff->children);
- Lst_Done(&suff->parents);
- SearchPath_Free(suff->searchPath);
+ Lst_Done(&suff->ref);
+ Lst_Done(&suff->children);
+ Lst_Done(&suff->parents);
+ SearchPath_Free(suff->searchPath);
- free(suff->name);
- free(suff);
+ free(suff->name);
+ free(suff);
}
static void
SuffFree(void *p)
{
- Suffix_Free(p);
+ Suffix_Free(p);
}
/* Remove the suffix from the list, and free if it is otherwise unused. */
static void
SuffixList_Remove(SuffixList *list, Suffix *suff)
{
- SuffixList_Unref(list, suff);
- if (suff->refCount == 0) {
- /* XXX: can lead to suff->refCount == -1 */
- SuffixList_Unref(&sufflist, suff);
- DEBUG1(SUFF, "Removing suffix \"%s\"\n", suff->name);
- SuffFree(suff);
- }
+ SuffixList_Unref(list, suff);
+ if (suff->refCount == 0) {
+ /* XXX: can lead to suff->refCount == -1 */
+ SuffixList_Unref(&sufflist, suff);
+ DEBUG1(SUFF, "Removing suffix \"%s\"\n", suff->name);
+ SuffFree(suff);
+ }
}
/* Insert the suffix into the list, keeping the list ordered by suffix
@@ -398,53 +431,54 @@ SuffixList_Remove(SuffixList *list, Suff
static void
SuffixList_Insert(SuffixList *list, Suffix *suff)
{
- SuffixListNode *ln;
- Suffix *listSuff = NULL;
+ SuffixListNode *ln;
+ Suffix *listSuff = NULL;
- for (ln = list->first; ln != NULL; ln = ln->next) {
- listSuff = ln->datum;
- if (listSuff->sNum >= suff->sNum)
- break;
- }
+ for (ln = list->first; ln != NULL; ln = ln->next) {
+ listSuff = ln->datum;
+ if (listSuff->sNum >= suff->sNum)
+ break;
+ }
- if (ln == NULL) {
- SUFF_DEBUG2("inserting \"%s\" (%d) at end of list\n",
+ if (ln == NULL) {
+ SUFF_DEBUG2("inserting \"%s\" (%d) at end of list\n",
suff->name, suff->sNum);
- Lst_Append(list, Suffix_Ref(suff));
- Lst_Append(&suff->ref, list);
- } else if (listSuff->sNum != suff->sNum) {
- DEBUG4(SUFF, "inserting \"%s\" (%d) before \"%s\" (%d)\n",
- suff->name, suff->sNum, listSuff->name, listSuff->sNum);
- Lst_InsertBefore(list, ln, Suffix_Ref(suff));
- Lst_Append(&suff->ref, list);
- } else {
- SUFF_DEBUG2("\"%s\" (%d) is already there\n", suff->name, suff->sNum);
- }
+ Lst_Append(list, Suffix_Ref(suff));
+ Lst_Append(&suff->ref, list);
+ } else if (listSuff->sNum != suff->sNum) {
+ DEBUG4(SUFF, "inserting \"%s\" (%d) before \"%s\" (%d)\n",
+ suff->name, suff->sNum, listSuff->name, listSuff->sNum);
+ Lst_InsertBefore(list, ln, Suffix_Ref(suff));
+ Lst_Append(&suff->ref, list);
+ } else {
+ SUFF_DEBUG2("\"%s\" (%d) is already there\n",
+ suff->name, suff->sNum);
+ }
}
static void
Relate(Suffix *srcSuff, Suffix *targSuff)
{
- SuffixList_Insert(&targSuff->children, srcSuff);
- SuffixList_Insert(&srcSuff->parents, targSuff);
+ SuffixList_Insert(&targSuff->children, srcSuff);
+ SuffixList_Insert(&srcSuff->parents, targSuff);
}
static Suffix *
Suffix_New(const char *name)
{
- Suffix *suff = bmake_malloc(sizeof *suff);
+ Suffix *suff = bmake_malloc(sizeof *suff);
- suff->name = bmake_strdup(name);
- suff->nameLen = strlen(suff->name);
- suff->searchPath = SearchPath_New();
- Lst_Init(&suff->children);
- Lst_Init(&suff->parents);
- Lst_Init(&suff->ref);
- suff->sNum = sNum++;
- suff->flags = 0;
- suff->refCount = 1; /* XXX: why 1? It's not assigned anywhere yet. */
+ suff->name = bmake_strdup(name);
+ suff->nameLen = strlen(suff->name);
+ suff->searchPath = SearchPath_New();
+ Lst_Init(&suff->children);
+ Lst_Init(&suff->parents);
+ Lst_Init(&suff->ref);
+ suff->sNum = sNum++;
+ suff->flags = 0;
+ suff->refCount = 1; /* XXX: why 1? It's not assigned anywhere yet. */
- return suff;
+ return suff;
}
/*
@@ -458,17 +492,17 @@ void
Suff_ClearSuffixes(void)
{
#ifdef CLEANUP
- Lst_MoveAll(&suffClean, &sufflist);
+ Lst_MoveAll(&suffClean, &sufflist);
#endif
- DEBUG0(SUFF, "Clearing all suffixes\n");
- Lst_Init(&sufflist);
- sNum = 0;
- if (nullSuff != NULL)
- SuffFree(nullSuff);
- emptySuff = nullSuff = Suffix_New("");
+ DEBUG0(SUFF, "Clearing all suffixes\n");
+ Lst_Init(&sufflist);
+ sNum = 0;
+ if (nullSuff != NULL)
+ SuffFree(nullSuff);
+ emptySuff = nullSuff = Suffix_New("");
- SearchPath_AddAll(nullSuff->searchPath, &dirSearchPath);
- nullSuff->flags = SUFF_NULL;
+ SearchPath_AddAll(nullSuff->searchPath, &dirSearchPath);
+ nullSuff->flags = SUFF_NULL;
}
/* Parse a transformation string such as ".c.o" to find its two component
@@ -480,63 +514,66 @@ Suff_ClearSuffixes(void)
static Boolean
ParseTransform(const char *str, Suffix **out_src, Suffix **out_targ)
{
- SuffixListNode *ln;
- Suffix *single = NULL;
+ SuffixListNode *ln;
+ Suffix *single = NULL;
- /*
- * Loop looking first for a suffix that matches the start of the
- * string and then for one that exactly matches the rest of it. If
- * we can find two that meet these criteria, we've successfully
- * parsed the string.
- */
- for (ln = sufflist.first; ln != NULL; ln = ln->next) {
- Suffix *src = ln->datum;
+ /*
+ * Loop looking first for a suffix that matches the start of the
+ * string and then for one that exactly matches the rest of it. If
+ * we can find two that meet these criteria, we've successfully
+ * parsed the string.
+ */
+ for (ln = sufflist.first; ln != NULL; ln = ln->next) {
+ Suffix *src = ln->datum;
- if (StrTrimPrefix(src->name, str) == NULL)
- continue;
+ if (StrTrimPrefix(src->name, str) == NULL)
+ continue;
- if (str[src->nameLen] == '\0') {
- single = src;
- } else {
- Suffix *targ = FindSuffixByName(str + src->nameLen);
- if (targ != NULL) {
- *out_src = src;
- *out_targ = targ;
- return TRUE;
- }
+ if (str[src->nameLen] == '\0') {
+ single = src;
+ } else {
+ Suffix *targ = FindSuffixByName(str + src->nameLen);
+ if (targ != NULL) {
+ *out_src = src;
+ *out_targ = targ;
+ return TRUE;
+ }
+ }
}
- }
- if (single != NULL) {
- /*
- * There was a suffix that encompassed the entire string, so we
- * assume it was a transformation to the null suffix (thank you
- * POSIX; search for "single suffix" or "single-suffix").
- *
- * We still prefer to find a double rule over a singleton,
- * hence we leave this check until the end.
- *
- * XXX: Use emptySuff over nullSuff?
- */
- *out_src = single;
- *out_targ = nullSuff;
- return TRUE;
- }
- return FALSE;
+ if (single != NULL) {
+ /*
+ * There was a suffix that encompassed the entire string, so we
+ * assume it was a transformation to the null suffix (thank you
+ * POSIX; search for "single suffix" or "single-suffix").
+ *
+ * We still prefer to find a double rule over a singleton,
+ * hence we leave this check until the end.
+ *
+ * XXX: Use emptySuff over nullSuff?
+ */
+ *out_src = single;
+ *out_targ = nullSuff;
+ return TRUE;
+ }
+ return FALSE;
}
-/* Return TRUE if the given string is a transformation rule, that is, a
+/*
+ * Return TRUE if the given string is a transformation rule, that is, a
* concatenation of two known suffixes such as ".c.o" or a single suffix
- * such as ".o". */
+ * such as ".o".
+ */
Boolean
Suff_IsTransform(const char *str)
{
- Suffix *src, *targ;
+ Suffix *src, *targ;
- return ParseTransform(str, &src, &targ);
+ return ParseTransform(str, &src, &targ);
}
-/* Add the transformation rule to the list of rules and place the
+/*
+ * Add the transformation rule to the list of rules and place the
* transformation itself in the graph.
*
* The transformation is linked to the two suffixes mentioned in the name.
@@ -550,49 +587,49 @@ Suff_IsTransform(const char *str)
GNode *
Suff_AddTransform(const char *name)
{
- Suffix *srcSuff;
- Suffix *targSuff;
+ Suffix *srcSuff;
+ Suffix *targSuff;
- GNode *gn = FindTransformByName(name);
- if (gn == NULL) {
- /*
- * Make a new graph node for the transformation. It will be filled in
- * by the Parse module.
- */
- gn = GNode_New(name);
- Lst_Append(&transforms, gn);
- } else {
- /*
- * New specification for transformation rule. Just nuke the old list
- * of commands so they can be filled in again... We don't actually
- * free the commands themselves, because a given command can be
- * attached to several different transformations.
- */
- Lst_Done(&gn->commands);
- Lst_Init(&gn->commands);
- Lst_Done(&gn->children);
- Lst_Init(&gn->children);
- }
+ GNode *gn = FindTransformByName(name);
+ if (gn == NULL) {
+ /*
+ * Make a new graph node for the transformation. It will be
+ * filled in by the Parse module.
+ */
+ gn = GNode_New(name);
+ Lst_Append(&transforms, gn);
+ } else {
+ /*
+ * New specification for transformation rule. Just nuke the
+ * old list of commands so they can be filled in again. We
+ * don't actually free the commands themselves, because a
+ * given command can be attached to several different
+ * transformations.
+ */
+ Lst_Done(&gn->commands);
+ Lst_Init(&gn->commands);
+ Lst_Done(&gn->children);
+ Lst_Init(&gn->children);
+ }
- gn->type = OP_TRANSFORM;
+ gn->type = OP_TRANSFORM;
- {
- Boolean ok = ParseTransform(name, &srcSuff, &targSuff);
- assert(ok);
- (void)ok;
- }
+ {
+ Boolean ok = ParseTransform(name, &srcSuff, &targSuff);
+ assert(ok);
+ (void)ok;
+ }
- /*
- * link the two together in the proper relationship and order
- */
- SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
- srcSuff->name, targSuff->name);
- Relate(srcSuff, targSuff);
+ /* Link the two together in the proper relationship and order. */
+ SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
+ srcSuff->name, targSuff->name);
+ Relate(srcSuff, targSuff);
- return gn;
+ return gn;
}
-/* Handle the finish of a transformation definition, removing the
+/*
+ * Handle the finish of a transformation definition, removing the
* transformation from the graph if it has neither commands nor sources.
*
* If the node has no commands or children, the children and parents lists
@@ -604,34 +641,37 @@ Suff_AddTransform(const char *name)
void
Suff_EndTransform(GNode *gn)
{
- Suffix *srcSuff, *targSuff;
- SuffixList *srcSuffParents;
+ Suffix *srcSuff, *targSuff;
+ SuffixList *srcSuffParents;
- if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(&gn->cohorts))
- gn = gn->cohorts.last->datum;
+ if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(&gn->cohorts))
+ gn = gn->cohorts.last->datum;
- if (!(gn->type & OP_TRANSFORM))
- return;
+ if (!(gn->type & OP_TRANSFORM))
+ return;
+
+ if (!Lst_IsEmpty(&gn->commands) || !Lst_IsEmpty(&gn->children)) {
+ SUFF_DEBUG1("transformation %s complete\n", gn->name);
+ return;
+ }
+
+ /*
+ * SuffParseTransform() may fail for special rules which are not
+ * actual transformation rules. (e.g. .DEFAULT)
+ */
+ if (!ParseTransform(gn->name, &srcSuff, &targSuff))
+ return;
- if (!Lst_IsEmpty(&gn->commands) || !Lst_IsEmpty(&gn->children)) {
- SUFF_DEBUG1("transformation %s complete\n", gn->name);
- return;
- }
-
- /*
- * SuffParseTransform() may fail for special rules which are not
- * actual transformation rules. (e.g. .DEFAULT)
- */
- if (!ParseTransform(gn->name, &srcSuff, &targSuff))
- return;
-
- SUFF_DEBUG2("deleting incomplete transformation from `%s' to `%s'\n",
- srcSuff->name, targSuff->name);
-
- /* Remember parents since srcSuff could be deleted in SuffixList_Remove. */
- srcSuffParents = &srcSuff->parents;
- SuffixList_Remove(&targSuff->children, srcSuff);
- SuffixList_Remove(srcSuffParents, targSuff);
+ SUFF_DEBUG2("deleting incomplete transformation from `%s' to `%s'\n",
+ srcSuff->name, targSuff->name);
+
+ /*
+ * Remember the parents since srcSuff could be deleted in
+ * SuffixList_Remove.
+ */
+ srcSuffParents = &srcSuff->parents;
+ SuffixList_Remove(&targSuff->children, srcSuff);
+ SuffixList_Remove(srcSuffParents, targSuff);
}
/* Called from Suff_AddSuffix to search through the list of
@@ -650,35 +690,32 @@ Suff_EndTransform(GNode *gn)
static void
RebuildGraph(GNode *transform, Suffix *suff)
{
- const char *name = transform->name;
- size_t nameLen = strlen(name);
- const char *toName;
-
- /*
- * First see if it is a transformation from this suffix.
- */
- toName = StrTrimPrefix(suff->name, name);
- if (toName != NULL) {
- Suffix *to = FindSuffixByName(toName);
- if (to != NULL) {
- /* Link in and return, since it can't be anything else. */
- Relate(suff, to);
- return;
- }
- }
-
- /*
- * Not from, maybe to?
- */
- toName = Suffix_TrimSuffix(suff, nameLen, name + nameLen);
- if (toName != NULL) {
- Suffix *from = FindSuffixByNameLen(name, (size_t)(toName - name));
- if (from != NULL)
- Relate(from, suff);
- }
+ const char *name = transform->name;
+ size_t nameLen = strlen(name);
+ const char *toName;
+
+ /* See if it is a transformation from this suffix to another suffix. */
+ toName = StrTrimPrefix(suff->name, name);
+ if (toName != NULL) {
+ Suffix *to = FindSuffixByName(toName);
+ if (to != NULL) {
+ Relate(suff, to);
+ return;
+ }
+ }
+
+ /* See if it is a transformation from another suffix to this suffix. */
+ toName = Suffix_TrimSuffix(suff, nameLen, name + nameLen);
+ if (toName != NULL) {
+ Suffix *from = FindSuffixByNameLen(name,
+ (size_t)(toName - name));
+ if (from != NULL)
+ Relate(from, suff);
+ }
}
-/* During Suff_AddSuffix, search through the list of existing targets and find
+/*
+ * During Suff_AddSuffix, search through the list of existing targets and find
* if any of the existing targets can be turned into a transformation rule.
*
* If such a target is found and the target is the current main target, the
@@ -690,96 +727,101 @@ RebuildGraph(GNode *transform, Suffix *s
*/
static Boolean
UpdateTarget(GNode *target, GNode **inout_main, Suffix *suff,
- Boolean *inout_removedMain)
+ Boolean *inout_removedMain)
{
- Suffix *srcSuff, *targSuff;
- char *ptr;
+ Suffix *srcSuff, *targSuff;
+ char *ptr;
+
+ if (*inout_main == NULL && *inout_removedMain &&
+ !(target->type & OP_NOTARGET)) {
+ DEBUG1(MAKE, "Setting main node to \"%s\"\n", target->name);
+ *inout_main = target;
+ Targ_SetMain(target);
+ /*
+ * XXX: Why could it be a good idea to return TRUE here?
+ * The main task of this function is to turn ordinary nodes
+ * into transformations, no matter whether or not a new .MAIN
+ * node has been found.
+ */
+ /*
+ * XXX: Even when changing this to FALSE, none of the existing
+ * unit tests fails.
+ */
+ return TRUE;
+ }
+
+ if (target->type == OP_TRANSFORM)
+ return FALSE;
- if (*inout_main == NULL && *inout_removedMain &&
- !(target->type & OP_NOTARGET)) {
- DEBUG1(MAKE, "Setting main node to \"%s\"\n", target->name);
- *inout_main = target;
- Targ_SetMain(target);
/*
- * XXX: Why could it be a good idea to return TRUE here?
- * The main task of this function is to turn ordinary nodes into
- * transformations, no matter whether or not a new .MAIN node
- * has been found.
+ * XXX: What about a transformation ".cpp.c"? If ".c" is added as
+ * a new suffix, it seems wrong that this transformation would be
+ * skipped just because ".c" happens to be a prefix of ".cpp".
*/
+ ptr = strstr(target->name, suff->name);
+ if (ptr == NULL)
+ return FALSE;
+
/*
- * XXX: Even when changing this to FALSE, none of the existing unit
- * tests fails.
+ * XXX: In suff-rebuild.mk, in the line '.SUFFIXES: .c .b .a', this
+ * condition prevents the rule '.b.c' from being added again during
+ * Suff_AddSuffix(".b").
+ *
+ * XXX: Removing this paragraph makes suff-add-later.mk use massive
+ * amounts of memory.
*/
- return TRUE;
- }
-
- if (target->type == OP_TRANSFORM)
- return FALSE;
-
- /*
- * XXX: What about a transformation ".cpp.c"? If ".c" is added as a new
- * suffix, it seems wrong that this transformation would be skipped just
- * because ".c" happens to be a prefix of ".cpp".
- */
- ptr = strstr(target->name, suff->name);
- if (ptr == NULL)
- return FALSE;
+ if (ptr == target->name)
+ return FALSE;
- /*
- * XXX: In suff-rebuild.mk, in the line '.SUFFIXES: .c .b .a', this
- * condition prevents the rule '.b.c' from being added again during
- * Suff_AddSuffix(".b").
- *
- * XXX: Removing this paragraph makes suff-add-later.mk use massive
- * amounts of memory.
- */
- if (ptr == target->name)
- return FALSE;
+ if (ParseTransform(target->name, &srcSuff, &targSuff)) {
+ if (*inout_main == target) {
+ DEBUG1(MAKE,
+ "Setting main node from \"%s\" back to null\n",
+ target->name);
+ *inout_removedMain = TRUE;
+ *inout_main = NULL;
+ Targ_SetMain(NULL);
+ }
+ Lst_Done(&target->children);
+ Lst_Init(&target->children);
+ target->type = OP_TRANSFORM;
- if (ParseTransform(target->name, &srcSuff, &targSuff)) {
- if (*inout_main == target) {
- DEBUG1(MAKE, "Setting main node from \"%s\" back to null\n",
- target->name);
- *inout_removedMain = TRUE;
- *inout_main = NULL;
- Targ_SetMain(NULL);
- }
- Lst_Done(&target->children);
- Lst_Init(&target->children);
- target->type = OP_TRANSFORM;
- /*
- * link the two together in the proper relationship and order
- */
- SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
+ /*
+ * Link the two together in the proper relationship and order.
+ */
+ SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
srcSuff->name, targSuff->name);
- Relate(srcSuff, targSuff);
- }
- return FALSE;
+ Relate(srcSuff, targSuff);
+ }
+ return FALSE;
}
-/* Look at all existing targets to see if adding this suffix will make one
+/*
+ * Look at all existing targets to see if adding this suffix will make one
* of the current targets mutate into a suffix rule.
*
* This is ugly, but other makes treat all targets that start with a '.' as
- * suffix rules. */
+ * suffix rules.
+ */
static void
UpdateTargets(GNode **inout_main, Suffix *suff)
{
- Boolean removedMain = FALSE;
- GNodeListNode *ln;
+ Boolean removedMain = FALSE;
+ GNodeListNode *ln;
- for (ln = Targ_List()->first; ln != NULL; ln = ln->next) {
- GNode *gn = ln->datum;
- if (UpdateTarget(gn, inout_main, suff, &removedMain))
- break;
- }
+ for (ln = Targ_List()->first; ln != NULL; ln = ln->next) {
+ GNode *gn = ln->datum;
+ if (UpdateTarget(gn, inout_main, suff, &removedMain))
+ break;
+ }
}
/* Add the suffix to the end of the list of known suffixes.
- * Should we restructure the suffix graph? Make doesn't...
+ * Should we restructure the suffix graph? Make doesn't.
*
- * A GNode is created for the suffix and a Suffix structure is created and
- * added to the suffixes list unless the suffix was already known.
+ * A GNode is created for the suffix (XXX: this sounds completely wrong) and
+ * a Suffix structure is created and added to the suffixes list unless the
+ * suffix was already known.
* The mainNode passed can be modified if a target mutated into a
* transform and that target happened to be the main target.
*
@@ -789,32 +831,32 @@ UpdateTargets(GNode **inout_main, Suffix
void
Suff_AddSuffix(const char *name, GNode **inout_main)
{
- GNodeListNode *ln;
+ GNodeListNode *ln;
+
+ Suffix *suff = FindSuffixByName(name);
+ if (suff != NULL)
+ return;
+
+ suff = Suffix_New(name);
+ Lst_Append(&sufflist, suff);
+ DEBUG1(SUFF, "Adding suffix \"%s\"\n", suff->name);
+
+ UpdateTargets(inout_main, suff);
- Suffix *suff = FindSuffixByName(name);
- if (suff != NULL)
- return;
-
- suff = Suffix_New(name);
- Lst_Append(&sufflist, suff);
- DEBUG1(SUFF, "Adding suffix \"%s\"\n", suff->name);
-
- UpdateTargets(inout_main, suff);
-
- /*
- * Look for any existing transformations from or to this suffix.
- * XXX: Only do this after a Suff_ClearSuffixes?
- */
- for (ln = transforms.first; ln != NULL; ln = ln->next)
- RebuildGraph(ln->datum, suff);
+ /*
+ * Look for any existing transformations from or to this suffix.
+ * XXX: Only do this after a Suff_ClearSuffixes?
+ */
+ for (ln = transforms.first; ln != NULL; ln = ln->next)
+ RebuildGraph(ln->datum, suff);
}
/* Return the search path for the given suffix, or NULL. */
SearchPath *
Suff_GetPath(const char *sname)
{
- Suffix *suff = FindSuffixByName(sname);
- return suff != NULL ? suff->searchPath : NULL;
+ Suffix *suff = FindSuffixByName(sname);
+ return suff != NULL ? suff->searchPath : NULL;
}
/*
@@ -833,39 +875,40 @@ Suff_GetPath(const char *sname)
void
Suff_DoPaths(void)
{
- SuffixListNode *ln;
- char *flags;
- SearchPath *inIncludes = SearchPath_New(); /* Cumulative .INCLUDES path */
- SearchPath *inLibs = SearchPath_New(); /* Cumulative .LIBS path */
-
- for (ln = sufflist.first; ln != NULL; ln = ln->next) {
- Suffix *suff = ln->datum;
- if (!Lst_IsEmpty(suff->searchPath)) {
+ SuffixListNode *ln;
+ char *flags;
+ SearchPath *includesPath = SearchPath_New();
+ SearchPath *libsPath = SearchPath_New();
+
+ for (ln = sufflist.first; ln != NULL; ln = ln->next) {
+ Suffix *suff = ln->datum;
+ if (!Lst_IsEmpty(suff->searchPath)) {
#ifdef INCLUDES
- if (suff->flags & SUFF_INCLUDE)
- SearchPath_AddAll(inIncludes, suff->searchPath);
+ if (suff->flags & SUFF_INCLUDE)
+ SearchPath_AddAll(includesPath,
+ suff->searchPath);
#endif
#ifdef LIBRARIES
- if (suff->flags & SUFF_LIBRARY)
- SearchPath_AddAll(inLibs, suff->searchPath);
+ if (suff->flags & SUFF_LIBRARY)
+ SearchPath_AddAll(libsPath, suff->searchPath);
#endif
- SearchPath_AddAll(suff->searchPath, &dirSearchPath);
- } else {
- SearchPath_Free(suff->searchPath);
- suff->searchPath = Dir_CopyDirSearchPath();
+ SearchPath_AddAll(suff->searchPath, &dirSearchPath);
+ } else {
+ SearchPath_Free(suff->searchPath);
+ suff->searchPath = Dir_CopyDirSearchPath();
+ }
}
- }
- flags = SearchPath_ToFlags("-I", inIncludes);
- Var_Set(".INCLUDES", flags, VAR_GLOBAL);
- free(flags);
+ flags = SearchPath_ToFlags("-I", includesPath);
+ Var_Set(".INCLUDES", flags, VAR_GLOBAL);
+ free(flags);
+
+ flags = SearchPath_ToFlags("-L", libsPath);
+ Var_Set(".LIBS", flags, VAR_GLOBAL);
+ free(flags);
- flags = SearchPath_ToFlags("-L", inLibs);
- Var_Set(".LIBS", flags, VAR_GLOBAL);
- free(flags);
-
- SearchPath_Free(inIncludes);
- SearchPath_Free(inLibs);
+ SearchPath_Free(includesPath);
+ SearchPath_Free(libsPath);
}
/*
@@ -877,9 +920,9 @@ Suff_DoPaths(void)
void
Suff_AddInclude(const char *suffName)
{
- Suffix *suff = FindSuffixByName(suffName);
- if (suff != NULL)
- suff->flags |= SUFF_INCLUDE;
+ Suffix *suff = FindSuffixByName(suffName);
+ if (suff != NULL)
+ suff->flags |= SUFF_INCLUDE;
}
/*
@@ -891,45 +934,45 @@ Suff_AddInclude(const char *suffName)
void
Suff_AddLib(const char *suffName)
{
- Suffix *suff = FindSuffixByName(suffName);
- if (suff != NULL)
- suff->flags |= SUFF_LIBRARY;
+ Suffix *suff = FindSuffixByName(suffName);
+ if (suff != NULL)
+ suff->flags |= SUFF_LIBRARY;
}
- /********** Implicit Source Search Functions *********/
+/********** Implicit Source Search Functions *********/
static void
CandidateSearcher_Init(CandidateSearcher *cs)
{
- Lst_Init(&cs->list);
+ Lst_Init(&cs->list);
}
static void
CandidateSearcher_Done(CandidateSearcher *cs)
{
- Lst_Done(&cs->list);
+ Lst_Done(&cs->list);
}
static void
CandidateSearcher_Add(CandidateSearcher *cs, Candidate *cand)
{
- /* TODO: filter duplicates */
- Lst_Append(&cs->list, cand);
+ /* TODO: filter duplicates */
+ Lst_Append(&cs->list, cand);
}
static void
CandidateSearcher_AddIfNew(CandidateSearcher *cs, Candidate *cand)
{
- /* TODO: filter duplicates */
- if (Lst_FindDatum(&cs->list, cand) == NULL)
- Lst_Append(&cs->list, cand);
+ /* TODO: filter duplicates */
+ if (Lst_FindDatum(&cs->list, cand) == NULL)
+ Lst_Append(&cs->list, cand);
}
static void
CandidateSearcher_MoveAll(CandidateSearcher *cs, CandidateList *list)
{
- /* TODO: filter duplicates */
- Lst_MoveAll(&cs->list, list);
+ /* TODO: filter duplicates */
+ Lst_MoveAll(&cs->list, list);
}
@@ -937,13 +980,13 @@ CandidateSearcher_MoveAll(CandidateSearc
static void
CandidateList_PrintAddrs(CandidateList *list)
{
- CandidateListNode *ln;
+ CandidateListNode *ln;
- for (ln = list->first; ln != NULL; ln = ln->next) {
- Candidate *cand = ln->datum;
- debug_printf(" %p:%s", cand, cand->file);
- }
- debug_printf("\n");
+ for (ln = list->first; ln != NULL; ln = ln->next) {
+ Candidate *cand = ln->datum;
+ debug_printf(" %p:%s", cand, cand->file);
+ }
+ debug_printf("\n");
}
#endif
@@ -951,19 +994,19 @@ static Candidate *
Candidate_New(char *name, char *prefix, Suffix *suff, Candidate *parent,
GNode *gn)
{
- Candidate *cand = bmake_malloc(sizeof *cand);
+ Candidate *cand = bmake_malloc(sizeof *cand);
- cand->file = name;
- cand->prefix = prefix;
- cand->suff = Suffix_Ref(suff);
- cand->parent = parent;
- cand->node = gn;
- cand->numChildren = 0;
+ cand->file = name;
+ cand->prefix = prefix;
+ cand->suff = Suffix_Ref(suff);
+ cand->parent = parent;
+ cand->node = gn;
+ cand->numChildren = 0;
#ifdef DEBUG_SRC
- Lst_Init(&cand->childrenList);
+ Lst_Init(&cand->childrenList);
#endif
- return cand;
+ return cand;
}
/* Add a new candidate to the list. */
@@ -971,139 +1014,150 @@ static void
CandidateList_Add(CandidateList *list, char *srcName, Candidate *targ,
Suffix *suff, const char *debug_tag)
{
- Candidate *cand = Candidate_New(srcName, targ->prefix, suff, targ, NULL);
- targ->numChildren++;
- Lst_Append(list, cand);
+ Candidate *cand = Candidate_New(srcName, targ->prefix, suff, targ,
+ NULL);
+ targ->numChildren++;
+ Lst_Append(list, cand);
#ifdef DEBUG_SRC
- Lst_Append(&targ->childrenList, cand);
- debug_printf("%s add suff %p:%s candidate %p:%s to list %p:",
- debug_tag, targ, targ->file, cand, cand->file, list);
- CandidateList_PrintAddrs(list);
+ Lst_Append(&targ->childrenList, cand);
+ debug_printf("%s add suff %p:%s candidate %p:%s to list %p:",
+ debug_tag, targ, targ->file, cand, cand->file, list);
+ CandidateList_PrintAddrs(list);
#endif
}
-/* Add all candidates to the list that can be formed by applying a suffix to
- * the candidate. */
+/*
+ * Add all candidates to the list that can be formed by applying a suffix to
+ * the candidate.
+ */
static void
CandidateList_AddCandidatesFor(CandidateList *list, Candidate *cand)
{
- SuffixListNode *ln;
- for (ln = cand->suff->children.first; ln != NULL; ln = ln->next) {
- Suffix *suff = ln->datum;
-
- if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') {
- /*
- * If the suffix has been marked as the NULL suffix, also
- * create a candidate for a file with no suffix attached.
- */
- CandidateList_Add(list, bmake_strdup(cand->prefix),
- cand, suff, "1");
- }
-
- CandidateList_Add(list, str_concat2(cand->prefix, suff->name),
- cand, suff, "2");
- }
+ SuffixListNode *ln;
+ for (ln = cand->suff->children.first; ln != NULL; ln = ln->next) {
+ Suffix *suff = ln->datum;
+
+ if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') {
+ /*
+ * If the suffix has been marked as the NULL suffix,
+ * also create a candidate for a file with no suffix
+ * attached.
+ */
+ CandidateList_Add(list, bmake_strdup(cand->prefix),
+ cand, suff, "1");
+ }
+
+ CandidateList_Add(list, str_concat2(cand->prefix, suff->name),
+ cand, suff, "2");
+ }
}
-/* Free the first candidate in the list that is not referenced anymore.
- * Return whether a candidate was removed. */
+/*
+ * Free the first candidate in the list that is not referenced anymore.
+ * Return whether a candidate was removed.
+ */
static Boolean
RemoveCandidate(CandidateList *srcs)
{
- CandidateListNode *ln;
+ CandidateListNode *ln;
#ifdef DEBUG_SRC
- debug_printf("cleaning list %p:", srcs);
- CandidateList_PrintAddrs(srcs);
+ debug_printf("cleaning list %p:", srcs);
+ CandidateList_PrintAddrs(srcs);
#endif
- for (ln = srcs->first; ln != NULL; ln = ln->next) {
- Candidate *src = ln->datum;
+ for (ln = srcs->first; ln != NULL; ln = ln->next) {
+ Candidate *src = ln->datum;
- if (src->numChildren == 0) {
- free(src->file);
- if (src->parent == NULL)
- free(src->prefix);
- else {
+ if (src->numChildren == 0) {
+ free(src->file);
+ if (src->parent == NULL)
+ free(src->prefix);
+ else {
#ifdef DEBUG_SRC
- /* XXX: Lst_RemoveDatum */
- CandidateListNode *ln2;
- ln2 = Lst_FindDatum(&src->parent->childrenList, src);
- if (ln2 != NULL)
- Lst_Remove(&src->parent->childrenList, ln2);
+ /* XXX: Lst_RemoveDatum */
+ CandidateListNode *ln2;
+ ln2 = Lst_FindDatum(&src->parent->childrenList,
+ src);
+ if (ln2 != NULL)
+ Lst_Remove(&src->parent->childrenList,
+ ln2);
#endif
- src->parent->numChildren--;
- }
+ src->parent->numChildren--;
+ }
#ifdef DEBUG_SRC
- debug_printf("free: list %p src %p:%s children %d\n",
- srcs, src, src->file, src->numChildren);
- Lst_Done(&src->childrenList);
+ debug_printf("free: list %p src %p:%s children %d\n",
+ srcs, src, src->file, src->numChildren);
+ Lst_Done(&src->childrenList);
#endif
- Lst_Remove(srcs, ln);
- free(src);
- return TRUE;
- }
+ Lst_Remove(srcs, ln);
+ free(src);
+ return TRUE;
+ }
#ifdef DEBUG_SRC
- else {
- debug_printf("keep: list %p src %p:%s children %d:",
- srcs, src, src->file, src->numChildren);
- CandidateList_PrintAddrs(&src->childrenList);
- }
+ else {
+ debug_printf("keep: list %p src %p:%s children %d:",
+ srcs, src, src->file, src->numChildren);
+ CandidateList_PrintAddrs(&src->childrenList);
+ }
#endif
- }
+ }
- return FALSE;
+ return FALSE;
}
/* Find the first existing file/target in srcs. */
static Candidate *
FindThem(CandidateList *srcs, CandidateSearcher *cs)
{
- HashSet seen;
+ HashSet seen;
- HashSet_Init(&seen);
+ HashSet_Init(&seen);
- while (!Lst_IsEmpty(srcs)) {
- Candidate *src = Lst_Dequeue(srcs);
+ while (!Lst_IsEmpty(srcs)) {
+ Candidate *src = Lst_Dequeue(srcs);
#ifdef DEBUG_SRC
- debug_printf("remove from list %p src %p:%s\n", srcs, src, src->file);
+ debug_printf("remove from list %p src %p:%s\n",
+ srcs, src, src->file);
#endif
- SUFF_DEBUG1("\ttrying %s...", src->file);
+ SUFF_DEBUG1("\ttrying %s...", src->file);
- /*
- * A file is considered to exist if either a node exists in the
- * graph for it or the file actually exists.
- */
- if (Targ_FindNode(src->file) != NULL) {
- found:
- HashSet_Done(&seen);
- SUFF_DEBUG0("got it\n");
- return src;
- }
+ /*
+ * A file is considered to exist if either a node exists in the
+ * graph for it or the file actually exists.
+ */
+ if (Targ_FindNode(src->file) != NULL) {
+ found:
+ HashSet_Done(&seen);
+ SUFF_DEBUG0("got it\n");
+ return src;
+ }
- {
- char *file = Dir_FindFile(src->file, src->suff->searchPath);
- if (file != NULL) {
- free(file);
- goto found;
- }
- }
+ {
+ char *file = Dir_FindFile(src->file,
+ src->suff->searchPath);
+ if (file != NULL) {
+ free(file);
+ goto found;
+ }
+ }
- SUFF_DEBUG0("not there\n");
+ SUFF_DEBUG0("not there\n");
- if (HashSet_Add(&seen, src->file))
- CandidateList_AddCandidatesFor(srcs, src);
- else {
- SUFF_DEBUG1("FindThem: skipping duplicate \"%s\"\n", src->file);
- }
+ if (HashSet_Add(&seen, src->file))
+ CandidateList_AddCandidatesFor(srcs, src);
+ else {
+ SUFF_DEBUG1("FindThem: skipping duplicate \"%s\"\n",
+ src->file);
+ }
- CandidateSearcher_Add(cs, src);
- }
+ CandidateSearcher_Add(cs, src);
+ }
- HashSet_Done(&seen);
- return NULL;
+ HashSet_Done(&seen);
+ return NULL;
}
/*
@@ -1114,115 +1168,117 @@ FindThem(CandidateList *srcs, CandidateS
static Candidate *
FindCmds(Candidate *targ, CandidateSearcher *cs)
{
- GNodeListNode *gln;
- GNode *tgn; /* Target GNode */
- GNode *sgn; /* Source GNode */
- size_t prefLen; /* The length of the defined prefix */
- Suffix *suff; /* Suffix on matching beastie */
- Candidate *ret; /* Return value */
- char *cp;
-
- tgn = targ->node;
- prefLen = strlen(targ->prefix);
-
- for (gln = tgn->children.first; gln != NULL; gln = gln->next) {
- sgn = gln->datum;
-
- if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(&tgn->commands)) {
- /*
- * We haven't looked to see if .OPTIONAL files exist yet, so
- * don't use one as the implicit source.
- * This allows us to use .OPTIONAL in .depend files so make won't
- * complain "don't know how to make xxx.h' when a dependent file
- * has been moved/deleted.
- */
- continue;
- }
-
- cp = strrchr(sgn->name, '/');
- if (cp == NULL) {
- cp = sgn->name;
- } else {
- cp++;
- }
- if (strncmp(cp, targ->prefix, prefLen) != 0)
- continue;
- /* The node matches the prefix ok, see if it has a known suffix. */
- suff = FindSuffixByName(cp + prefLen);
- if (suff == NULL)
- continue;
+ GNodeListNode *gln;
+ GNode *tgn; /* Target GNode */
+ GNode *sgn; /* Source GNode */
+ size_t prefLen; /* The length of the defined prefix */
+ Suffix *suff; /* Suffix on matching beastie */
+ Candidate *ret; /* Return value */
+ char *cp;
+
+ tgn = targ->node;
+ prefLen = strlen(targ->prefix);
+
+ for (gln = tgn->children.first; gln != NULL; gln = gln->next) {
+ sgn = gln->datum;
+
+ if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(&tgn->commands)) {
+ /*
+ * We haven't looked to see if .OPTIONAL files exist
+ * yet, so don't use one as the implicit source.
+ * This allows us to use .OPTIONAL in .depend files so
+ * make won't complain "don't know how to make xxx.h"
+ * when a dependent file has been moved/deleted.
+ */
+ continue;
+ }
- /*
- * It even has a known suffix, see if there's a transformation
- * defined between the node's suffix and the target's suffix.
- *
- * XXX: Handle multi-stage transformations here, too.
- */
+ cp = strrchr(sgn->name, '/');
+ if (cp == NULL) {
+ cp = sgn->name;
+ } else {
+ cp++;
+ }
+ if (strncmp(cp, targ->prefix, prefLen) != 0)
+ continue;
+ /* The node matches the prefix, see if it has a known suffix. */
+ suff = FindSuffixByName(cp + prefLen);
+ if (suff == NULL)
+ continue;
- if (Lst_FindDatum(&suff->parents, targ->suff) != NULL)
- break;
- }
+ /*
+ * It even has a known suffix, see if there's a transformation
+ * defined between the node's suffix and the target's suffix.
+ *
+ * XXX: Handle multi-stage transformations here, too.
+ */
- if (gln == NULL)
- return NULL;
+ if (Lst_FindDatum(&suff->parents, targ->suff) != NULL)
+ break;
+ }
+
+ if (gln == NULL)
+ return NULL;
- ret = Candidate_New(bmake_strdup(sgn->name), targ->prefix, suff, targ, sgn);
- targ->numChildren++;
+ ret = Candidate_New(bmake_strdup(sgn->name), targ->prefix, suff, targ,
+ sgn);
+ targ->numChildren++;
#ifdef DEBUG_SRC
- debug_printf("3 add targ %p:%s ret %p:%s\n",
- targ, targ->file, ret, ret->file);
- Lst_Append(&targ->childrenList, ret);
+ debug_printf("3 add targ %p:%s ret %p:%s\n",
+ targ, targ->file, ret, ret->file);
+ Lst_Append(&targ->childrenList, ret);
#endif
- CandidateSearcher_Add(cs, ret);
- SUFF_DEBUG1("\tusing existing source %s\n", sgn->name);
- return ret;
+ CandidateSearcher_Add(cs, ret);
+ SUFF_DEBUG1("\tusing existing source %s\n", sgn->name);
+ return ret;
}
static void
ExpandWildcards(GNodeListNode *cln, GNode *pgn)
{
- GNode *cgn = cln->datum;
- StringList expansions;
+ GNode *cgn = cln->datum;
+ StringList expansions;
- if (!Dir_HasWildcards(cgn->name))
- return;
+ if (!Dir_HasWildcards(cgn->name))
+ return;
- /*
- * Expand the word along the chosen path
- */
- Lst_Init(&expansions);
- Dir_Expand(cgn->name, Suff_FindPath(cgn), &expansions);
-
- while (!Lst_IsEmpty(&expansions)) {
- GNode *gn;
/*
- * Fetch next expansion off the list and find its GNode
+ * Expand the word along the chosen path
*/
- char *cp = Lst_Dequeue(&expansions);
+ Lst_Init(&expansions);
+ Dir_Expand(cgn->name, Suff_FindPath(cgn), &expansions);
+
+ while (!Lst_IsEmpty(&expansions)) {
+ GNode *gn;
+ /*
+ * Fetch next expansion off the list and find its GNode
+ */
+ char *cp = Lst_Dequeue(&expansions);
- SUFF_DEBUG1("%s...", cp);
- gn = Targ_GetNode(cp);
+ SUFF_DEBUG1("%s...", cp);
+ gn = Targ_GetNode(cp);
- /* Add gn to the parents child list before the original child */
- Lst_InsertBefore(&pgn->children, cln, gn);
- Lst_Append(&gn->parents, pgn);
- pgn->unmade++;
- }
+ /* Add gn to the parents child list before the original child */
+ Lst_InsertBefore(&pgn->children, cln, gn);
+ Lst_Append(&gn->parents, pgn);
+ pgn->unmade++;
+ }
- Lst_Done(&expansions);
+ Lst_Done(&expansions);
- SUFF_DEBUG0("\n");
+ SUFF_DEBUG0("\n");
- /*
- * Now the source is expanded, remove it from the list of children to
- * keep it from being processed.
- */
- pgn->unmade--;
- Lst_Remove(&pgn->children, cln);
- Lst_Remove(&cgn->parents, Lst_FindDatum(&cgn->parents, pgn));
+ /*
+ * Now the source is expanded, remove it from the list of children to
+ * keep it from being processed.
+ */
+ pgn->unmade--;
+ Lst_Remove(&pgn->children, cln);
+ Lst_Remove(&cgn->parents, Lst_FindDatum(&cgn->parents, pgn));
}
-/* Expand the names of any children of a given node that contain variable
+/*
+ * Expand the names of any children of a given node that contain variable
* expressions or file wildcards into actual targets.
*
* The expanded node is removed from the parent's list of children, and the
@@ -1235,160 +1291,170 @@ ExpandWildcards(GNodeListNode *cln, GNod
static void
ExpandChildren(GNodeListNode *cln, GNode *pgn)
{
- GNode *cgn = cln->datum;
- GNode *gn; /* New source 8) */
- char *cp; /* Expanded value */
-
- if (!Lst_IsEmpty(&cgn->order_pred) || !Lst_IsEmpty(&cgn->order_succ))
- /* It is all too hard to process the result of .ORDER */
- return;
-
- if (cgn->type & OP_WAIT)
- /* Ignore these (& OP_PHONY ?) */
- return;
-
- /*
- * First do variable expansion -- this takes precedence over
- * wildcard expansion. If the result contains wildcards, they'll be gotten
- * to later since the resulting words are tacked on to the end of
- * the children list.
- */
- if (strchr(cgn->name, '$') == NULL) {
- ExpandWildcards(cln, pgn);
- return;
- }
-
- SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
- (void)Var_Subst(cgn->name, pgn, VARE_WANTRES | VARE_UNDEFERR, &cp);
- /* TODO: handle errors */
-
- {
- GNodeList members = LST_INIT;
-
- if (cgn->type & OP_ARCHV) {
- /*
- * Node was an archive(member) target, so we want to call
- * on the Arch module to find the nodes for us, expanding
- * variables in the parent's context.
- */
- char *sacrifice = cp;
+ GNode *cgn = cln->datum;
+ char *cp; /* Expanded value */
- (void)Arch_ParseArchive(&sacrifice, &members, pgn);
- } else {
- /*
- * Break the result into a vector of strings whose nodes
- * we can find, then add those nodes to the members list.
- * Unfortunately, we can't use Str_Words because it
- * doesn't understand about variable specifications with
- * spaces in them...
- */
- char *start;
- char *initcp = cp; /* For freeing... */
-
- start = cp;
- pp_skip_hspace(&start);
- cp = start;
- while (*cp != '\0') {
- if (*cp == ' ' || *cp == '\t') {
- /*
- * White-space -- terminate element, find the node,
- * add it, skip any further spaces.
- */
- *cp++ = '\0';
- gn = Targ_GetNode(start);
- Lst_Append(&members, gn);
- pp_skip_hspace(&cp);
- start = cp; /* Continue at the next non-space. */
- } else if (*cp == '$') {
- /* Skip over the variable expression. */
- const char *nested_p = cp;
- const char *junk;
- void *freeIt;
-
- (void)Var_Parse(&nested_p, pgn, VARE_NONE, &junk, &freeIt);
- /* TODO: handle errors */
- if (junk == var_Error) {
- Parse_Error(PARSE_FATAL,
- "Malformed variable expression at \"%s\"",
- cp);
- cp++;
- } else {
- cp += nested_p - cp;
- }
-
- free(freeIt);
- } else if (cp[0] == '\\' && cp[1] != '\0') {
- /*
- * Escaped something -- skip over it
- */
- /* XXX: In other places, escaping at this syntactical
- * position is done by a '$', not a '\'. The '\' is only
- * used in variable modifiers. */
- cp += 2;
+ if (!Lst_IsEmpty(&cgn->order_pred) || !Lst_IsEmpty(&cgn->order_succ))
+ /* It is all too hard to process the result of .ORDER */
+ return;
+
+ if (cgn->type & OP_WAIT)
+ /* Ignore these (& OP_PHONY ?) */
+ return;
+
+ /*
+ * First do variable expansion -- this takes precedence over wildcard
+ * expansion. If the result contains wildcards, they'll be gotten to
+ * later since the resulting words are tacked on to the end of the
+ * children list.
+ */
+ if (strchr(cgn->name, '$') == NULL) {
+ ExpandWildcards(cln, pgn);
+ return;
+ }
+
+ SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
+ (void)Var_Subst(cgn->name, pgn, VARE_WANTRES | VARE_UNDEFERR, &cp);
+ /* TODO: handle errors */
+
+ {
+ GNodeList members = LST_INIT;
+
+ if (cgn->type & OP_ARCHV) {
+ /*
+ * Node was an archive(member) target, so we want to
+ * call on the Arch module to find the nodes for us,
+ * expanding variables in the parent's context.
+ */
+ char *sacrifice = cp;
+
+ (void)Arch_ParseArchive(&sacrifice, &members, pgn);
} else {
- cp++;
+ /*
+ * Break the result into a vector of strings whose
+ * nodes we can find, then add those nodes to the
+ * members list.
+ *
+ * Unfortunately, we can't use Str_Words because it
+ * doesn't understand about variable specifications
+ * with spaces in them.
+ */
+ char *start;
+ char *initcp = cp; /* For freeing... */
+
+ start = cp;
+ pp_skip_hspace(&start);
+ cp = start;
+ while (*cp != '\0') {
+ if (*cp == ' ' || *cp == '\t') {
+ GNode *gn;
+ /*
+ * White-space -- terminate element,
+ * find the node, add it, skip any
+ * further spaces.
+ */
+ *cp++ = '\0';
+ gn = Targ_GetNode(start);
+ Lst_Append(&members, gn);
+ pp_skip_hspace(&cp);
+ /* Continue at the next non-space. */
+ start = cp;
+ } else if (*cp == '$') {
+ /* Skip over the variable expression. */
+ const char *nested_p = cp;
+ const char *junk;
+ void *freeIt;
+
+ (void)Var_Parse(&nested_p, pgn,
+ VARE_NONE, &junk, &freeIt);
+ /* TODO: handle errors */
+ if (junk == var_Error) {
+ Parse_Error(PARSE_FATAL,
+ "Malformed variable "
+ "expression at \"%s\"",
+ cp);
+ cp++;
+ } else {
+ cp += nested_p - cp;
+ }
+
+ free(freeIt);
+ } else if (cp[0] == '\\' && cp[1] != '\0') {
+ /*
+ * Escaped something -- skip over it
+ */
+ /*
+ * XXX: In other places, escaping at
+ * this syntactical position is done
+ * by a '$', not a '\'. The '\' is
+ * only used in variable modifiers.
+ */
+ cp += 2;
+ } else {
+ cp++;
+ }
+ }
+
+ if (cp != start) {
+ /*
+ * Stuff left over -- add it to the list too
+ */
+ GNode *gn = Targ_GetNode(start);
+ Lst_Append(&members, gn);
+ }
+ /*
+ * Point cp back at the beginning again so the
+ * variable value can be freed.
+ */
+ cp = initcp;
}
- }
- if (cp != start) {
/*
- * Stuff left over -- add it to the list too
+ * Add all elements of the members list to the parent node.
*/
- gn = Targ_GetNode(start);
- Lst_Append(&members, gn);
- }
- /*
- * Point cp back at the beginning again so the variable value
- * can be freed.
- */
- cp = initcp;
- }
+ while (!Lst_IsEmpty(&members)) {
+ GNode *gn = Lst_Dequeue(&members);
- /*
- * Add all elements of the members list to the parent node.
- */
- while(!Lst_IsEmpty(&members)) {
- gn = Lst_Dequeue(&members);
+ SUFF_DEBUG1("%s...", gn->name);
+ /*
+ * Add gn to the parents child list before the
+ * original child.
+ */
+ Lst_InsertBefore(&pgn->children, cln, gn);
+ Lst_Append(&gn->parents, pgn);
+ pgn->unmade++;
+ /* Expand wildcards on new node */
+ ExpandWildcards(cln->prev, pgn);
+ }
+ Lst_Done(&members);
- SUFF_DEBUG1("%s...", gn->name);
- /* Add gn to the parents child list before the original child */
- Lst_InsertBefore(&pgn->children, cln, gn);
- Lst_Append(&gn->parents, pgn);
- pgn->unmade++;
- /* Expand wildcards on new node */
- ExpandWildcards(cln->prev, pgn);
+ free(cp);
}
- Lst_Done(&members);
+
+ SUFF_DEBUG0("\n");
/*
- * Free the result
+ * Now the source is expanded, remove it from the list of children to
+ * keep it from being processed.
*/
- free(cp);
- }
-
- SUFF_DEBUG0("\n");
-
- /*
- * Now the source is expanded, remove it from the list of children to
- * keep it from being processed.
- */
- pgn->unmade--;
- Lst_Remove(&pgn->children, cln);
- Lst_Remove(&cgn->parents, Lst_FindDatum(&cgn->parents, pgn));
+ pgn->unmade--;
+ Lst_Remove(&pgn->children, cln);
+ Lst_Remove(&cgn->parents, Lst_FindDatum(&cgn->parents, pgn));
}
static void
ExpandAllChildren(GNode *gn)
{
- GNodeListNode *ln, *nln;
+ GNodeListNode *ln, *nln;
- for (ln = gn->children.first; ln != NULL; ln = nln) {
- nln = ln->next;
- ExpandChildren(ln, gn);
- }
+ for (ln = gn->children.first; ln != NULL; ln = nln) {
+ nln = ln->next;
+ ExpandChildren(ln, gn);
+ }
}
-/* Find a path along which to expand the node.
+/*
+ * Find a path along which to expand the node.
*
* If the node has a known suffix, use that path.
* If it has no known suffix, use the default system search path.
@@ -1400,31 +1466,34 @@ ExpandAllChildren(GNode *gn)
* The appropriate path to search for the GNode.
*/
SearchPath *
-Suff_FindPath(GNode* gn)
+Suff_FindPath(GNode *gn)
{
- Suffix *suff = gn->suffix;
+ Suffix *suff = gn->suffix;
- if (suff == NULL) {
- char *name = gn->name;
- size_t nameLen = strlen(gn->name);
- SuffixListNode *ln;
- for (ln = sufflist.first; ln != NULL; ln = ln->next)
- if (Suffix_IsSuffix(ln->datum, nameLen, name + nameLen))
- break;
-
- SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
- if (ln != NULL)
- suff = ln->datum;
- /* XXX: Here we can save the suffix so we don't have to do this again */
- }
-
- if (suff != NULL) {
- SUFF_DEBUG1("suffix is \"%s\"...\n", suff->name);
- return suff->searchPath;
- } else {
- SUFF_DEBUG0("\n");
- return &dirSearchPath; /* Use default search path */
- }
+ if (suff == NULL) {
+ char *name = gn->name;
+ size_t nameLen = strlen(gn->name);
+ SuffixListNode *ln;
+ for (ln = sufflist.first; ln != NULL; ln = ln->next)
+ if (Suffix_IsSuffix(ln->datum, nameLen, name + nameLen))
+ break;
+
+ SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
+ if (ln != NULL)
+ suff = ln->datum;
+ /*
+ * XXX: Here we can save the suffix so we don't have to do
+ * this again.
+ */
+ }
+
+ if (suff != NULL) {
+ SUFF_DEBUG1("suffix is \"%s\"...\n", suff->name);
+ return suff->searchPath;
+ } else {
+ SUFF_DEBUG0("\n");
+ return &dirSearchPath; /* Use default search path */
+ }
}
/* Apply a transformation rule, given the source and target nodes and
@@ -1440,53 +1509,48 @@ Suff_FindPath(GNode* gn)
static Boolean
ApplyTransform(GNode *tgn, GNode *sgn, Suffix *tsuff, Suffix *ssuff)
{
- GNodeListNode *ln;
- char *tname; /* Name of transformation rule */
- GNode *gn; /* Node for same */
-
- /*
- * Form the proper links between the target and source.
- */
- Lst_Append(&tgn->children, sgn);
- Lst_Append(&sgn->parents, tgn);
- tgn->unmade++;
-
- /*
- * Locate the transformation rule itself
- */
- tname = str_concat2(ssuff->name, tsuff->name);
- gn = FindTransformByName(tname);
- free(tname);
+ GNodeListNode *ln;
+ char *tname; /* Name of transformation rule */
+ GNode *gn; /* Node for the transformation rule */
+
+ /* Form the proper links between the target and source. */
+ Lst_Append(&tgn->children, sgn);
+ Lst_Append(&sgn->parents, tgn);
+ tgn->unmade++;
+
+ /* Locate the transformation rule itself. */
+ tname = str_concat2(ssuff->name, tsuff->name);
+ gn = FindTransformByName(tname);
+ free(tname);
- if (gn == NULL) {
/* This can happen when linking an OP_MEMBER and OP_ARCHV node. */
- return FALSE;
- }
+ if (gn == NULL)
+ return FALSE;
- DEBUG3(SUFF,"\tapplying %s -> %s to \"%s\"\n",
- ssuff->name, tsuff->name, tgn->name);
+ DEBUG3(SUFF, "\tapplying %s -> %s to \"%s\"\n",
+ ssuff->name, tsuff->name, tgn->name);
- /* Record last child; Make_HandleUse may add child nodes. */
- ln = tgn->children.last;
+ /* Record last child; Make_HandleUse may add child nodes. */
+ ln = tgn->children.last;
- /* Apply the rule. */
- Make_HandleUse(gn, tgn);
-
- /* Deal with wildcards and variables in any acquired sources. */
- ln = ln != NULL ? ln->next : NULL;
- while (ln != NULL) {
- GNodeListNode *nln = ln->next;
- ExpandChildren(ln, tgn);
- ln = nln;
- }
-
- /*
- * Keep track of another parent to which this node is transformed so
- * the .IMPSRC variable can be set correctly for the parent.
- */
- Lst_Append(&sgn->implicitParents, tgn);
+ /* Apply the rule. */
+ Make_HandleUse(gn, tgn);
+
+ /* Deal with wildcards and variables in any acquired sources. */
+ ln = ln != NULL ? ln->next : NULL;
+ while (ln != NULL) {
+ GNodeListNode *nln = ln->next;
+ ExpandChildren(ln, tgn);
+ ln = nln;
+ }
+
+ /*
+ * Keep track of another parent to which this node is transformed so
+ * the .IMPSRC variable can be set correctly for the parent.
+ */
+ Lst_Append(&sgn->implicitParents, tgn);
- return TRUE;
+ return TRUE;
}
/*
@@ -1499,22 +1563,22 @@ ApplyTransform(GNode *tgn, GNode *sgn, S
static void
ExpandMember(GNode *gn, const char *eoarch, GNode *mem, Suffix *memSuff)
{
- GNodeListNode *ln;
- size_t nameLen = (size_t)(eoarch - gn->name);
+ GNodeListNode *ln;
+ size_t nameLen = (size_t)(eoarch - gn->name);
- /* Use first matching suffix... */
- for (ln = memSuff->parents.first; ln != NULL; ln = ln->next)
- if (Suffix_IsSuffix(ln->datum, nameLen, eoarch))
- break;
-
- if (ln != NULL) {
- /* Got one -- apply it */
- Suffix *suff = ln->datum;
- if (!ApplyTransform(gn, mem, suff, memSuff)) {
- SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
- memSuff->name, suff->name);
+ /* Use first matching suffix... */
+ for (ln = memSuff->parents.first; ln != NULL; ln = ln->next)
+ if (Suffix_IsSuffix(ln->datum, nameLen, eoarch))
+ break;
+
+ if (ln != NULL) {
+ /* Got one -- apply it */
+ Suffix *suff = ln->datum;
+ if (!ApplyTransform(gn, mem, suff, memSuff)) {
+ SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
+ memSuff->name, suff->name);
+ }
}
- }
}
static void FindDeps(GNode *, CandidateSearcher *);
@@ -1530,102 +1594,93 @@ static void FindDeps(GNode *, CandidateS
static void
FindDepsArchive(GNode *gn, CandidateSearcher *cs)
{
- char *eoarch; /* End of archive portion */
- char *eoname; /* End of member portion */
- GNode *mem; /* Node for member */
- Suffix *memSuff;
- const char *name; /* Start of member's name */
-
- /*
- * The node is an archive(member) pair. so we must find a
- * suffix for both of them.
- */
- eoarch = strchr(gn->name, '(');
- eoname = strchr(eoarch, ')');
-
- /*
- * Caller guarantees the format `libname(member)', via
- * Arch_ParseArchive.
- */
- assert(eoarch != NULL);
- assert(eoname != NULL);
-
- *eoname = '\0'; /* Nuke parentheses during suffix search */
- *eoarch = '\0'; /* So a suffix can be found */
-
- name = eoarch + 1;
-
- /*
- * To simplify things, call Suff_FindDeps recursively on the member now,
- * so we can simply compare the member's .PREFIX and .TARGET variables
- * to locate its suffix. This allows us to figure out the suffix to
- * use for the archive without having to do a quadratic search over the
- * suffix list, backtracking for each one...
- */
- mem = Targ_GetNode(name);
- FindDeps(mem, cs);
-
- /*
- * Create the link between the two nodes right off
- */
- Lst_Append(&gn->children, mem);
- Lst_Append(&mem->parents, gn);
- gn->unmade++;
-
- /*
- * Copy in the variables from the member node to this one.
- */
- Var_Set(PREFIX, GNode_VarPrefix(mem), gn);
- Var_Set(TARGET, GNode_VarTarget(mem), gn);
-
- memSuff = mem->suffix;
- if (memSuff == NULL) { /* Didn't know what it was. */
- SUFF_DEBUG0("using null suffix\n");
- memSuff = nullSuff;
- }
-
-
- /*
- * Set the other two local variables required for this target.
- */
- Var_Set(MEMBER, name, gn);
- Var_Set(ARCHIVE, gn->name, gn);
-
- /*
- * Set $@ for compatibility with other makes
- */
- Var_Set(TARGET, gn->name, gn);
-
- /*
- * Now we've got the important local variables set, expand any sources
- * that still contain variables or wildcards in their names.
- */
- ExpandAllChildren(gn);
-
- if (memSuff != NULL)
- ExpandMember(gn, eoarch, mem, memSuff);
-
- /*
- * Replace the opening and closing parens now we've no need of the separate
- * pieces.
- */
- *eoarch = '(';
- *eoname = ')';
-
- /*
- * Pretend gn appeared to the left of a dependency operator so
- * the user needn't provide a transformation from the member to the
- * archive.
- */
- if (!GNode_IsTarget(gn))
- gn->type |= OP_DEPENDS;
-
- /*
- * Flag the member as such so we remember to look in the archive for
- * its modification time. The OP_JOIN | OP_MADE is needed because this
- * target should never get made.
- */
- mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
+ char *eoarch; /* End of archive portion */
+ char *eoname; /* End of member portion */
+ GNode *mem; /* Node for member */
+ Suffix *memSuff;
+ const char *name; /* Start of member's name */
+
+ /*
+ * The node is an archive(member) pair. so we must find a
+ * suffix for both of them.
+ */
+ eoarch = strchr(gn->name, '(');
+ eoname = strchr(eoarch, ')');
+
+ /*
+ * Caller guarantees the format `libname(member)', via
+ * Arch_ParseArchive.
+ */
+ assert(eoarch != NULL);
+ assert(eoname != NULL);
+
+ *eoname = '\0'; /* Nuke parentheses during suffix search */
+ *eoarch = '\0'; /* So a suffix can be found */
+
+ name = eoarch + 1;
+
+ /*
+ * To simplify things, call Suff_FindDeps recursively on the member
+ * now, so we can simply compare the member's .PREFIX and .TARGET
+ * variables to locate its suffix. This allows us to figure out the
+ * suffix to use for the archive without having to do a quadratic
+ * search over the suffix list, backtracking for each one.
+ */
+ mem = Targ_GetNode(name);
+ FindDeps(mem, cs);
+
+ /* Create the link between the two nodes right off. */
+ Lst_Append(&gn->children, mem);
+ Lst_Append(&mem->parents, gn);
+ gn->unmade++;
+
+ /* Copy in the variables from the member node to this one. */
+ Var_Set(PREFIX, GNode_VarPrefix(mem), gn);
+ Var_Set(TARGET, GNode_VarTarget(mem), gn);
+
+ memSuff = mem->suffix;
+ if (memSuff == NULL) { /* Didn't know what it was. */
+ SUFF_DEBUG0("using null suffix\n");
+ memSuff = nullSuff;
+ }
+
+
+ /* Set the other two local variables required for this target. */
+ Var_Set(MEMBER, name, gn);
+ Var_Set(ARCHIVE, gn->name, gn);
+ /* Set $@ for compatibility with other makes. */
+ Var_Set(TARGET, gn->name, gn);
+
+ /*
+ * Now we've got the important local variables set, expand any sources
+ * that still contain variables or wildcards in their names.
+ */
+ ExpandAllChildren(gn);
+
+ if (memSuff != NULL)
+ ExpandMember(gn, eoarch, mem, memSuff);
+
+ /*
+ * Replace the opening and closing parens now we've no need of the
+ * separate pieces.
+ */
+ *eoarch = '(';
+ *eoname = ')';
+
+ /*
+ * Pretend gn appeared to the left of a dependency operator so the
+ * user needn't provide a transformation from the member to the
+ * archive.
+ */
+ if (!GNode_IsTarget(gn))
+ gn->type |= OP_DEPENDS;
+
+ /*
+ * Flag the member as such so we remember to look in the archive for
+ * its modification time. The OP_JOIN | OP_MADE is needed because
+ * this target should never get made.
+ */
+ mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
}
/*
@@ -1639,138 +1694,141 @@ FindDepsArchive(GNode *gn, CandidateSear
static void
FindDepsLib(GNode *gn)
{
- Suffix *suff = FindSuffixByName(LIBSUFF);
- if (suff != NULL) {
- Suffix_Reassign(&gn->suffix, suff);
- Arch_FindLib(gn, suff->searchPath);
- } else {
- Suffix_Unassign(&gn->suffix);
- Var_Set(TARGET, gn->name, gn);
- }
+ Suffix *suff = FindSuffixByName(LIBSUFF);
+ if (suff != NULL) {
+ Suffix_Reassign(&gn->suffix, suff);
+ Arch_FindLib(gn, suff->searchPath);
+ } else {
+ Suffix_Unassign(&gn->suffix);
+ Var_Set(TARGET, gn->name, gn);
+ }
- /*
- * Because a library (-lfoo) target doesn't follow the standard
- * filesystem conventions, we don't set the regular variables for
- * the thing. .PREFIX is simply made empty.
- */
- Var_Set(PREFIX, "", gn);
+ /*
+ * Because a library (-lfoo) target doesn't follow the standard
+ * filesystem conventions, we don't set the regular variables for
+ * the thing. .PREFIX is simply made empty.
+ */
+ Var_Set(PREFIX, "", gn);
}
static void
FindDepsRegularKnown(const char *name, size_t nameLen, GNode *gn,
CandidateList *srcs, CandidateList *targs)
{
- SuffixListNode *ln;
- Candidate *targ;
- char *pref;
-
- for (ln = sufflist.first; ln != NULL; ln = ln->next) {
- Suffix *suff = ln->datum;
- if (!Suffix_IsSuffix(suff, nameLen, name + nameLen))
- continue;
+ SuffixListNode *ln;
+ Candidate *targ;
+ char *pref;
- pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen));
- targ = Candidate_New(bmake_strdup(gn->name), pref, suff, NULL, gn);
+ for (ln = sufflist.first; ln != NULL; ln = ln->next) {
+ Suffix *suff = ln->datum;
+ if (!Suffix_IsSuffix(suff, nameLen, name + nameLen))
+ continue;
+
+ pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen));
+ targ = Candidate_New(bmake_strdup(gn->name), pref, suff, NULL,
+ gn);
- CandidateList_AddCandidatesFor(srcs, targ);
+ CandidateList_AddCandidatesFor(srcs, targ);
- /*
- * Record the target so we can nuke it
- */
- Lst_Append(targs, targ);
- }
+ /* Record the target so we can nuke it. */
+ Lst_Append(targs, targ);
+ }
}
static void
FindDepsRegularUnknown(GNode *gn, const char *sopref,
CandidateList *srcs, CandidateList *targs)
{
- Candidate *targ;
+ Candidate *targ;
- if (!Lst_IsEmpty(targs) || nullSuff == NULL)
- return;
+ if (!Lst_IsEmpty(targs) || nullSuff == NULL)
+ return;
- SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
+ SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
- targ = Candidate_New(bmake_strdup(gn->name), bmake_strdup(sopref),
- nullSuff, NULL, gn);
+ targ = Candidate_New(bmake_strdup(gn->name), bmake_strdup(sopref),
+ nullSuff, NULL, gn);
- /*
- * Only use the default suffix rules if we don't have commands
- * defined for this gnode; traditional make programs used to
- * not define suffix rules if the gnode had children but we
- * don't do this anymore.
- */
- if (Lst_IsEmpty(&gn->commands))
- CandidateList_AddCandidatesFor(srcs, targ);
- else {
- SUFF_DEBUG0("not ");
- }
+ /*
+ * Only use the default suffix rules if we don't have commands
+ * defined for this gnode; traditional make programs used to not
+ * define suffix rules if the gnode had children but we don't do
+ * this anymore.
+ */
+ if (Lst_IsEmpty(&gn->commands))
+ CandidateList_AddCandidatesFor(srcs, targ);
+ else {
+ SUFF_DEBUG0("not ");
+ }
- SUFF_DEBUG0("adding suffix rules\n");
+ SUFF_DEBUG0("adding suffix rules\n");
- Lst_Append(targs, targ);
+ Lst_Append(targs, targ);
}
/*
- * Deal with finding the thing on the default search path. We
- * always do that, not only if the node is only a source (not
- * on the lhs of a dependency operator or [XXX] it has neither
- * children or commands) as the old pmake did.
+ * Deal with finding the thing on the default search path. We always do
+ * that, not only if the node is only a source (not on the lhs of a
+ * dependency operator or [XXX] it has neither children or commands) as
+ * the old pmake did.
*/
static void
FindDepsRegularPath(GNode *gn, Candidate *targ)
{
- if (gn->type & (OP_PHONY | OP_NOPATH))
- return;
+ if (gn->type & (OP_PHONY | OP_NOPATH))
+ return;
- free(gn->path);
- gn->path = Dir_FindFile(gn->name,
- (targ == NULL ? &dirSearchPath :
- targ->suff->searchPath));
- if (gn->path == NULL)
- return;
+ free(gn->path);
+ gn->path = Dir_FindFile(gn->name,
+ (targ == NULL ? &dirSearchPath :
+ targ->suff->searchPath));
+ if (gn->path == NULL)
+ return;
- Var_Set(TARGET, gn->path, gn);
+ Var_Set(TARGET, gn->path, gn);
- if (targ != NULL) {
- /*
- * Suffix known for the thing -- trim the suffix off
- * the path to form the proper .PREFIX variable.
- */
- size_t savep = strlen(gn->path) - targ->suff->nameLen;
- char savec;
- char *ptr;
+ if (targ != NULL) {
+ /*
+ * Suffix known for the thing -- trim the suffix off
+ * the path to form the proper .PREFIX variable.
+ */
+ size_t savep = strlen(gn->path) - targ->suff->nameLen;
+ char savec;
+ char *ptr;
- Suffix_Reassign(&gn->suffix, targ->suff);
+ Suffix_Reassign(&gn->suffix, targ->suff);
- savec = gn->path[savep];
- gn->path[savep] = '\0';
+ savec = gn->path[savep];
+ gn->path[savep] = '\0';
- if ((ptr = strrchr(gn->path, '/')) != NULL)
- ptr++;
- else
- ptr = gn->path;
+ if ((ptr = strrchr(gn->path, '/')) != NULL)
+ ptr++;
+ else
+ ptr = gn->path;
- Var_Set(PREFIX, ptr, gn);
+ Var_Set(PREFIX, ptr, gn);
- gn->path[savep] = savec;
- } else {
- char *ptr;
+ gn->path[savep] = savec;
+ } else {
+ char *ptr;
- /* The .PREFIX gets the full path if the target has no known suffix. */
- Suffix_Unassign(&gn->suffix);
+ /*
+ * The .PREFIX gets the full path if the target has no
+ * known suffix.
+ */
+ Suffix_Unassign(&gn->suffix);
- if ((ptr = strrchr(gn->path, '/')) != NULL)
- ptr++;
- else
- ptr = gn->path;
+ if ((ptr = strrchr(gn->path, '/')) != NULL)
+ ptr++;
+ else
+ ptr = gn->path;
- Var_Set(PREFIX, ptr, gn);
- }
+ Var_Set(PREFIX, ptr, gn);
+ }
}
-/* Locate implicit dependencies for regular targets.
+/*
+ * Locate implicit dependencies for regular targets.
*
* Input:
* gn Node for which to find sources
@@ -1781,195 +1839,199 @@ FindDepsRegularPath(GNode *gn, Candidate
static void
FindDepsRegular(GNode *gn, CandidateSearcher *cs)
{
- /* List of sources at which to look */
- CandidateList srcs = LST_INIT;
- /* List of targets to which things can be transformed.
- * They all have the same file, but different suff and prefix fields. */
- CandidateList targs = LST_INIT;
- Candidate *bottom; /* Start of found transformation path */
- Candidate *src;
- Candidate *targ;
+ /* List of sources at which to look */
+ CandidateList srcs = LST_INIT;
+ /*
+ * List of targets to which things can be transformed.
+ * They all have the same file, but different suff and prefix fields.
+ */
+ CandidateList targs = LST_INIT;
+ Candidate *bottom; /* Start of found transformation path */
+ Candidate *src;
+ Candidate *targ;
- const char *name = gn->name;
- size_t nameLen = strlen(name);
+ const char *name = gn->name;
+ size_t nameLen = strlen(name);
#ifdef DEBUG_SRC
- DEBUG1(SUFF, "FindDepsRegular \"%s\"\n", gn->name);
+ DEBUG1(SUFF, "FindDepsRegular \"%s\"\n", gn->name);
#endif
- /*
- * We're caught in a catch-22 here. On the one hand, we want to use any
- * transformation implied by the target's sources, but we can't examine
- * the sources until we've expanded any variables/wildcards they may hold,
- * and we can't do that until we've set up the target's local variables
- * and we can't do that until we know what the proper suffix for the
- * target is (in case there are two suffixes one of which is a suffix of
- * the other) and we can't know that until we've found its implied
- * source, which we may not want to use if there's an existing source
- * that implies a different transformation.
- *
- * In an attempt to get around this, which may not work all the time,
- * but should work most of the time, we look for implied sources first,
- * checking transformations to all possible suffixes of the target,
- * use what we find to set the target's local variables, expand the
- * children, then look for any overriding transformations they imply.
- * Should we find one, we discard the one we found before.
- */
- bottom = NULL;
- targ = NULL;
-
- if (!(gn->type & OP_PHONY)) {
-
- FindDepsRegularKnown(name, nameLen, gn, &srcs, &targs);
+ /*
+ * We're caught in a catch-22 here. On the one hand, we want to use
+ * any transformation implied by the target's sources, but we can't
+ * examine the sources until we've expanded any variables/wildcards
+ * they may hold, and we can't do that until we've set up the
+ * target's local variables and we can't do that until we know what
+ * the proper suffix for the target is (in case there are two
+ * suffixes one of which is a suffix of the other) and we can't know
+ * that until we've found its implied source, which we may not want
+ * to use if there's an existing source that implies a different
+ * transformation.
+ *
+ * In an attempt to get around this, which may not work all the time,
+ * but should work most of the time, we look for implied sources
+ * first, checking transformations to all possible suffixes of the
+ * target, use what we find to set the target's local variables,
+ * expand the children, then look for any overriding transformations
+ * they imply. Should we find one, we discard the one we found before.
+ */
+ bottom = NULL;
+ targ = NULL;
+
+ if (!(gn->type & OP_PHONY)) {
- /* Handle target of unknown suffix... */
- FindDepsRegularUnknown(gn, name, &srcs, &targs);
+ FindDepsRegularKnown(name, nameLen, gn, &srcs, &targs);
+
+ /* Handle target of unknown suffix... */
+ FindDepsRegularUnknown(gn, name, &srcs, &targs);
+
+ /*
+ * Using the list of possible sources built up from the target
+ * suffix(es), try and find an existing file/target that
+ * matches.
+ */
+ bottom = FindThem(&srcs, cs);
+
+ if (bottom == NULL) {
+ /*
+ * No known transformations -- use the first suffix
+ * found for setting the local variables.
+ */
+ if (targs.first != NULL)
+ targ = targs.first->datum;
+ else
+ targ = NULL;
+ } else {
+ /*
+ * Work up the transformation path to find the suffix
+ * of the target to which the transformation was made.
+ */
+ for (targ = bottom;
+ targ->parent != NULL; targ = targ->parent)
+ continue;
+ }
+ }
+
+ Var_Set(TARGET, GNode_Path(gn), gn);
+ Var_Set(PREFIX, targ != NULL ? targ->prefix : gn->name, gn);
/*
- * Using the list of possible sources built up from the target
- * suffix(es), try and find an existing file/target that matches.
+ * Now we've got the important local variables set, expand any sources
+ * that still contain variables or wildcards in their names.
*/
- bottom = FindThem(&srcs, cs);
+ {
+ GNodeListNode *ln, *nln;
+ for (ln = gn->children.first; ln != NULL; ln = nln) {
+ nln = ln->next;
+ ExpandChildren(ln, gn);
+ }
+ }
+
+ if (targ == NULL) {
+ SUFF_DEBUG1("\tNo valid suffix on %s\n", gn->name);
+
+ sfnd_abort:
+ FindDepsRegularPath(gn, targ);
+ goto sfnd_return;
+ }
+
+ /*
+ * If the suffix indicates that the target is a library, mark that in
+ * the node's type field.
+ */
+ if (targ->suff->flags & SUFF_LIBRARY)
+ gn->type |= OP_LIB;
+
+ /*
+ * Check for overriding transformation rule implied by sources
+ */
+ if (!Lst_IsEmpty(&gn->children)) {
+ src = FindCmds(targ, cs);
+
+ if (src != NULL) {
+ /*
+ * Free up all the candidates in the transformation
+ * path, up to but not including the parent node.
+ */
+ while (bottom != NULL && bottom->parent != NULL) {
+ CandidateSearcher_AddIfNew(cs, bottom);
+ bottom = bottom->parent;
+ }
+ bottom = src;
+ }
+ }
if (bottom == NULL) {
- /*
- * No known transformations -- use the first suffix found
- * for setting the local variables.
- */
- if (targs.first != NULL)
- targ = targs.first->datum;
- else
- targ = NULL;
- } else {
- /*
- * Work up the transformation path to find the suffix of the
- * target to which the transformation was made.
- */
- for (targ = bottom; targ->parent != NULL; targ = targ->parent)
- continue;
+ /* No idea from where it can come -- return now. */
+ goto sfnd_abort;
}
- }
- Var_Set(TARGET, GNode_Path(gn), gn);
- Var_Set(PREFIX, targ != NULL ? targ->prefix : gn->name, gn);
+ /*
+ * We now have a list of candidates headed by 'bottom' and linked via
+ * their 'parent' pointers. What we do next is create links between
+ * source and target nodes (which may or may not have been created)
+ * and set the necessary local variables in each target.
+ *
+ * The commands for each target are set from the commands of the
+ * transformation rule used to get from the src suffix to the targ
+ * suffix. Note that this causes the commands list of the original
+ * node, gn, to be replaced with the commands of the final
+ * transformation rule.
+ */
+ if (bottom->node == NULL)
+ bottom->node = Targ_GetNode(bottom->file);
- /*
- * Now we've got the important local variables set, expand any sources
- * that still contain variables or wildcards in their names.
- */
- {
- GNodeListNode *ln, *nln;
- for (ln = gn->children.first; ln != NULL; ln = nln) {
- nln = ln->next;
- ExpandChildren(ln, gn);
+ for (src = bottom; src->parent != NULL; src = src->parent) {
+ targ = src->parent;
+
+ Suffix_Reassign(&src->node->suffix, src->suff);
+
+ if (targ->node == NULL)
+ targ->node = Targ_GetNode(targ->file);
+
+ ApplyTransform(targ->node, src->node,
+ targ->suff, src->suff);
+
+ if (targ->node != gn) {
+ /*
+ * Finish off the dependency-search process for any
+ * nodes between bottom and gn (no point in questing
+ * around the filesystem for their implicit source
+ * when it's already known). Note that the node
+ * can't have any sources that need expanding, since
+ * SuffFindThem will stop on an existing node, so all
+ * we need to do is set the standard variables.
+ */
+ targ->node->type |= OP_DEPS_FOUND;
+ Var_Set(PREFIX, targ->prefix, targ->node);
+ Var_Set(TARGET, targ->node->name, targ->node);
+ }
}
- }
- if (targ == NULL) {
- SUFF_DEBUG1("\tNo valid suffix on %s\n", gn->name);
+ Suffix_Reassign(&gn->suffix, src->suff);
-sfnd_abort:
- FindDepsRegularPath(gn, targ);
- goto sfnd_return;
- }
-
- /*
- * If the suffix indicates that the target is a library, mark that in
- * the node's type field.
- */
- if (targ->suff->flags & SUFF_LIBRARY)
- gn->type |= OP_LIB;
-
- /*
- * Check for overriding transformation rule implied by sources
- */
- if (!Lst_IsEmpty(&gn->children)) {
- src = FindCmds(targ, cs);
-
- if (src != NULL) {
- /*
- * Free up all the candidates in the transformation path,
- * up to but not including the parent node.
- */
- while (bottom != NULL && bottom->parent != NULL) {
- CandidateSearcher_AddIfNew(cs, bottom);
- bottom = bottom->parent;
- }
- bottom = src;
- }
- }
-
- if (bottom == NULL) {
- /*
- * No idea from where it can come -- return now.
- */
- goto sfnd_abort;
- }
-
- /*
- * We now have a list of candidates headed by 'bottom' and linked via
- * their 'parent' pointers. What we do next is create links between
- * source and target nodes (which may or may not have been created)
- * and set the necessary local variables in each target.
- *
- * The commands for each target are set from the commands of the
- * transformation rule used to get from the src suffix to the targ
- * suffix. Note that this causes the commands list of the original
- * node, gn, to be replaced with the commands of the final
- * transformation rule.
- */
- if (bottom->node == NULL)
- bottom->node = Targ_GetNode(bottom->file);
-
- for (src = bottom; src->parent != NULL; src = src->parent) {
- targ = src->parent;
-
- Suffix_Reassign(&src->node->suffix, src->suff);
-
- if (targ->node == NULL)
- targ->node = Targ_GetNode(targ->file);
-
- ApplyTransform(targ->node, src->node,
- targ->suff, src->suff);
-
- if (targ->node != gn) {
- /*
- * Finish off the dependency-search process for any nodes
- * between bottom and gn (no point in questing around the
- * filesystem for their implicit source when it's already
- * known). Note that the node can't have any sources that
- * need expanding, since SuffFindThem will stop on an existing
- * node, so all we need to do is set the standard variables.
- */
- targ->node->type |= OP_DEPS_FOUND;
- Var_Set(PREFIX, targ->prefix, targ->node);
- Var_Set(TARGET, targ->node->name, targ->node);
- }
- }
-
- Suffix_Reassign(&gn->suffix, src->suff);
-
- /*
- * Nuke the transformation path and the candidates left over in the
- * two lists.
- */
+ /*
+ * Nuke the transformation path and the candidates left over in the
+ * two lists.
+ */
sfnd_return:
- if (bottom != NULL)
- CandidateSearcher_AddIfNew(cs, bottom);
+ if (bottom != NULL)
+ CandidateSearcher_AddIfNew(cs, bottom);
- while (RemoveCandidate(&srcs) || RemoveCandidate(&targs))
- continue;
+ while (RemoveCandidate(&srcs) || RemoveCandidate(&targs))
+ continue;
- CandidateSearcher_MoveAll(cs, &srcs);
- CandidateSearcher_MoveAll(cs, &targs);
+ CandidateSearcher_MoveAll(cs, &srcs);
+ CandidateSearcher_MoveAll(cs, &targs);
}
static void
CandidateSearcher_CleanUp(CandidateSearcher *cs)
{
- while (RemoveCandidate(&cs->list))
- continue;
- assert(Lst_IsEmpty(&cs->list));
+ while (RemoveCandidate(&cs->list))
+ continue;
+ assert(Lst_IsEmpty(&cs->list));
}
@@ -1990,40 +2052,39 @@ CandidateSearcher_CleanUp(CandidateSearc
void
Suff_FindDeps(GNode *gn)
{
- CandidateSearcher cs;
+ CandidateSearcher cs;
- CandidateSearcher_Init(&cs);
+ CandidateSearcher_Init(&cs);
- FindDeps(gn, &cs);
+ FindDeps(gn, &cs);
- CandidateSearcher_CleanUp(&cs);
- CandidateSearcher_Done(&cs);
+ CandidateSearcher_CleanUp(&cs);
+ CandidateSearcher_Done(&cs);
}
static void
FindDeps(GNode *gn, CandidateSearcher *cs)
{
- if (gn->type & OP_DEPS_FOUND)
- return;
- gn->type |= OP_DEPS_FOUND;
-
- /*
- * Make sure we have these set, may get revised below.
- */
- Var_Set(TARGET, GNode_Path(gn), gn);
- Var_Set(PREFIX, gn->name, gn);
-
- SUFF_DEBUG1("SuffFindDeps \"%s\"\n", gn->name);
-
- if (gn->type & OP_ARCHV)
- FindDepsArchive(gn, cs);
- else if (gn->type & OP_LIB)
- FindDepsLib(gn);
- else
- FindDepsRegular(gn, cs);
+ if (gn->type & OP_DEPS_FOUND)
+ return;
+ gn->type |= OP_DEPS_FOUND;
+
+ /* Make sure we have these set, may get revised below. */
+ Var_Set(TARGET, GNode_Path(gn), gn);
+ Var_Set(PREFIX, gn->name, gn);
+
+ SUFF_DEBUG1("SuffFindDeps \"%s\"\n", gn->name);
+
+ if (gn->type & OP_ARCHV)
+ FindDepsArchive(gn, cs);
+ else if (gn->type & OP_LIB)
+ FindDepsLib(gn);
+ else
+ FindDepsRegular(gn, cs);
}
-/* Define which suffix is the null suffix.
+/*
+ * Define which suffix is the null suffix.
*
* Need to handle the changing of the null suffix gracefully so the old
* transformation rules don't just go away.
@@ -2034,32 +2095,31 @@ FindDeps(GNode *gn, CandidateSearcher *c
void
Suff_SetNull(const char *name)
{
- Suffix *suff = FindSuffixByName(name);
- if (suff == NULL) {
- Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
+ Suffix *suff = FindSuffixByName(name);
+ if (suff == NULL) {
+ Parse_Error(PARSE_WARNING,
+ "Desired null suffix %s not defined.",
name);
- return;
- }
+ return;
+ }
- if (nullSuff != NULL)
- nullSuff->flags &= ~(unsigned)SUFF_NULL;
- suff->flags |= SUFF_NULL;
- /*
- * XXX: Here's where the transformation mangling would take place
- */
- nullSuff = suff;
+ if (nullSuff != NULL)
+ nullSuff->flags &= ~(unsigned)SUFF_NULL;
+ suff->flags |= SUFF_NULL;
+ /* XXX: Here's where the transformation mangling would take place. */
+ nullSuff = suff;
}
/* Initialize the suffixes module. */
void
Suff_Init(void)
{
- /*
- * Create null suffix for single-suffix rules (POSIX). The thing doesn't
- * actually go on the suffix list or everyone will think that's its
- * suffix.
- */
- Suff_ClearSuffixes();
+ /*
+ * Create null suffix for single-suffix rules (POSIX). The thing
+ * doesn't actually go on the suffix list or everyone will think
+ * that's its suffix.
+ */
+ Suff_ClearSuffixes();
}
@@ -2068,11 +2128,11 @@ void
Suff_End(void)
{
#ifdef CLEANUP
- Lst_DoneCall(&sufflist, SuffFree);
- Lst_DoneCall(&suffClean, SuffFree);
- if (nullSuff != NULL)
- SuffFree(nullSuff);
- Lst_Done(&transforms);
+ Lst_DoneCall(&sufflist, SuffFree);
+ Lst_DoneCall(&suffClean, SuffFree);
+ if (nullSuff != NULL)
+ SuffFree(nullSuff);
+ Lst_Done(&transforms);
#endif
}
@@ -2080,63 +2140,63 @@ Suff_End(void)
static void
PrintSuffNames(const char *prefix, SuffixList *suffs)
{
- SuffixListNode *ln;
+ SuffixListNode *ln;
- debug_printf("#\t%s: ", prefix);
- for (ln = suffs->first; ln != NULL; ln = ln->next) {
- Suffix *suff = ln->datum;
- debug_printf("%s ", suff->name);
- }
- debug_printf("\n");
+ debug_printf("#\t%s: ", prefix);
+ for (ln = suffs->first; ln != NULL; ln = ln->next) {
+ Suffix *suff = ln->datum;
+ debug_printf("%s ", suff->name);
+ }
+ debug_printf("\n");
}
static void
Suffix_Print(Suffix *suff)
{
- debug_printf("# \"%s\" (num %d, ref %d)",
- suff->name, suff->sNum, suff->refCount);
- if (suff->flags != 0) {
- char flags_buf[SuffixFlags_ToStringSize];
-
- debug_printf(" (%s)",
- Enum_FlagsToString(flags_buf, sizeof flags_buf,
- suff->flags,
- SuffixFlags_ToStringSpecs));
- }
- debug_printf("\n");
-
- PrintSuffNames("To", &suff->parents);
- PrintSuffNames("From", &suff->children);
-
- debug_printf("#\tSearch Path: ");
- SearchPath_Print(suff->searchPath);
- debug_printf("\n");
+ debug_printf("# \"%s\" (num %d, ref %d)",
+ suff->name, suff->sNum, suff->refCount);
+ if (suff->flags != 0) {
+ char flags_buf[SuffixFlags_ToStringSize];
+
+ debug_printf(" (%s)",
+ Enum_FlagsToString(flags_buf, sizeof flags_buf,
+ suff->flags,
+ SuffixFlags_ToStringSpecs));
+ }
+ debug_printf("\n");
+
+ PrintSuffNames("To", &suff->parents);
+ PrintSuffNames("From", &suff->children);
+
+ debug_printf("#\tSearch Path: ");
+ SearchPath_Print(suff->searchPath);
+ debug_printf("\n");
}
static void
PrintTransformation(GNode *t)
{
- debug_printf("%-16s:", t->name);
- Targ_PrintType(t->type);
- debug_printf("\n");
- Targ_PrintCmds(t);
- debug_printf("\n");
+ debug_printf("%-16s:", t->name);
+ Targ_PrintType(t->type);
+ debug_printf("\n");
+ Targ_PrintCmds(t);
+ debug_printf("\n");
}
void
Suff_PrintAll(void)
{
- debug_printf("#*** Suffixes:\n");
- {
- SuffixListNode *ln;
- for (ln = sufflist.first; ln != NULL; ln = ln->next)
- Suffix_Print(ln->datum);
- }
+ debug_printf("#*** Suffixes:\n");
+ {
+ SuffixListNode *ln;
+ for (ln = sufflist.first; ln != NULL; ln = ln->next)
+ Suffix_Print(ln->datum);
+ }
- debug_printf("#*** Transformations:\n");
- {
- GNodeListNode *ln;
- for (ln = transforms.first; ln != NULL; ln = ln->next)
- PrintTransformation(ln->datum);
- }
+ debug_printf("#*** Transformations:\n");
+ {
+ GNodeListNode *ln;
+ for (ln = transforms.first; ln != NULL; ln = ln->next)
+ PrintTransformation(ln->datum);
+ }
}