2020-11-20 03:54:37 +00:00
|
|
|
/* $NetBSD: suff.c,v 1.247 2020/11/16 23:27:41 rillig Exp $ */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
|
|
|
* Maintain suffix lists and find implicit dependents using suffix
|
|
|
|
* transformation rules such as ".c.o".
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
|
|
|
* Interface:
|
2020-11-20 03:54:37 +00:00
|
|
|
* Suff_Init Initialize the module.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-20 03:54:37 +00:00
|
|
|
* Suff_End Clean up the module.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-20 03:54:37 +00:00
|
|
|
* Suff_DoPaths Extend the search path of each suffix to include the
|
|
|
|
* default search path.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_ClearSuffixes
|
2020-11-20 03:54:37 +00:00
|
|
|
* Clear out all the suffixes and transformations.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_IsTransform
|
2020-11-20 03:54:37 +00:00
|
|
|
* See if the passed string is a transformation rule.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_AddSuffix Add the passed string as another known suffix.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_GetPath Return the search path for the given suffix.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_AddInclude
|
|
|
|
* Mark the given suffix as denoting an include file.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_AddLib Mark the given suffix as denoting a library.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_AddTransform
|
2020-11-20 03:54:37 +00:00
|
|
|
* Add another transformation to the suffix graph.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_SetNull Define the suffix to consider the suffix of
|
|
|
|
* any file that doesn't have a known one.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_FindDeps Find implicit sources for and the location of
|
|
|
|
* a target based on its suffix. Returns the
|
|
|
|
* bottom-most node added to the graph or NULL
|
|
|
|
* if the target had no implicit sources.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Suff_FindPath Return the appropriate path to search in order to
|
|
|
|
* find the node.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "dir.h"
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
|
2020-11-20 03:54:37 +00:00
|
|
|
MAKE_RCSID("$NetBSD: suff.c,v 1.247 2020/11/16 23:27:41 rillig Exp $");
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#define SUFF_DEBUG0(text) DEBUG0(SUFF, text)
|
|
|
|
#define SUFF_DEBUG1(fmt, arg1) DEBUG1(SUFF, fmt, arg1)
|
|
|
|
#define SUFF_DEBUG2(fmt, arg1, arg2) DEBUG2(SUFF, fmt, arg1, arg2)
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
typedef List SuffList;
|
|
|
|
typedef ListNode SuffListNode;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
typedef List SrcList;
|
|
|
|
typedef ListNode SrcListNode;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static SuffList *sufflist; /* List of suffixes */
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2020-11-07 19:39:21 +00:00
|
|
|
static SuffList *suffClean; /* List of suffixes to be cleaned */
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
static SrcList *srclist; /* List of sources */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* List of transformation rules, such as ".c.o" */
|
|
|
|
static GNodeList *transforms;
|
|
|
|
|
|
|
|
static int sNum = 0; /* Counter for assigning suffix numbers */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
typedef enum SuffFlags {
|
2020-09-05 16:11:04 +00:00
|
|
|
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? */
|
|
|
|
} SuffFlags;
|
|
|
|
|
|
|
|
ENUM_FLAGS_RTTI_3(SuffFlags,
|
|
|
|
SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL);
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
typedef List SuffListList;
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
typedef struct Suff {
|
2020-11-20 03:54:37 +00:00
|
|
|
/* The suffix itself, such as ".c" */
|
|
|
|
char *name;
|
|
|
|
/* Length of the name, to avoid strlen calls */
|
|
|
|
size_t nameLen;
|
|
|
|
/* Type of suffix */
|
|
|
|
SuffFlags 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 */
|
|
|
|
SuffList *parents;
|
|
|
|
/* Suffixes we have a transformation from */
|
|
|
|
SuffList *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. */
|
|
|
|
SuffListList *ref;
|
1996-10-06 15:57:15 +00:00
|
|
|
} Suff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structure used in the search for implied sources.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
typedef struct Src {
|
|
|
|
char *file; /* The file to look for */
|
|
|
|
char *pref; /* Prefix from which file was formed */
|
|
|
|
Suff *suff; /* The suffix on the file */
|
|
|
|
struct Src *parent; /* The Src for which this is a source */
|
|
|
|
GNode *node; /* The node describing the file */
|
2020-11-20 03:54:37 +00:00
|
|
|
int numChildren; /* Count of existing children (so we don't free
|
1996-10-06 15:57:15 +00:00
|
|
|
* this thing too early or never nuke it) */
|
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
SrcList *childrenList;
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
|
|
|
} Src;
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* TODO: Document the difference between suffNull and emptySuff. */
|
|
|
|
/* The NULL suffix for this run */
|
|
|
|
static Suff *suffNull;
|
|
|
|
/* The empty suffix required for POSIX single-suffix transformation rules */
|
|
|
|
static Suff *emptySuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void SuffFindDeps(GNode *, SrcList *);
|
|
|
|
static void SuffExpandWildcards(GNodeListNode *, GNode *);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
|
|
|
* See if pref is a prefix of str.
|
|
|
|
* Return NULL if it ain't, pointer to character in str after prefix if so.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
static const char *
|
|
|
|
SuffStrIsPrefix(const char *pref, const char *str)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
while (*str && *pref == *str) {
|
|
|
|
pref++;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
return *pref != '\0' ? NULL : str;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
|
|
|
* See if suff is a suffix of name.
|
|
|
|
* Return NULL if it ain't, pointer to the start of suffix in name if it is.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static const char *
|
|
|
|
SuffSuffGetSuffix(const Suff *s, size_t nameLen, const char *nameEnd)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
const char *p1; /* Pointer into suffix name */
|
|
|
|
const char *p2; /* Pointer into string being examined */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (nameLen < s->nameLen)
|
2012-06-08 21:57:36 +00:00
|
|
|
return NULL; /* this string is shorter than the suffix */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
p1 = s->name + s->nameLen;
|
2020-11-07 19:39:21 +00:00
|
|
|
p2 = nameEnd;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
while (p1 >= s->name && *p1 == *p2) {
|
|
|
|
p1--;
|
|
|
|
p2--;
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* XXX: s->name - 1 invokes undefined behavior */
|
|
|
|
return p1 == s->name - 1 ? p2 + 1 : NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
static Boolean
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffSuffIsSuffix(const Suff *suff, size_t nameLen, const char *nameEnd)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
return SuffSuffGetSuffix(suff, nameLen, nameEnd) != NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static Suff *
|
|
|
|
FindSuffByNameLen(const char *name, size_t nameLen)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln;
|
|
|
|
|
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *suff = ln->datum;
|
|
|
|
if (suff->nameLen == nameLen && memcmp(suff->name, name, nameLen) == 0)
|
|
|
|
return suff;
|
|
|
|
}
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static Suff *
|
|
|
|
FindSuffByName(const char *name)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
return FindSuffByNameLen(name, strlen(name));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static GNode *
|
|
|
|
FindTransformByName(const char *name)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
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;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList_Unref(SuffList *list, Suff *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln = Lst_FindDatum(list, suff);
|
2012-06-08 21:57:36 +00:00
|
|
|
if (ln != NULL) {
|
2020-11-07 19:39:21 +00:00
|
|
|
Lst_Remove(list, ln);
|
|
|
|
suff->refCount--;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Free up all memory associated with the given suffix structure. */
|
1996-10-06 15:57:15 +00:00
|
|
|
static void
|
2012-06-08 21:57:36 +00:00
|
|
|
SuffFree(void *sp)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *suff = sp;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (suff == suffNull)
|
1996-10-06 15:57:15 +00:00
|
|
|
suffNull = NULL;
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (suff == emptySuff)
|
1996-10-06 15:57:15 +00:00
|
|
|
emptySuff = NULL;
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#if 0
|
2012-06-08 21:57:36 +00:00
|
|
|
/* We don't delete suffixes in order, so we cannot use this */
|
2020-11-20 03:54:37 +00:00
|
|
|
if (suff->refCount != 0)
|
|
|
|
Punt("Internal error deleting suffix `%s' with refcount = %d",
|
|
|
|
suff->name, suff->refCount);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
Lst_Free(suff->ref);
|
|
|
|
Lst_Free(suff->children);
|
|
|
|
Lst_Free(suff->parents);
|
|
|
|
Lst_Destroy(suff->searchPath, Dir_Destroy);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
free(suff->name);
|
|
|
|
free(suff);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Remove the suffix from the list, and free if it is otherwise unused. */
|
1996-10-06 15:57:15 +00:00
|
|
|
static void
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList_Remove(SuffList *list, Suff *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList_Unref(list, suff);
|
2020-11-07 19:39:21 +00:00
|
|
|
if (suff->refCount == 0) {
|
2020-11-20 03:54:37 +00:00
|
|
|
/* XXX: can lead to suff->refCount == -1 */
|
|
|
|
SuffList_Unref(sufflist, suff);
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFree(suff);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Insert the suffix into the list, keeping the list ordered by suffix
|
2020-11-20 03:54:37 +00:00
|
|
|
* number. */
|
1996-10-06 15:57:15 +00:00
|
|
|
static void
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList_Insert(SuffList *list, Suff *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln;
|
|
|
|
Suff *listSuff = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = list->first; ln != NULL; ln = ln->next) {
|
|
|
|
listSuff = ln->datum;
|
|
|
|
if (listSuff->sNum >= suff->sNum)
|
1996-10-06 15:57:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (ln == NULL) {
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG2("inserting \"%s\" (%d) at end of list\n",
|
|
|
|
suff->name, suff->sNum);
|
|
|
|
Lst_Append(list, suff);
|
|
|
|
suff->refCount++;
|
|
|
|
Lst_Append(suff->ref, list);
|
|
|
|
} else if (listSuff->sNum != suff->sNum) {
|
2020-11-20 03:54:37 +00:00
|
|
|
DEBUG4(SUFF, "inserting \"%s\" (%d) before \"%s\" (%d)\n",
|
|
|
|
suff->name, suff->sNum, listSuff->name, listSuff->sNum);
|
2020-11-07 19:39:21 +00:00
|
|
|
Lst_InsertBefore(list, ln, suff);
|
|
|
|
suff->refCount++;
|
|
|
|
Lst_Append(suff->ref, list);
|
2020-09-05 16:11:04 +00:00
|
|
|
} else {
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG2("\"%s\" (%d) is already there\n", suff->name, suff->sNum);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
static void
|
|
|
|
SuffRelate(Suff *srcSuff, Suff *targSuff)
|
|
|
|
{
|
|
|
|
SuffList_Insert(targSuff->children, srcSuff);
|
|
|
|
SuffList_Insert(srcSuff->parents, targSuff);
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
static Suff *
|
|
|
|
SuffNew(const char *name)
|
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *suff = bmake_malloc(sizeof *suff);
|
|
|
|
|
|
|
|
suff->name = bmake_strdup(name);
|
|
|
|
suff->nameLen = strlen(suff->name);
|
|
|
|
suff->searchPath = Lst_New();
|
|
|
|
suff->children = Lst_New();
|
|
|
|
suff->parents = Lst_New();
|
|
|
|
suff->ref = Lst_New();
|
|
|
|
suff->sNum = sNum++;
|
|
|
|
suff->flags = 0;
|
|
|
|
suff->refCount = 1; /* XXX: why 1? It's not assigned anywhere yet. */
|
|
|
|
|
|
|
|
return suff;
|
2020-09-05 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
|
|
|
* Nuke the list of suffixes but keep all transformation rules around. The
|
|
|
|
* transformation graph is destroyed in this process, but we leave the list
|
|
|
|
* of rules so when a new graph is formed, the rules will remain. This
|
|
|
|
* function is called when a line '.SUFFIXES:' with an empty suffixes list is
|
|
|
|
* encountered in a makefile.
|
|
|
|
*/
|
1996-10-06 15:57:15 +00:00
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_ClearSuffixes(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_MoveAll(suffClean, sufflist);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
sufflist = Lst_New();
|
1996-10-06 15:57:15 +00:00
|
|
|
sNum = 0;
|
2015-12-25 08:09:48 +00:00
|
|
|
if (suffNull)
|
|
|
|
SuffFree(suffNull);
|
2020-09-05 16:11:04 +00:00
|
|
|
emptySuff = suffNull = SuffNew("");
|
2015-12-25 08:09:48 +00:00
|
|
|
|
|
|
|
Dir_Concat(suffNull->searchPath, dirSearchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
suffNull->flags = SUFF_NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Parse a transformation string such as ".c.o" to find its two component
|
|
|
|
* suffixes (the source ".c" and the target ".o"). If there are no such
|
|
|
|
* suffixes, try a single-suffix transformation as well.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Return TRUE if the string is a valid transformation.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
static Boolean
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffParseTransform(const char *str, Suff **out_src, Suff **out_targ)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln;
|
|
|
|
Suff *singleSrc = NULL;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *src = ln->datum;
|
|
|
|
|
|
|
|
if (SuffStrIsPrefix(src->name, str) == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (str[src->nameLen] == '\0') {
|
|
|
|
singleSrc = src;
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *targ = FindSuffByName(str + src->nameLen);
|
|
|
|
if (targ != NULL) {
|
2020-09-05 16:11:04 +00:00
|
|
|
*out_src = src;
|
2020-11-07 19:39:21 +00:00
|
|
|
*out_targ = targ;
|
2020-07-08 18:32:15 +00:00
|
|
|
return TRUE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
if (singleSrc != NULL) {
|
|
|
|
/*
|
|
|
|
* Not so fast Mr. Smith! There was a suffix that encompassed
|
|
|
|
* the entire string, so we assume it was a transformation
|
|
|
|
* to the null suffix (thank you POSIX). We still prefer to
|
|
|
|
* find a double rule over a singleton, hence we leave this
|
|
|
|
* check until the end.
|
|
|
|
*
|
|
|
|
* XXX: Use emptySuff over suffNull?
|
|
|
|
*/
|
|
|
|
*out_src = singleSrc;
|
|
|
|
*out_targ = suffNull;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Return TRUE if the given string is a transformation rule, that is, a
|
2020-11-20 03:54:37 +00:00
|
|
|
* concatenation of two known suffixes such as ".c.o" or a single suffix
|
|
|
|
* such as ".o". */
|
1996-10-06 15:57:15 +00:00
|
|
|
Boolean
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_IsTransform(const char *str)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *src, *targ;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-07-08 18:32:15 +00:00
|
|
|
return SuffParseTransform(str, &src, &targ);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* 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.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
2020-11-07 19:39:21 +00:00
|
|
|
* name must have the form ".from.to" or just ".from"
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
2020-11-07 19:39:21 +00:00
|
|
|
* The created or existing transformation node in the transforms list
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
GNode *
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_AddTransform(const char *name)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *srcSuff;
|
|
|
|
Suff *targSuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
GNode *gn = FindTransformByName(name);
|
2020-11-07 19:39:21 +00:00
|
|
|
if (gn == NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Make a new graph node for the transformation. It will be filled in
|
2012-06-08 21:57:36 +00:00
|
|
|
* by the Parse module.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
gn = GNode_New(name);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(transforms, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
} 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.
|
|
|
|
*/
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(gn->commands);
|
|
|
|
Lst_Free(gn->children);
|
2020-11-07 19:39:21 +00:00
|
|
|
gn->commands = Lst_New();
|
|
|
|
gn->children = Lst_New();
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gn->type = OP_TRANSFORM;
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
{
|
|
|
|
Boolean ok = SuffParseTransform(name, &srcSuff, &targSuff);
|
|
|
|
assert(ok);
|
|
|
|
(void)ok;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* link the two together in the proper relationship and order
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
|
2020-11-20 03:54:37 +00:00
|
|
|
srcSuff->name, targSuff->name);
|
|
|
|
SuffRelate(srcSuff, targSuff);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-07-08 18:32:15 +00:00
|
|
|
return gn;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* 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
|
|
|
|
* of the affected suffixes are altered.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
2020-11-07 19:39:21 +00:00
|
|
|
* gn Node for transformation
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
void
|
|
|
|
Suff_EndTransform(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-09-05 16:11:04 +00:00
|
|
|
if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(gn->cohorts))
|
2020-11-07 19:39:21 +00:00
|
|
|
gn = gn->cohorts->last->datum;
|
2020-11-20 03:54:37 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) &&
|
|
|
|
Lst_IsEmpty(gn->children))
|
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *srcSuff, *targSuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* SuffParseTransform() may fail for special rules which are not
|
|
|
|
* actual transformation rules. (e.g. .DEFAULT)
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
if (SuffParseTransform(gn->name, &srcSuff, &targSuff)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/*
|
2020-11-20 03:54:37 +00:00
|
|
|
* Remember parents since srcSuff could be deleted in
|
|
|
|
* SuffList_Remove
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList *srcSuffParents = srcSuff->parents;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
SUFF_DEBUG2("deleting transformation from `%s' to `%s'\n",
|
|
|
|
srcSuff->name, targSuff->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffList_Remove(targSuff->children, srcSuff);
|
|
|
|
SuffList_Remove(srcSuffParents, targSuff);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
} else if (gn->type & OP_TRANSFORM) {
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG1("transformation %s complete\n", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Called from Suff_AddSuffix to search through the list of
|
2020-09-05 16:11:04 +00:00
|
|
|
* existing transformation rules and rebuild the transformation graph when
|
|
|
|
* it has been destroyed by Suff_ClearSuffixes. If the given rule is a
|
|
|
|
* transformation involving this suffix and another, existing suffix, the
|
|
|
|
* proper relationship is established between the two.
|
|
|
|
*
|
|
|
|
* The appropriate links will be made between this suffix and others if
|
|
|
|
* transformation rules exist for it.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
2020-11-07 19:39:21 +00:00
|
|
|
* transform Transformation to test
|
|
|
|
* suff Suffix to rebuild
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
SuffRebuildGraph(GNode *transform, Suff *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
const char *name = transform->name;
|
|
|
|
size_t nameLen = strlen(name);
|
|
|
|
const char *toName;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First see if it is a transformation from this suffix.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
toName = SuffStrIsPrefix(suff->name, name);
|
|
|
|
if (toName != NULL) {
|
|
|
|
Suff *to = FindSuffByName(toName);
|
|
|
|
if (to != NULL) {
|
|
|
|
/* Link in and return, since it can't be anything else. */
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffRelate(suff, to);
|
2020-11-07 19:39:21 +00:00
|
|
|
return;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not from, maybe to?
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
toName = SuffSuffGetSuffix(suff, nameLen, name + nameLen);
|
|
|
|
if (toName != NULL) {
|
|
|
|
Suff *from = FindSuffByNameLen(name, (size_t)(toName - name));
|
2020-11-20 03:54:37 +00:00
|
|
|
if (from != NULL)
|
|
|
|
SuffRelate(from, suff);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* 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.
|
2020-09-05 16:11:04 +00:00
|
|
|
*
|
|
|
|
* If such a target is found and the target is the current main target, the
|
|
|
|
* main target is set to NULL and the next target examined (if that exists)
|
|
|
|
* becomes the main target.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* Results:
|
2020-11-07 19:39:21 +00:00
|
|
|
* TRUE iff a new main target has been selected.
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static Boolean
|
|
|
|
SuffScanTargets(GNode *target, GNode **inout_main, Suff *gs_s, Boolean *gs_r)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *srcSuff, *targSuff;
|
2020-11-07 19:39:21 +00:00
|
|
|
char *ptr;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (*inout_main == NULL && *gs_r && !(target->type & OP_NOTARGET)) {
|
|
|
|
*inout_main = target;
|
2012-06-08 21:57:36 +00:00
|
|
|
Targ_SetMain(target);
|
2020-11-07 19:39:21 +00:00
|
|
|
return TRUE;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
if (target->type == OP_TRANSFORM)
|
2020-11-07 19:39:21 +00:00
|
|
|
return FALSE;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if ((ptr = strstr(target->name, gs_s->name)) == NULL ||
|
2012-06-08 21:57:36 +00:00
|
|
|
ptr == target->name)
|
2020-11-07 19:39:21 +00:00
|
|
|
return FALSE;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (SuffParseTransform(target->name, &srcSuff, &targSuff)) {
|
2020-11-07 19:39:21 +00:00
|
|
|
if (*inout_main == target) {
|
|
|
|
*gs_r = TRUE;
|
|
|
|
*inout_main = NULL;
|
2012-06-08 21:57:36 +00:00
|
|
|
Targ_SetMain(NULL);
|
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(target->children);
|
2020-11-07 19:39:21 +00:00
|
|
|
target->children = Lst_New();
|
2012-06-08 21:57:36 +00:00
|
|
|
target->type = OP_TRANSFORM;
|
|
|
|
/*
|
|
|
|
* link the two together in the proper relationship and order
|
|
|
|
*/
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG2("defining transformation from `%s' to `%s'\n",
|
2020-11-20 03:54:37 +00:00
|
|
|
srcSuff->name, targSuff->name);
|
|
|
|
SuffRelate(srcSuff, targSuff);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
static void
|
|
|
|
UpdateTargets(GNode **inout_main, Suff *s)
|
|
|
|
{
|
|
|
|
Boolean r = FALSE;
|
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = Targ_List()->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
if (SuffScanTargets(gn, inout_main, s, &r))
|
|
|
|
break;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Add the suffix to the end of the list of known suffixes.
|
|
|
|
* Should we restructure the suffix graph? Make doesn't...
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-09-05 16:11:04 +00:00
|
|
|
* A GNode is created for the suffix and a Suff 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.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-09-05 16:11:04 +00:00
|
|
|
* Input:
|
|
|
|
* name the name of the suffix to add
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_AddSuffix(const char *name, GNode **inout_main)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeListNode *ln;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *s = FindSuffByName(name);
|
|
|
|
if (s != NULL)
|
|
|
|
return;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
s = SuffNew(name);
|
|
|
|
Lst_Append(sufflist, s);
|
|
|
|
|
|
|
|
UpdateTargets(inout_main, s);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
SuffRebuildGraph(ln->datum, s);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Return the search path for the given suffix, or NULL. */
|
2020-11-07 19:39:21 +00:00
|
|
|
SearchPath *
|
|
|
|
Suff_GetPath(const char *sname)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *s = FindSuffByName(sname);
|
|
|
|
return s != NULL ? s->searchPath : NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
|
|
|
* Extend the search paths for all suffixes to include the default search
|
|
|
|
* path (dirSearchPath).
|
|
|
|
*
|
|
|
|
* The default search path can be defined using the special target '.PATH'.
|
|
|
|
* The search path of each suffix can be defined using the special target
|
|
|
|
* '.PATH<suffix>'.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-20 03:54:37 +00:00
|
|
|
* If paths were specified for the ".h" suffix, the directories are stuffed
|
|
|
|
* into a global variable called ".INCLUDES" with each directory preceded by
|
|
|
|
* '-I'. The same is done for the ".a" suffix, except the variable is called
|
|
|
|
* ".LIBS" and the flag is '-L'.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_DoPaths(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln;
|
|
|
|
char *ptr;
|
|
|
|
SearchPath *inIncludes; /* Cumulative .INCLUDES path */
|
|
|
|
SearchPath *inLibs; /* Cumulative .LIBS path */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
inIncludes = Lst_New();
|
|
|
|
inLibs = Lst_New();
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *s = ln->datum;
|
2020-09-05 16:11:04 +00:00
|
|
|
if (!Lst_IsEmpty(s->searchPath)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef INCLUDES
|
2020-11-20 03:54:37 +00:00
|
|
|
if (s->flags & SUFF_INCLUDE)
|
1996-10-06 15:57:15 +00:00
|
|
|
Dir_Concat(inIncludes, s->searchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef LIBRARIES
|
2020-11-20 03:54:37 +00:00
|
|
|
if (s->flags & SUFF_LIBRARY)
|
1996-10-06 15:57:15 +00:00
|
|
|
Dir_Concat(inLibs, s->searchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
Dir_Concat(s->searchPath, dirSearchPath);
|
|
|
|
} else {
|
2012-06-08 21:57:36 +00:00
|
|
|
Lst_Destroy(s->searchPath, Dir_Destroy);
|
2020-11-07 19:39:21 +00:00
|
|
|
s->searchPath = Dir_CopyDirSearchPath();
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
|
1996-10-06 15:57:15 +00:00
|
|
|
free(ptr);
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
|
1996-10-06 15:57:15 +00:00
|
|
|
free(ptr);
|
|
|
|
|
|
|
|
Lst_Destroy(inIncludes, Dir_Destroy);
|
|
|
|
Lst_Destroy(inLibs, Dir_Destroy);
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Add the given suffix as a type of file which gets included.
|
|
|
|
* Called from the parse module when a .INCLUDES line is parsed.
|
|
|
|
* The suffix must have already been defined.
|
|
|
|
* The SUFF_INCLUDE bit is set in the suffix's flags field.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* sname Name of the suffix to mark
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_AddInclude(const char *sname)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *suff = FindSuffByName(sname);
|
|
|
|
if (suff != NULL)
|
|
|
|
suff->flags |= SUFF_INCLUDE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Add the given suffix as a type of file which is a library.
|
|
|
|
* Called from the parse module when parsing a .LIBS line.
|
|
|
|
* The suffix must have been defined via .SUFFIXES before this is called.
|
|
|
|
* The SUFF_LIBRARY bit is set in the suffix's flags field.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* sname Name of the suffix to mark
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-09-05 16:11:04 +00:00
|
|
|
Suff_AddLib(const char *sname)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *suff = FindSuffByName(sname);
|
|
|
|
if (suff != NULL)
|
|
|
|
suff->flags |= SUFF_LIBRARY;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/********** Implicit Source Search Functions *********/
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
static void
|
|
|
|
SrcList_PrintAddrs(SrcList *srcList)
|
|
|
|
{
|
|
|
|
SrcListNode *ln;
|
|
|
|
for (ln = srcList->first; ln != NULL; ln = ln->next)
|
|
|
|
debug_printf(" %p", ln->datum);
|
|
|
|
debug_printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Src *
|
|
|
|
SrcNew(char *name, char *pref, Suff *suff, Src *parent, GNode *gn)
|
|
|
|
{
|
|
|
|
Src *src = bmake_malloc(sizeof *src);
|
|
|
|
|
|
|
|
src->file = name;
|
|
|
|
src->pref = pref;
|
|
|
|
src->suff = suff;
|
|
|
|
src->parent = parent;
|
|
|
|
src->node = gn;
|
2020-11-20 03:54:37 +00:00
|
|
|
src->numChildren = 0;
|
2020-11-07 19:39:21 +00:00
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
src->childrenList = Lst_New();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SuffAddSrc(Suff *suff, SrcList *srcList, Src *targ, char *srcName,
|
2020-11-20 03:54:37 +00:00
|
|
|
const char *debug_tag MAKE_ATTR_UNUSED)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
|
|
|
Src *s2 = SrcNew(srcName, targ->pref, suff, targ, NULL);
|
|
|
|
suff->refCount++;
|
2020-11-20 03:54:37 +00:00
|
|
|
targ->numChildren++;
|
2020-11-07 19:39:21 +00:00
|
|
|
Lst_Append(srcList, s2);
|
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
Lst_Append(targ->childrenList, s2);
|
|
|
|
debug_printf("%s add suff %p src %p to list %p:",
|
|
|
|
debug_tag, targ, s2, srcList);
|
|
|
|
SrcList_PrintAddrs(srcList);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Add a suffix as a Src structure to the given list with its parent
|
|
|
|
* being the given Src structure. If the suffix is the null suffix,
|
2020-11-20 03:54:37 +00:00
|
|
|
* the prefix is used unaltered as the filename in the Src structure.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
2020-11-07 19:39:21 +00:00
|
|
|
* suff suffix for which to create a Src structure
|
|
|
|
* srcList list for the new Src
|
|
|
|
* targ parent for the new Src
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
SuffAddSources(Suff *suff, SrcList *srcList, Src *targ)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
if ((suff->flags & SUFF_NULL) && suff->name[0] != '\0') {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* If the suffix has been marked as the NULL suffix, also create a Src
|
|
|
|
* structure for a file with no suffix attached. Two birds, and all
|
|
|
|
* that...
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffAddSrc(suff, srcList, targ, bmake_strdup(targ->pref), "1");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffAddSrc(suff, srcList, targ, str_concat2(targ->pref, suff->name), "2");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Add all the children of targ to the list. */
|
1996-10-06 15:57:15 +00:00
|
|
|
static void
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffAddLevel(SrcList *srcs, Src *targ)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SrcListNode *ln;
|
|
|
|
for (ln = targ->suff->children->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *childSuff = ln->datum;
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffAddSources(childSuff, srcs, targ);
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Free the first Src in the list that is not referenced anymore.
|
2020-09-05 16:11:04 +00:00
|
|
|
* Return whether a Src was removed. */
|
|
|
|
static Boolean
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffRemoveSrc(SrcList *l)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SrcListNode *ln;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("cleaning list %p:", l);
|
|
|
|
SrcList_PrintAddrs(l);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = l->first; ln != NULL; ln = ln->next) {
|
2020-11-20 03:54:37 +00:00
|
|
|
Src *src = ln->datum;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (src->numChildren == 0) {
|
|
|
|
free(src->file);
|
|
|
|
if (src->parent == NULL)
|
|
|
|
free(src->pref);
|
1996-10-06 15:57:15 +00:00
|
|
|
else {
|
|
|
|
#ifdef DEBUG_SRC
|
2020-11-20 03:54:37 +00:00
|
|
|
SrcListNode *ln2 = Lst_FindDatum(src->parent->childrenList, src);
|
2016-09-08 23:49:33 +00:00
|
|
|
if (ln2 != NULL)
|
2020-11-20 03:54:37 +00:00
|
|
|
Lst_Remove(src->parent->childrenList, ln2);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2020-11-20 03:54:37 +00:00
|
|
|
src->parent->numChildren--;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("free: list %p src %p children %d\n",
|
2020-11-20 03:54:37 +00:00
|
|
|
l, src, src->children);
|
|
|
|
Lst_Free(src->childrenList);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
|
|
|
Lst_Remove(l, ln);
|
2020-11-20 03:54:37 +00:00
|
|
|
free(src);
|
1996-10-06 15:57:15 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
else {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("keep: list %p src %p children %d:",
|
2020-11-20 03:54:37 +00:00
|
|
|
l, src, src->children);
|
|
|
|
SrcList_PrintAddrs(src->childrenList);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
return FALSE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Find the first existing file/target in srcs. */
|
1996-10-06 15:57:15 +00:00
|
|
|
static Src *
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindThem(SrcList *srcs, SrcList *slst)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
Src *retsrc = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
while (!Lst_IsEmpty(srcs)) {
|
2020-11-07 19:39:21 +00:00
|
|
|
Src *src = Lst_Dequeue(srcs);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG1("\ttrying %s...", src->file);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A file is considered to exist if either a node exists in the
|
|
|
|
* graph for it or the file actually exists.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
if (Targ_FindNode(src->file) != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("remove from list %p src %p\n", srcs, src);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
retsrc = src;
|
1996-10-06 15:57:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
|
|
|
char *file = Dir_FindFile(src->file, src->suff->searchPath);
|
|
|
|
if (file != NULL) {
|
|
|
|
retsrc = src;
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("remove from list %p src %p\n", srcs, src);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
free(file);
|
|
|
|
break;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG0("not there\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffAddLevel(srcs, src);
|
|
|
|
Lst_Append(slst, src);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (retsrc) {
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG0("got it\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
return retsrc;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* See if any of the children of the target in the Src structure is one from
|
|
|
|
* which the target can be transformed. If there is one, a Src structure is
|
|
|
|
* put together for it and returned.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
2020-09-05 16:11:04 +00:00
|
|
|
* targ Src to play with
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
2020-09-05 16:11:04 +00:00
|
|
|
* The Src of the "winning" child, or NULL.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
static Src *
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindCmds(Src *targ, SrcList *slst)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeListNode *gln;
|
|
|
|
GNode *tgn; /* Target GNode */
|
|
|
|
GNode *sgn; /* Source GNode */
|
|
|
|
size_t prefLen; /* The length of the defined prefix */
|
|
|
|
Suff *suff; /* Suffix on matching beastie */
|
|
|
|
Src *ret; /* Return value */
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
tgn = targ->node;
|
2012-06-08 21:57:36 +00:00
|
|
|
prefLen = strlen(targ->pref);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (gln = tgn->children->first; gln != NULL; gln = gln->next) {
|
|
|
|
sgn = gln->datum;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (sgn->type & OP_OPTIONAL && Lst_IsEmpty(tgn->commands)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
cp = strrchr(sgn->name, '/');
|
2012-06-08 21:57:36 +00:00
|
|
|
if (cp == NULL) {
|
2020-11-07 19:39:21 +00:00
|
|
|
cp = sgn->name;
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
cp++;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
if (strncmp(cp, targ->pref, prefLen) != 0)
|
|
|
|
continue;
|
2020-11-20 03:54:37 +00:00
|
|
|
/* The node matches the prefix ok, see if it has a known suffix. */
|
2020-11-07 19:39:21 +00:00
|
|
|
suff = FindSuffByName(cp + prefLen);
|
|
|
|
if (suff == NULL)
|
2012-06-08 21:57:36 +00:00
|
|
|
continue;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* XXX: Can targ->suff be NULL here? */
|
|
|
|
if (targ->suff != NULL &&
|
|
|
|
Lst_FindDatum(suff->parents, targ->suff) != NULL)
|
2012-06-08 21:57:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (gln == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* Hot Damn! Create a new Src structure to describe
|
|
|
|
* this transformation (making sure to duplicate the
|
|
|
|
* source node's name so Suff_FindDeps can free it
|
|
|
|
* again (ick)), and return the new structure.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
ret = SrcNew(bmake_strdup(sgn->name), targ->pref, suff, targ, sgn);
|
2012-06-08 21:57:36 +00:00
|
|
|
suff->refCount++;
|
2020-11-20 03:54:37 +00:00
|
|
|
targ->numChildren++;
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("3 add targ %p ret %p\n", targ, ret);
|
|
|
|
Lst_Append(targ->childrenList, ret);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(slst, ret);
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG1("\tusing existing source %s\n", sgn->name);
|
2020-07-08 18:32:15 +00:00
|
|
|
return ret;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Expand the names of any children of a given node that contain variable
|
2020-11-07 19:39:21 +00:00
|
|
|
* expressions or file wildcards into actual targets.
|
2020-09-05 16:11:04 +00:00
|
|
|
*
|
|
|
|
* The expanded node is removed from the parent's list of children, and the
|
|
|
|
* parent's unmade counter is decremented, but other nodes may be added.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* cln Child to examine
|
|
|
|
* pgn Parent node being processed
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
static void
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffExpandChildren(GNodeListNode *cln, GNode *pgn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNode *cgn = cln->datum;
|
|
|
|
GNode *gn; /* New source 8) */
|
|
|
|
char *cp; /* Expanded value */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
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;
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
if (strchr(cgn->name, '$') == NULL) {
|
|
|
|
SuffExpandWildcards(cln, pgn);
|
|
|
|
return;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("Expanding \"%s\"...", cgn->name);
|
2020-11-20 03:54:37 +00:00
|
|
|
(void)Var_Subst(cgn->name, pgn, VARE_WANTRES | VARE_UNDEFERR, &cp);
|
2020-11-07 19:39:21 +00:00
|
|
|
/* TODO: handle errors */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeList *members = Lst_New();
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
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 {
|
|
|
|
/*
|
|
|
|
* Break the result into a vector of strings whose nodes
|
|
|
|
* we can find, then add those nodes to the members list.
|
2020-11-20 03:54:37 +00:00
|
|
|
* Unfortunately, we can't use Str_Words because it
|
2012-06-08 21:57:36 +00:00
|
|
|
* doesn't understand about variable specifications with
|
|
|
|
* spaces in them...
|
|
|
|
*/
|
|
|
|
char *start;
|
|
|
|
char *initcp = cp; /* For freeing... */
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
start = cp;
|
|
|
|
pp_skip_hspace(&start);
|
2020-11-07 19:39:21 +00:00
|
|
|
cp = start;
|
|
|
|
while (*cp != '\0') {
|
2012-06-08 21:57:36 +00:00
|
|
|
if (*cp == ' ' || *cp == '\t') {
|
|
|
|
/*
|
|
|
|
* White-space -- terminate element, find the node,
|
|
|
|
* add it, skip any further spaces.
|
|
|
|
*/
|
|
|
|
*cp++ = '\0';
|
2020-11-07 19:39:21 +00:00
|
|
|
gn = Targ_GetNode(start);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(members, gn);
|
2020-11-20 03:54:37 +00:00
|
|
|
pp_skip_hspace(&cp);
|
2020-11-07 19:39:21 +00:00
|
|
|
start = cp; /* Continue at the next non-space. */
|
2012-06-08 21:57:36 +00:00
|
|
|
} else if (*cp == '$') {
|
|
|
|
/*
|
|
|
|
* Start of a variable spec -- contact variable module
|
|
|
|
* to find the end so we can skip over it.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
const char *nested_p = cp;
|
2020-09-05 16:11:04 +00:00
|
|
|
const char *junk;
|
2012-06-08 21:57:36 +00:00
|
|
|
void *freeIt;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* XXX: Why VARE_WANTRES when the result is not used? */
|
|
|
|
(void)Var_Parse(&nested_p, pgn,
|
2020-11-20 03:54:37 +00:00
|
|
|
VARE_WANTRES | VARE_UNDEFERR,
|
2020-11-07 19:39:21 +00:00
|
|
|
&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;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2016-03-11 00:37:02 +00:00
|
|
|
free(freeIt);
|
2020-11-20 03:54:37 +00:00
|
|
|
} else if (cp[0] == '\\' && cp[1] != '\0') {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Escaped something -- skip over it
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
/* 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 {
|
2012-06-08 21:57:36 +00:00
|
|
|
cp++;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (cp != start) {
|
|
|
|
/*
|
|
|
|
* Stuff left over -- add it to the list too
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
gn = Targ_GetNode(start);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(members, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Point cp back at the beginning again so the variable value
|
|
|
|
* can be freed.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
cp = initcp;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Add all elements of the members list to the parent node.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
while(!Lst_IsEmpty(members)) {
|
2020-09-05 16:11:04 +00:00
|
|
|
gn = Lst_Dequeue(members);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("%s...", gn->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
/* Add gn to the parents child list before the original child */
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_InsertBefore(pgn->children, cln, gn);
|
|
|
|
Lst_Append(gn->parents, pgn);
|
2012-06-08 21:57:36 +00:00
|
|
|
pgn->unmade++;
|
|
|
|
/* Expand wildcards on new node */
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffExpandWildcards(cln->prev, pgn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(members);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Free the result
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
free(cp);
|
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
SUFF_DEBUG0("\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
static void
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffExpandWildcards(GNodeListNode *cln, GNode *pgn)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNode *cgn = cln->datum;
|
2020-11-20 03:54:37 +00:00
|
|
|
StringList *expansions;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (!Dir_HasWildcards(cgn->name))
|
|
|
|
return;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* Expand the word along the chosen path
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
expansions = Lst_New();
|
|
|
|
Dir_Expand(cgn->name, Suff_FindPath(cgn), expansions);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
while (!Lst_IsEmpty(expansions)) {
|
2020-11-07 19:39:21 +00:00
|
|
|
GNode *gn;
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Fetch next expansion off the list and find its GNode
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
char *cp = Lst_Dequeue(expansions);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("%s...", cp);
|
2020-11-07 19:39:21 +00:00
|
|
|
gn = Targ_GetNode(cp);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/* Add gn to the parents child list before the original child */
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_InsertBefore(pgn->children, cln, gn);
|
|
|
|
Lst_Append(gn->parents, pgn);
|
2012-06-08 21:57:36 +00:00
|
|
|
pgn->unmade++;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
Lst_Free(expansions);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG0("\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Remove(cgn->parents, Lst_FindDatum(cgn->parents, pgn));
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Find a path along which to expand the node.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-20 03:54:37 +00:00
|
|
|
* If the node has a known suffix, use that path.
|
2020-09-05 16:11:04 +00:00
|
|
|
* If it has no known suffix, use the default system search path.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* gn Node being examined
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The appropriate path to search for the GNode.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
SearchPath *
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_FindPath(GNode* gn)
|
|
|
|
{
|
|
|
|
Suff *suff = gn->suffix;
|
|
|
|
|
|
|
|
if (suff == NULL) {
|
2020-11-07 19:39:21 +00:00
|
|
|
char *name = gn->name;
|
|
|
|
size_t nameLen = strlen(gn->name);
|
|
|
|
SuffListNode *ln;
|
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next)
|
|
|
|
if (SuffSuffIsSuffix(ln->datum, nameLen, name + nameLen))
|
|
|
|
break;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("Wildcard expanding \"%s\"...", gn->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
if (ln != NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
suff = ln->datum;
|
2012-06-08 21:57:36 +00:00
|
|
|
/* XXX: Here we can save the suffix so we don't have to do this again */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (suff != NULL) {
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG1("suffix is \"%s\"...\n", suff->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
return suff->searchPath;
|
|
|
|
} else {
|
2020-11-07 19:39:21 +00:00
|
|
|
SUFF_DEBUG0("\n");
|
|
|
|
return dirSearchPath; /* Use default search path */
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Apply a transformation rule, given the source and target nodes and
|
|
|
|
* suffixes.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-11-20 03:54:37 +00:00
|
|
|
* The source and target are linked and the commands from the transformation
|
|
|
|
* are added to the target node's commands list. The target also inherits all
|
|
|
|
* the sources for the transformation rule.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Results:
|
|
|
|
* TRUE if successful, FALSE if not.
|
|
|
|
*/
|
|
|
|
static Boolean
|
2020-11-20 03:54:37 +00:00
|
|
|
SuffApplyTransform(GNode *tgn, GNode *sgn, Suff *tsuff, Suff *ssuff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
GNodeListNode *ln;
|
2020-11-07 19:39:21 +00:00
|
|
|
char *tname; /* Name of transformation rule */
|
|
|
|
GNode *gn; /* Node for same */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* Form the proper links between the target and source.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
Lst_Append(tgn->children, sgn);
|
|
|
|
Lst_Append(sgn->parents, tgn);
|
|
|
|
tgn->unmade++;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the transformation rule itself
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
tname = str_concat2(ssuff->name, tsuff->name);
|
2020-11-07 19:39:21 +00:00
|
|
|
gn = FindTransformByName(tname);
|
1996-10-06 15:57:15 +00:00
|
|
|
free(tname);
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (gn == NULL) {
|
2020-11-20 03:54:37 +00:00
|
|
|
/* This can happen when linking an OP_MEMBER and OP_ARCHV node. */
|
2020-07-08 18:32:15 +00:00
|
|
|
return FALSE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
DEBUG3(SUFF,"\tapplying %s -> %s to \"%s\"\n",
|
|
|
|
ssuff->name, tsuff->name, tgn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Record last child; Make_HandleUse may add child nodes. */
|
|
|
|
ln = tgn->children->last;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Apply the rule. */
|
|
|
|
Make_HandleUse(gn, tgn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Deal with wildcards and variables in any acquired sources. */
|
|
|
|
ln = ln != NULL ? ln->next : NULL;
|
|
|
|
while (ln != NULL) {
|
|
|
|
GNodeListNode *nln = ln->next;
|
|
|
|
SuffExpandChildren(ln, tgn);
|
|
|
|
ln = nln;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-11-20 03:54:37 +00:00
|
|
|
* Keep track of another parent to which this node is transformed so
|
1996-10-06 15:57:15 +00:00
|
|
|
* the .IMPSRC variable can be set correctly for the parent.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
Lst_Append(sgn->implicitParents, tgn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-07-08 18:32:15 +00:00
|
|
|
return TRUE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Locate dependencies for an OP_ARCHV node.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* gn Node for which to locate dependencies
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Side Effects:
|
|
|
|
* Same as Suff_FindDeps
|
|
|
|
*/
|
|
|
|
static void
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindArchiveDeps(GNode *gn, SrcList *slst)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
char *eoarch; /* End of archive portion */
|
|
|
|
char *eoname; /* End of member portion */
|
|
|
|
GNode *mem; /* Node for member */
|
|
|
|
SuffListNode *ln, *nln; /* Next suffix node to check */
|
|
|
|
Suff *ms; /* Suffix descriptor for member */
|
|
|
|
char *name; /* Start of member's name */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* The node is an archive(member) pair. so we must find a
|
|
|
|
* suffix for both of them.
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
eoarch = strchr(gn->name, '(');
|
|
|
|
eoname = strchr(eoarch, ')');
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2017-04-20 23:12:37 +00:00
|
|
|
/*
|
|
|
|
* Caller guarantees the format `libname(member)', via
|
|
|
|
* Arch_ParseArchive.
|
|
|
|
*/
|
|
|
|
assert(eoarch != NULL);
|
|
|
|
assert(eoname != NULL);
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
*eoname = '\0'; /* Nuke parentheses during suffix search */
|
|
|
|
*eoarch = '\0'; /* So a suffix can be found */
|
|
|
|
|
|
|
|
name = eoarch + 1;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
mem = Targ_GetNode(name);
|
1996-10-06 15:57:15 +00:00
|
|
|
SuffFindDeps(mem, slst);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the link between the two nodes right off
|
|
|
|
*/
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(gn->children, mem);
|
|
|
|
Lst_Append(mem->parents, gn);
|
2020-11-07 19:39:21 +00:00
|
|
|
gn->unmade++;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Copy in the variables from the member node to this one.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
Var_Set(PREFIX, GNode_VarPrefix(mem), gn);
|
|
|
|
Var_Set(TARGET, GNode_VarTarget(mem), gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
ms = mem->suffix;
|
2020-11-20 03:54:37 +00:00
|
|
|
if (ms == NULL) { /* Didn't know what it was. */
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG0("using null suffix\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
ms = suffNull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the other two local variables required for this target.
|
|
|
|
*/
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(MEMBER, name, gn);
|
|
|
|
Var_Set(ARCHIVE, gn->name, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2016-03-18 17:27:26 +00:00
|
|
|
/*
|
|
|
|
* Set $@ for compatibility with other makes
|
|
|
|
*/
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(TARGET, gn->name, gn);
|
2016-03-18 17:27:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we've got the important local variables set, expand any sources
|
|
|
|
* that still contain variables or wildcards in their names.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = gn->children->first; ln != NULL; ln = nln) {
|
|
|
|
nln = ln->next;
|
2016-03-18 17:27:26 +00:00
|
|
|
SuffExpandChildren(ln, gn);
|
|
|
|
}
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
if (ms != NULL) {
|
|
|
|
/*
|
|
|
|
* Member has a known suffix, so look for a transformation rule from
|
|
|
|
* it to a possible suffix of the archive. Rather than searching
|
|
|
|
* through the entire list, we just look at suffixes to which the
|
|
|
|
* member's suffix may be transformed...
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
size_t nameLen = (size_t)(eoarch - gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Use first matching suffix... */
|
|
|
|
for (ln = ms->parents->first; ln != NULL; ln = ln->next)
|
|
|
|
if (SuffSuffIsSuffix(ln->datum, nameLen, eoarch))
|
|
|
|
break;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (ln != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Got one -- apply it
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *suff = ln->datum;
|
2020-09-05 16:11:04 +00:00
|
|
|
if (!SuffApplyTransform(gn, mem, suff, ms)) {
|
|
|
|
SUFF_DEBUG2("\tNo transformation from %s -> %s\n",
|
|
|
|
ms->name, suff->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace the opening and closing parens now we've no need of the separate
|
|
|
|
* pieces.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
*eoarch = '(';
|
|
|
|
*eoname = ')';
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pretend gn appeared to the left of a dependency operator so
|
|
|
|
* the user needn't provide a transformation from the member to the
|
|
|
|
* archive.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
if (!GNode_IsTarget(gn))
|
1996-10-06 15:57:15 +00:00
|
|
|
gn->type |= OP_DEPENDS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flag the member as such so we remember to look in the archive for
|
2016-03-18 17:27:26 +00:00
|
|
|
* its modification time. The OP_JOIN | OP_MADE is needed because this
|
|
|
|
* target should never get made.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2016-03-18 17:27:26 +00:00
|
|
|
mem->type |= OP_MEMBER | OP_JOIN | OP_MADE;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
SuffFindNormalDepsKnown(const char *name, size_t nameLen, GNode *gn,
|
|
|
|
SrcList *srcs, SrcList *targs)
|
|
|
|
{
|
|
|
|
SuffListNode *ln;
|
|
|
|
Src *targ;
|
|
|
|
char *pref;
|
|
|
|
|
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *suff = ln->datum;
|
|
|
|
if (!SuffSuffIsSuffix(suff, nameLen, name + nameLen))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen));
|
|
|
|
targ = SrcNew(bmake_strdup(gn->name), pref, suff, NULL, gn);
|
|
|
|
suff->refCount++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add nodes from which the target can be made
|
|
|
|
*/
|
|
|
|
SuffAddLevel(srcs, targ);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record the target so we can nuke it
|
|
|
|
*/
|
|
|
|
Lst_Append(targs, targ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SuffFindNormalDepsUnknown(GNode *gn, const char *sopref,
|
|
|
|
SrcList *srcs, SrcList *targs)
|
|
|
|
{
|
|
|
|
Src *targ;
|
|
|
|
|
|
|
|
if (!Lst_IsEmpty(targs) || suffNull == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SUFF_DEBUG1("\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
|
|
|
|
|
|
|
|
targ = SrcNew(bmake_strdup(gn->name), bmake_strdup(sopref),
|
|
|
|
suffNull, NULL, gn);
|
|
|
|
targ->suff->refCount++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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))
|
|
|
|
SuffAddLevel(srcs, targ);
|
|
|
|
else {
|
|
|
|
SUFF_DEBUG0("not ");
|
|
|
|
}
|
|
|
|
|
|
|
|
SUFF_DEBUG0("adding suffix rules\n");
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
SuffFindNormalDepsPath(GNode *gn, Src *targ)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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 (gn->suffix)
|
|
|
|
gn->suffix->refCount--;
|
|
|
|
gn->suffix = targ->suff;
|
|
|
|
gn->suffix->refCount++;
|
|
|
|
|
|
|
|
savec = gn->path[savep];
|
|
|
|
gn->path[savep] = '\0';
|
|
|
|
|
|
|
|
if ((ptr = strrchr(gn->path, '/')) != NULL)
|
|
|
|
ptr++;
|
|
|
|
else
|
|
|
|
ptr = gn->path;
|
|
|
|
|
|
|
|
Var_Set(PREFIX, ptr, gn);
|
|
|
|
|
|
|
|
gn->path[savep] = savec;
|
|
|
|
} else {
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
/* The .PREFIX gets the full path if the target has no known suffix. */
|
|
|
|
if (gn->suffix)
|
|
|
|
gn->suffix->refCount--;
|
|
|
|
gn->suffix = NULL;
|
|
|
|
|
|
|
|
if ((ptr = strrchr(gn->path, '/')) != NULL)
|
|
|
|
ptr++;
|
|
|
|
else
|
|
|
|
ptr = gn->path;
|
|
|
|
|
|
|
|
Var_Set(PREFIX, ptr, gn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Locate implicit dependencies for regular targets.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* gn Node for which to find sources
|
|
|
|
*
|
1996-10-06 15:57:15 +00:00
|
|
|
* Side Effects:
|
2020-09-05 16:11:04 +00:00
|
|
|
* Same as Suff_FindDeps
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
static void
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindNormalDeps(GNode *gn, SrcList *slst)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SrcList *srcs; /* List of sources at which to look */
|
|
|
|
SrcList *targs; /* List of targets to which things can be
|
|
|
|
* transformed. They all have the same file,
|
|
|
|
* but different suff and pref fields */
|
|
|
|
Src *bottom; /* Start of found transformation path */
|
|
|
|
Src *src; /* General Src pointer */
|
|
|
|
char *pref; /* Prefix to use */
|
|
|
|
Src *targ; /* General Src target pointer */
|
|
|
|
|
|
|
|
const char *name = gn->name;
|
|
|
|
size_t nameLen = strlen(name);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Begin at the beginning...
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
srcs = Lst_New();
|
|
|
|
targs = Lst_New();
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-05-20 22:35:32 +00:00
|
|
|
bottom = NULL;
|
|
|
|
targ = NULL;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2013-05-20 22:35:32 +00:00
|
|
|
if (!(gn->type & OP_PHONY)) {
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindNormalDepsKnown(name, nameLen, gn, srcs, targs);
|
2013-05-20 22:35:32 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Handle target of unknown suffix... */
|
|
|
|
SuffFindNormalDepsUnknown(gn, name, srcs, targs);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2013-05-20 22:35:32 +00:00
|
|
|
* Using the list of possible sources built up from the target
|
|
|
|
* suffix(es), try and find an existing file/target that matches.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2013-05-20 22:35:32 +00:00
|
|
|
bottom = SuffFindThem(srcs, slst);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2013-05-20 22:35:32 +00:00
|
|
|
if (bottom == NULL) {
|
|
|
|
/*
|
|
|
|
* No known transformations -- use the first suffix found
|
|
|
|
* for setting the local variables.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
if (targs->first != NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
targ = targs->first->datum;
|
2020-11-20 03:54:37 +00:00
|
|
|
else
|
2013-05-20 22:35:32 +00:00
|
|
|
targ = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
2013-05-20 22:35:32 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
Var_Set(TARGET, GNode_Path(gn), gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
pref = targ != NULL ? targ->pref : gn->name;
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(PREFIX, pref, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we've got the important local variables set, expand any sources
|
|
|
|
* that still contain variables or wildcards in their names.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
|
|
|
SuffListNode *ln, *nln;
|
|
|
|
for (ln = gn->children->first; ln != NULL; ln = nln) {
|
|
|
|
nln = ln->next;
|
|
|
|
SuffExpandChildren(ln, gn);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
if (targ == NULL) {
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("\tNo valid suffix on %s\n", gn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
sfnd_abort:
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindNormalDepsPath(gn, targ);
|
1996-10-06 15:57:15 +00:00
|
|
|
goto sfnd_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the suffix indicates that the target is a library, mark that in
|
|
|
|
* the node's type field.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
if (targ->suff->flags & SUFF_LIBRARY)
|
1996-10-06 15:57:15 +00:00
|
|
|
gn->type |= OP_LIB;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for overriding transformation rule implied by sources
|
|
|
|
*/
|
|
|
|
if (!Lst_IsEmpty(gn->children)) {
|
|
|
|
src = SuffFindCmds(targ, slst);
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
if (src != NULL) {
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
|
|
|
* Free up all the Src structures in the transformation path
|
|
|
|
* up to, but not including, the parent node.
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
while (bottom != NULL && bottom->parent != NULL) {
|
|
|
|
if (Lst_FindDatum(slst, bottom) == NULL)
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(slst, bottom);
|
1996-10-06 15:57:15 +00:00
|
|
|
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 Src structures 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 by the commands of the final
|
|
|
|
* transformation rule. Also, the unmade field of gn is incremented.
|
2012-06-08 21:57:36 +00:00
|
|
|
* Etc.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
if (bottom->node == NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
bottom->node = Targ_GetNode(bottom->file);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
for (src = bottom; src->parent != NULL; src = src->parent) {
|
1996-10-06 15:57:15 +00:00
|
|
|
targ = src->parent;
|
|
|
|
|
|
|
|
if (src->node->suffix)
|
|
|
|
src->node->suffix->refCount--;
|
|
|
|
src->node->suffix = src->suff;
|
|
|
|
src->node->suffix->refCount++;
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (targ->node == NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
targ->node = Targ_GetNode(targ->file);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
SuffApplyTransform(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
|
2020-11-20 03:54:37 +00:00
|
|
|
* node, so all we need to do is set the standard variables.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
targ->node->type |= OP_DEPS_FOUND;
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(PREFIX, targ->pref, targ->node);
|
|
|
|
Var_Set(TARGET, targ->node->name, targ->node);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (gn->suffix != NULL)
|
1996-10-06 15:57:15 +00:00
|
|
|
gn->suffix->refCount--;
|
|
|
|
gn->suffix = src->suff;
|
|
|
|
gn->suffix->refCount++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nuke the transformation path and the Src structures left over in the
|
|
|
|
* two lists.
|
|
|
|
*/
|
|
|
|
sfnd_return:
|
2020-11-20 03:54:37 +00:00
|
|
|
if (bottom != NULL && Lst_FindDatum(slst, bottom) == NULL)
|
|
|
|
Lst_Append(slst, bottom);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
while (SuffRemoveSrc(srcs) || SuffRemoveSrc(targs))
|
|
|
|
continue;
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_MoveAll(slst, srcs);
|
|
|
|
Lst_MoveAll(slst, targs);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* Find implicit sources for the target.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-09-05 16:11:04 +00:00
|
|
|
* Nodes are added to the graph below the passed-in node. The nodes are
|
|
|
|
* marked to have their IMPSRC variable filled in. The PREFIX variable is set
|
|
|
|
* for the given node and all its implied children.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2020-09-05 16:11:04 +00:00
|
|
|
* The path found by this target is the shortest path in the transformation
|
|
|
|
* graph, which may pass through non-existent targets, to an existing target.
|
|
|
|
* The search continues on all paths from the root suffix until a file is
|
|
|
|
* found. I.e. if there's a path .o -> .c -> .l -> .l,v from the root and the
|
|
|
|
* .l,v file exists but the .c and .l files don't, the search will branch out
|
|
|
|
* in all directions from .o and again from all the nodes on the next level
|
|
|
|
* until the .l,v node is encountered.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_FindDeps(GNode *gn)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
SuffFindDeps(gn, srclist);
|
|
|
|
while (SuffRemoveSrc(srclist))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffFindDeps(GNode *gn, SrcList *slst)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-09-05 16:11:04 +00:00
|
|
|
if (gn->type & OP_DEPS_FOUND)
|
1996-10-06 15:57:15 +00:00
|
|
|
return;
|
2020-09-05 16:11:04 +00:00
|
|
|
gn->type |= OP_DEPS_FOUND;
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* Make sure we have these set, may get revised below.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
Var_Set(TARGET, GNode_Path(gn), gn);
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(PREFIX, gn->name, gn);
|
2013-05-20 22:35:32 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
SUFF_DEBUG1("SuffFindDeps (%s)\n", gn->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
if (gn->type & OP_ARCHV) {
|
|
|
|
SuffFindArchiveDeps(gn, slst);
|
|
|
|
} else if (gn->type & OP_LIB) {
|
|
|
|
/*
|
|
|
|
* If the node is a library, it is the arch module's job to find it
|
|
|
|
* and set the TARGET variable accordingly. We merely provide the
|
|
|
|
* search path, assuming all libraries end in ".a" (if the suffix
|
|
|
|
* hasn't been defined, there's nothing we can do for it, so we just
|
|
|
|
* set the TARGET variable to the node's name in order to give it a
|
|
|
|
* value).
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff *s = FindSuffByName(LIBSUFF);
|
1996-10-06 15:57:15 +00:00
|
|
|
if (gn->suffix)
|
|
|
|
gn->suffix->refCount--;
|
2020-11-07 19:39:21 +00:00
|
|
|
if (s != NULL) {
|
|
|
|
gn->suffix = s;
|
1996-10-06 15:57:15 +00:00
|
|
|
gn->suffix->refCount++;
|
2012-06-08 21:57:36 +00:00
|
|
|
Arch_FindLib(gn, s->searchPath);
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
gn->suffix = NULL;
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(TARGET, gn->name, gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
2020-07-08 18:32:15 +00:00
|
|
|
Var_Set(PREFIX, "", gn);
|
1996-10-06 15:57:15 +00:00
|
|
|
} else {
|
|
|
|
SuffFindNormalDeps(gn, slst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* 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.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2012-06-08 21:57:36 +00:00
|
|
|
* Input:
|
|
|
|
* name Name of null suffix
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_SetNull(const char *name)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
Suff *suff = FindSuffByName(name);
|
|
|
|
if (suff == NULL) {
|
2012-06-08 21:57:36 +00:00
|
|
|
Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
|
2020-11-07 19:39:21 +00:00
|
|
|
name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
if (suffNull != NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
suffNull->flags &= ~(unsigned)SUFF_NULL;
|
2020-11-20 03:54:37 +00:00
|
|
|
suff->flags |= SUFF_NULL;
|
2020-11-07 19:39:21 +00:00
|
|
|
/*
|
|
|
|
* XXX: Here's where the transformation mangling would take place
|
|
|
|
*/
|
2020-11-20 03:54:37 +00:00
|
|
|
suffNull = suff;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Initialize the suffixes module. */
|
1996-10-06 15:57:15 +00:00
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_Init(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2020-11-07 19:39:21 +00:00
|
|
|
suffClean = Lst_New();
|
|
|
|
sufflist = Lst_New();
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
srclist = Lst_New();
|
|
|
|
transforms = Lst_New();
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-12-25 08:09:48 +00:00
|
|
|
Suff_ClearSuffixes();
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Clean up the suffixes module. */
|
1996-10-06 15:57:15 +00:00
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_End(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
1996-10-06 15:57:15 +00:00
|
|
|
Lst_Destroy(sufflist, SuffFree);
|
|
|
|
Lst_Destroy(suffClean, SuffFree);
|
|
|
|
if (suffNull)
|
|
|
|
SuffFree(suffNull);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(srclist);
|
|
|
|
Lst_Free(transforms);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
PrintSuffNames(const char *prefix, SuffList *suffs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
SuffListNode *ln;
|
2016-09-08 23:49:33 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#\t%s: ", prefix);
|
|
|
|
for (ln = suffs->first; ln != NULL; ln = ln->next) {
|
|
|
|
Suff *suff = ln->datum;
|
|
|
|
debug_printf("%s ", suff->name);
|
|
|
|
}
|
|
|
|
debug_printf("\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
2020-11-20 03:54:37 +00:00
|
|
|
PrintSuff(Suff *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-20 03:54:37 +00:00
|
|
|
debug_printf("# \"%s\" (num %d, ref %d)",
|
|
|
|
suff->name, suff->sNum, suff->refCount);
|
|
|
|
if (suff->flags != 0) {
|
2020-09-05 16:11:04 +00:00
|
|
|
char flags_buf[SuffFlags_ToStringSize];
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf(" (%s)",
|
|
|
|
Enum_FlagsToString(flags_buf, sizeof flags_buf,
|
2020-11-20 03:54:37 +00:00
|
|
|
suff->flags, SuffFlags_ToStringSpecs));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("\n");
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
PrintSuffNames("To", suff->parents);
|
|
|
|
PrintSuffNames("From", suff->children);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
debug_printf("#\tSearch Path: ");
|
2020-11-20 03:54:37 +00:00
|
|
|
Dir_PrintPath(suff->searchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
PrintTransformation(GNode *t)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("%-16s:", t->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
Targ_PrintType(t->type);
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("\n");
|
|
|
|
Targ_PrintCmds(t);
|
|
|
|
debug_printf("\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_PrintAll(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#*** Suffixes:\n");
|
|
|
|
{
|
|
|
|
SuffListNode *ln;
|
|
|
|
for (ln = sufflist->first; ln != NULL; ln = ln->next)
|
|
|
|
PrintSuff(ln->datum);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#*** Transformations:\n");
|
|
|
|
{
|
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = transforms->first; ln != NULL; ln = ln->next)
|
|
|
|
PrintTransformation(ln->datum);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|