2021-12-18 07:27:22 +00:00
|
|
|
/* $NetBSD: suff.c,v 1.357 2021/12/12 20:45:48 sjg 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
|
|
|
*
|
2021-06-25 18:16:24 +00:00
|
|
|
* Suff_ExtendPaths
|
|
|
|
* Extend the search path of each suffix to include the
|
2020-11-20 03:54:37 +00:00
|
|
|
* 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" */
|
2021-12-18 07:27:22 +00:00
|
|
|
MAKE_RCSID("$NetBSD: suff.c,v 1.357 2021/12/12 20:45:48 sjg Exp $");
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
typedef List SuffixList;
|
|
|
|
typedef ListNode SuffixListNode;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
typedef List CandidateList;
|
|
|
|
typedef ListNode CandidateListNode;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* The defined suffixes, such as '.c', '.o', '.l'. */
|
|
|
|
static SuffixList sufflist = LST_INIT;
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2021-01-14 01:24:34 +00:00
|
|
|
/* The suffixes to be cleaned up at the end. */
|
|
|
|
static SuffixList suffClean = LST_INIT;
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Counter for assigning suffix numbers.
|
|
|
|
* TODO: What are these suffix numbers used for?
|
|
|
|
*/
|
|
|
|
static int sNum = 0;
|
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
typedef List SuffixListList;
|
2021-01-14 01:24:34 +00:00
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
/*
|
|
|
|
* A suffix such as ".c" or ".o" that is used in suffix transformation rules
|
|
|
|
* 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;
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* This suffix marks include files. Their search path ends up in the
|
|
|
|
* undocumented special variable '.INCLUDES'.
|
|
|
|
*/
|
2021-12-18 07:27:22 +00:00
|
|
|
bool include:1;
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* This suffix marks library files. Their search path ends up in the
|
|
|
|
* undocumented special variable '.LIBS'.
|
|
|
|
*/
|
2021-12-18 07:27:22 +00:00
|
|
|
bool library:1;
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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?
|
|
|
|
*/
|
2021-12-18 07:27:22 +00:00
|
|
|
bool isNull:1;
|
2021-01-14 01:24:34 +00:00
|
|
|
/* The path along which files of this suffix may be found */
|
|
|
|
SearchPath *searchPath;
|
2021-12-18 07:27:22 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* The suffix number; TODO: document the purpose of this number */
|
|
|
|
int sNum;
|
|
|
|
/* Reference count of list membership and several other places */
|
|
|
|
int refCount;
|
2021-12-18 07:27:22 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Suffixes we have a transformation to */
|
|
|
|
SuffixList parents;
|
|
|
|
/* Suffixes we have a transformation from */
|
|
|
|
SuffixList children;
|
2021-12-18 07:27:22 +00:00
|
|
|
/*
|
|
|
|
* Lists in which this suffix is referenced.
|
2021-01-14 01:24:34 +00:00
|
|
|
*
|
|
|
|
* XXX: These lists are used nowhere, they are just appended to, for
|
|
|
|
* no apparent reason. They do have the side effect of increasing
|
2021-12-18 07:27:22 +00:00
|
|
|
* refCount though.
|
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListList ref;
|
|
|
|
} Suffix;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A candidate when searching for implied sources.
|
|
|
|
*
|
|
|
|
* For example, when "src.o" is to be made, a typical candidate is "src.c"
|
|
|
|
* via the transformation rule ".c.o". If that doesn't exist, maybe there is
|
|
|
|
* another transformation rule ".pas.c" that would make "src.pas" an indirect
|
|
|
|
* candidate as well. The first such chain that leads to an existing file or
|
|
|
|
* 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;
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList childrenList;
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
} Candidate;
|
|
|
|
|
|
|
|
typedef struct CandidateSearcher {
|
|
|
|
|
|
|
|
CandidateList list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Add HashSet for seen entries, to avoid endless loops such as
|
|
|
|
* in suff-transform-endless.mk.
|
|
|
|
*/
|
|
|
|
|
|
|
|
} CandidateSearcher;
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* TODO: Document the difference between nullSuff and emptySuff. */
|
2020-11-20 03:54:37 +00:00
|
|
|
/* The NULL suffix for this run */
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *nullSuff;
|
2020-11-20 03:54:37 +00:00
|
|
|
/* The empty suffix required for POSIX single-suffix transformation rules */
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *emptySuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *
|
|
|
|
Suffix_Ref(Suffix *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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set a Suffix variable to NULL, adjusting the reference count. */
|
|
|
|
static void
|
|
|
|
Suffix_Unassign(Suffix **var)
|
|
|
|
{
|
|
|
|
if (*var != NULL)
|
|
|
|
(*var)->refCount--;
|
|
|
|
*var = NULL;
|
|
|
|
}
|
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 *
|
2021-01-14 01:24:34 +00:00
|
|
|
StrTrimPrefix(const char *pref, const char *str)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
while (*str != '\0' && *pref == *str) {
|
|
|
|
pref++;
|
|
|
|
str++;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
return *pref != '\0' ? NULL : str;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* See if suff is a suffix of str, and if so, return the pointer to the suffix
|
|
|
|
* in str, which at the same time marks the end of the prefix.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static const char *
|
2021-01-14 01:24:34 +00:00
|
|
|
StrTrimSuffix(const char *str, size_t strLen, const char *suff, size_t suffLen)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
const char *suffInStr;
|
|
|
|
size_t i;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (strLen < suffLen)
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
suffInStr = str + strLen - suffLen;
|
|
|
|
for (i = 0; i < suffLen; i++)
|
|
|
|
if (suff[i] != suffInStr[i])
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
return suffInStr;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* See if suff is a suffix of name, and if so, return the end of the prefix
|
|
|
|
* in name.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
Suffix_TrimSuffix(const Suffix *suff, size_t nameLen, const char *nameEnd)
|
|
|
|
{
|
|
|
|
return StrTrimSuffix(nameEnd - nameLen, nameLen,
|
|
|
|
suff->name, suff->nameLen);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-06-25 18:16:24 +00:00
|
|
|
static bool
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix_IsSuffix(const Suffix *suff, size_t nameLen, const char *nameEnd)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
return Suffix_TrimSuffix(suff, nameLen, nameEnd) != NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *
|
|
|
|
FindSuffixByNameLen(const char *name, size_t nameLen)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *
|
|
|
|
FindSuffixByName(const char *name)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
return FindSuffixByNameLen(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
|
|
|
{
|
2021-01-14 01:24:34 +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
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixList_Unref(SuffixList *list, Suffix *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln = Lst_FindDatum(list, suff);
|
|
|
|
if (ln != NULL) {
|
|
|
|
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
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix_Free(Suffix *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (suff == nullSuff)
|
|
|
|
nullSuff = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (suff == emptySuff)
|
|
|
|
emptySuff = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#if 0
|
2021-01-14 01:24:34 +00:00
|
|
|
/* 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);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Done(&suff->ref);
|
|
|
|
Lst_Done(&suff->children);
|
|
|
|
Lst_Done(&suff->parents);
|
|
|
|
SearchPath_Free(suff->searchPath);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
free(suff->name);
|
|
|
|
free(suff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SuffFree(void *p)
|
|
|
|
{
|
|
|
|
Suffix_Free(p);
|
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
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixList_Remove(SuffixList *list, Suffix *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
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);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Insert the suffix into the list, keeping the list ordered by suffix
|
|
|
|
* number.
|
|
|
|
*/
|
1996-10-06 15:57:15 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixList_Insert(SuffixList *list, Suffix *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln;
|
|
|
|
Suffix *listSuff = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
for (ln = list->first; ln != NULL; ln = ln->next) {
|
|
|
|
listSuff = ln->datum;
|
|
|
|
if (listSuff->sNum >= suff->sNum)
|
|
|
|
break;
|
|
|
|
}
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (ln == NULL) {
|
|
|
|
DEBUG2(SUFF, "inserting \"%s\" (%d) at end of list\n",
|
2020-11-07 19:39:21 +00:00
|
|
|
suff->name, suff->sNum);
|
2021-01-14 01:24:34 +00:00
|
|
|
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 {
|
|
|
|
DEBUG2(SUFF, "\"%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
|
2021-01-14 01:24:34 +00:00
|
|
|
Relate(Suffix *srcSuff, Suffix *targSuff)
|
2020-11-20 03:54:37 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixList_Insert(&targSuff->children, srcSuff);
|
|
|
|
SuffixList_Insert(&srcSuff->parents, targSuff);
|
2020-11-20 03:54:37 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static Suffix *
|
|
|
|
Suffix_New(const char *name)
|
2020-09-05 16:11:04 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
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++;
|
2021-12-18 07:27:22 +00:00
|
|
|
suff->include = false;
|
|
|
|
suff->library = false;
|
|
|
|
suff->isNull = false;
|
2021-01-14 01:24:34 +00:00
|
|
|
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
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_MoveAll(&suffClean, &sufflist);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
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);
|
2021-12-18 07:27:22 +00:00
|
|
|
nullSuff->include = false;
|
|
|
|
nullSuff->library = false;
|
|
|
|
nullSuff->isNull = true;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Parse a transformation string such as ".c.o" to find its two component
|
2020-11-07 19:39:21 +00:00
|
|
|
* 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
|
|
|
*
|
2021-06-25 18:16:24 +00:00
|
|
|
* Return true if the string is a valid transformation.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
static bool
|
2021-01-14 01:24:34 +00:00
|
|
|
ParseTransform(const char *str, Suffix **out_src, Suffix **out_targ)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln;
|
|
|
|
Suffix *single = NULL;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +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.
|
|
|
|
*/
|
|
|
|
for (ln = sufflist.first; ln != NULL; ln = ln->next) {
|
|
|
|
Suffix *src = ln->datum;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (StrTrimPrefix(src->name, str) == NULL)
|
|
|
|
continue;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (str[src->nameLen] == '\0') {
|
|
|
|
single = src;
|
|
|
|
} else {
|
|
|
|
Suffix *targ = FindSuffixByName(str + src->nameLen);
|
|
|
|
if (targ != NULL) {
|
|
|
|
*out_src = src;
|
|
|
|
*out_targ = targ;
|
2021-06-25 18:16:24 +00:00
|
|
|
return true;
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2021-06-25 18:16:24 +00:00
|
|
|
return true;
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
2021-06-25 18:16:24 +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
|
2021-01-14 01:24:34 +00:00
|
|
|
* such as ".o".
|
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
bool
|
2020-11-07 19:39:21 +00:00
|
|
|
Suff_IsTransform(const char *str)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *src, *targ;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
return ParseTransform(str, &src, &targ);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Add the transformation rule to the list of rules and place the
|
2020-11-07 19:39:21 +00:00
|
|
|
* 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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *srcSuff;
|
|
|
|
Suffix *targSuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
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);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
gn->type = OP_TRANSFORM;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
{
|
|
|
|
/* TODO: Avoid the redundant parsing here. */
|
2021-06-25 18:16:24 +00:00
|
|
|
bool ok = ParseTransform(name, &srcSuff, &targSuff);
|
2021-01-14 01:24:34 +00:00
|
|
|
assert(ok);
|
2021-12-18 07:27:22 +00:00
|
|
|
/* LINTED 129 *//* expression has null effect */
|
2021-01-14 01:24:34 +00:00
|
|
|
(void)ok;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Link the two together in the proper relationship and order. */
|
|
|
|
DEBUG2(SUFF, "defining transformation from `%s' to `%s'\n",
|
|
|
|
srcSuff->name, targSuff->name);
|
|
|
|
Relate(srcSuff, targSuff);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
return gn;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Handle the finish of a transformation definition, removing the
|
2020-09-05 16:11:04 +00:00
|
|
|
* 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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *srcSuff, *targSuff;
|
|
|
|
SuffixList *srcSuffParents;
|
|
|
|
|
|
|
|
if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(&gn->cohorts))
|
|
|
|
gn = gn->cohorts.last->datum;
|
2020-11-20 03:54:37 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (!(gn->type & OP_TRANSFORM))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!Lst_IsEmpty(&gn->commands) || !Lst_IsEmpty(&gn->children)) {
|
|
|
|
DEBUG1(SUFF, "transformation %s complete\n", gn->name);
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
if (!ParseTransform(gn->name, &srcSuff, &targSuff))
|
|
|
|
return;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG2(SUFF, "deleting incomplete transformation from `%s' to `%s'\n",
|
|
|
|
srcSuff->name, targSuff->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Remember the parents since srcSuff could be deleted in
|
|
|
|
* SuffixList_Remove.
|
|
|
|
*/
|
|
|
|
srcSuffParents = &srcSuff->parents;
|
|
|
|
SuffixList_Remove(&targSuff->children, srcSuff);
|
|
|
|
SuffixList_Remove(srcSuffParents, targSuff);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +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
|
2021-01-14 01:24:34 +00:00
|
|
|
RebuildGraph(GNode *transform, Suffix *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;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* During Suff_AddSuffix, search through the list of existing targets and find
|
2020-11-07 19:39:21 +00:00
|
|
|
* 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:
|
2021-06-25 18:16:24 +00:00
|
|
|
* true iff a new main target has been selected.
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
static bool
|
2021-01-14 01:24:34 +00:00
|
|
|
UpdateTarget(GNode *target, GNode **inout_main, Suffix *suff,
|
2021-06-25 18:16:24 +00:00
|
|
|
bool *inout_removedMain)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *srcSuff, *targSuff;
|
|
|
|
char *ptr;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
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);
|
|
|
|
/*
|
2021-06-25 18:16:24 +00:00
|
|
|
* XXX: Why could it be a good idea to return true here?
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/*
|
2021-06-25 18:16:24 +00:00
|
|
|
* XXX: Even when changing this to false, none of the existing
|
2021-01-14 01:24:34 +00:00
|
|
|
* unit tests fails.
|
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
return true;
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (target->type == OP_TRANSFORM)
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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.
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
if (ptr == target->name)
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
if (ParseTransform(target->name, &srcSuff, &targSuff)) {
|
|
|
|
if (*inout_main == target) {
|
|
|
|
DEBUG1(MAKE,
|
|
|
|
"Setting main node from \"%s\" back to null\n",
|
|
|
|
target->name);
|
2021-06-25 18:16:24 +00:00
|
|
|
*inout_removedMain = true;
|
2021-01-14 01:24:34 +00:00
|
|
|
*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.
|
|
|
|
*/
|
|
|
|
DEBUG2(SUFF, "defining transformation from `%s' to `%s'\n",
|
2020-11-20 03:54:37 +00:00
|
|
|
srcSuff->name, targSuff->name);
|
2021-01-14 01:24:34 +00:00
|
|
|
Relate(srcSuff, targSuff);
|
|
|
|
}
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Look at all existing targets to see if adding this suffix will make one
|
2020-11-07 19:39:21 +00:00
|
|
|
* of the current targets mutate into a suffix rule.
|
|
|
|
*
|
|
|
|
* This is ugly, but other makes treat all targets that start with a '.' as
|
2021-01-14 01:24:34 +00:00
|
|
|
* suffix rules.
|
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
UpdateTargets(GNode **inout_main, Suffix *suff)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-06-25 18:16:24 +00:00
|
|
|
bool removedMain = false;
|
2021-01-14 01:24:34 +00:00
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
for (ln = Targ_List()->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
if (UpdateTarget(gn, inout_main, suff, &removedMain))
|
|
|
|
break;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +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
|
|
|
*
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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.
|
2020-09-05 16:11:04 +00:00
|
|
|
* 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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
GNodeListNode *ln;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *suff = FindSuffixByName(name);
|
|
|
|
if (suff != NULL)
|
|
|
|
return;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
suff = Suffix_New(name);
|
|
|
|
Lst_Append(&sufflist, suff);
|
|
|
|
DEBUG1(SUFF, "Adding suffix \"%s\"\n", suff->name);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
UpdateTargets(inout_main, suff);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *suff = FindSuffixByName(sname);
|
|
|
|
return suff != NULL ? suff->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
|
2021-06-25 18:16:24 +00:00
|
|
|
Suff_ExtendPaths(void)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2021-02-11 01:51:11 +00:00
|
|
|
if (!Lst_IsEmpty(&suff->searchPath->dirs)) {
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef INCLUDES
|
2021-12-18 07:27:22 +00:00
|
|
|
if (suff->include)
|
2021-01-14 01:24:34 +00:00
|
|
|
SearchPath_AddAll(includesPath,
|
|
|
|
suff->searchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef LIBRARIES
|
2021-12-18 07:27:22 +00:00
|
|
|
if (suff->library)
|
2021-01-14 01:24:34 +00:00
|
|
|
SearchPath_AddAll(libsPath, suff->searchPath);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
SearchPath_AddAll(suff->searchPath, &dirSearchPath);
|
|
|
|
} else {
|
|
|
|
SearchPath_Free(suff->searchPath);
|
|
|
|
suff->searchPath = Dir_CopyDirSearchPath();
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
flags = SearchPath_ToFlags(includesPath, "-I");
|
|
|
|
Global_Set(".INCLUDES", flags);
|
2021-01-14 01:24:34 +00:00
|
|
|
free(flags);
|
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
flags = SearchPath_ToFlags(libsPath, "-L");
|
|
|
|
Global_Set(".LIBS", flags);
|
2021-01-14 01:24:34 +00:00
|
|
|
free(flags);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
SearchPath_Free(includesPath);
|
|
|
|
SearchPath_Free(libsPath);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Add the given suffix as a type of file which gets included.
|
|
|
|
* Called when a '.INCLUDES: .h' line is parsed.
|
|
|
|
* To have an effect, the suffix must already exist.
|
|
|
|
* This affects the magic variable '.INCLUDES'.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2021-01-14 01:24:34 +00:00
|
|
|
Suff_AddInclude(const char *suffName)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *suff = FindSuffixByName(suffName);
|
|
|
|
if (suff != NULL)
|
2021-12-18 07:27:22 +00:00
|
|
|
suff->include = true;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Add the given suffix as a type of file which is a library.
|
|
|
|
* Called when a '.LIBS: .a' line is parsed.
|
|
|
|
* To have an effect, the suffix must already exist.
|
|
|
|
* This affects the magic variable '.LIBS'.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
|
|
|
void
|
2021-01-14 01:24:34 +00:00
|
|
|
Suff_AddLib(const char *suffName)
|
|
|
|
{
|
|
|
|
Suffix *suff = FindSuffixByName(suffName);
|
|
|
|
if (suff != NULL)
|
2021-12-18 07:27:22 +00:00
|
|
|
suff->library = true;
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/********** Implicit Source Search Functions *********/
|
|
|
|
|
|
|
|
static void
|
|
|
|
CandidateSearcher_Init(CandidateSearcher *cs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Init(&cs->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CandidateSearcher_Done(CandidateSearcher *cs)
|
|
|
|
{
|
|
|
|
Lst_Done(&cs->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CandidateSearcher_Add(CandidateSearcher *cs, Candidate *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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CandidateSearcher_MoveAll(CandidateSearcher *cs, CandidateList *list)
|
|
|
|
{
|
|
|
|
/* TODO: filter duplicates */
|
|
|
|
Lst_MoveAll(&cs->list, list);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList_PrintAddrs(CandidateList *list)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
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");
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static Candidate *
|
|
|
|
Candidate_New(char *name, char *prefix, Suffix *suff, Candidate *parent,
|
|
|
|
GNode *gn)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2020-11-07 19:39:21 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Init(&cand->childrenList);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
return cand;
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Add a new candidate to the list. */
|
|
|
|
/*ARGSUSED*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList_Add(CandidateList *list, char *srcName, Candidate *targ,
|
|
|
|
Suffix *suff, const char *debug_tag)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Candidate *cand = Candidate_New(srcName, targ->prefix, suff, targ,
|
|
|
|
NULL);
|
|
|
|
targ->numChildren++;
|
|
|
|
Lst_Append(list, cand);
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
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);
|
2020-11-07 19:39:21 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Add all candidates to the list that can be formed by applying a suffix to
|
|
|
|
* the candidate.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList_AddCandidatesFor(CandidateList *list, Candidate *cand)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln;
|
|
|
|
for (ln = cand->suff->children.first; ln != NULL; ln = ln->next) {
|
|
|
|
Suffix *suff = ln->datum;
|
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
if (suff->isNull && suff->name[0] != '\0') {
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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");
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList_Add(list, str_concat2(cand->prefix, suff->name),
|
|
|
|
cand, suff, "2");
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Free the first candidate in the list that is not referenced anymore.
|
|
|
|
* Return whether a candidate was removed.
|
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
static bool
|
2021-01-14 01:24:34 +00:00
|
|
|
RemoveCandidate(CandidateList *srcs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateListNode *ln;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("cleaning list %p:", srcs);
|
|
|
|
CandidateList_PrintAddrs(srcs);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
for (ln = srcs->first; ln != NULL; ln = ln->next) {
|
|
|
|
Candidate *src = ln->datum;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (src->numChildren == 0) {
|
|
|
|
if (src->parent == NULL)
|
|
|
|
free(src->prefix);
|
|
|
|
else {
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
/* XXX: Lst_RemoveDatum */
|
|
|
|
CandidateListNode *ln2;
|
|
|
|
ln2 = Lst_FindDatum(&src->parent->childrenList,
|
|
|
|
src);
|
|
|
|
if (ln2 != NULL)
|
|
|
|
Lst_Remove(&src->parent->childrenList,
|
|
|
|
ln2);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
src->parent->numChildren--;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("free: list %p src %p:%s children %d\n",
|
|
|
|
srcs, src, src->file, src->numChildren);
|
|
|
|
Lst_Done(&src->childrenList);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Remove(srcs, ln);
|
|
|
|
free(src->file);
|
|
|
|
free(src);
|
2021-06-25 18:16:24 +00:00
|
|
|
return true;
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
else {
|
|
|
|
debug_printf("keep: list %p src %p:%s children %d:",
|
|
|
|
srcs, src, src->file, src->numChildren);
|
|
|
|
CandidateList_PrintAddrs(&src->childrenList);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-06-25 18:16:24 +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. */
|
2021-01-14 01:24:34 +00:00
|
|
|
static Candidate *
|
|
|
|
FindThem(CandidateList *srcs, CandidateSearcher *cs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
HashSet seen;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
HashSet_Init(&seen);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
while (!Lst_IsEmpty(srcs)) {
|
|
|
|
Candidate *src = Lst_Dequeue(srcs);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_SRC
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("remove from list %p src %p:%s\n",
|
|
|
|
srcs, src, src->file);
|
1996-10-06 15:57:15 +00:00
|
|
|
#endif
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG1(SUFF, "\ttrying %s...", src->file);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
DEBUG0(SUFF, "got it\n");
|
|
|
|
return src;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
{
|
|
|
|
char *file = Dir_FindFile(src->file,
|
|
|
|
src->suff->searchPath);
|
|
|
|
if (file != NULL) {
|
|
|
|
free(file);
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG0(SUFF, "not there\n");
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (HashSet_Add(&seen, src->file))
|
|
|
|
CandidateList_AddCandidatesFor(srcs, src);
|
|
|
|
else {
|
|
|
|
DEBUG1(SUFF, "FindThem: skipping duplicate \"%s\"\n",
|
|
|
|
src->file);
|
|
|
|
}
|
|
|
|
|
|
|
|
CandidateSearcher_Add(cs, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet_Done(&seen);
|
|
|
|
return NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* See if any of the children of the candidate's GNode is one from which the
|
|
|
|
* target can be transformed. If there is one, a candidate is put together
|
|
|
|
* for it and returned.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
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 */
|
2021-02-11 01:51:11 +00:00
|
|
|
Suffix *suff; /* Suffix of the matching candidate */
|
2021-01-14 01:24:34 +00:00
|
|
|
Candidate *ret; /* Return value */
|
|
|
|
|
|
|
|
tgn = targ->node;
|
|
|
|
prefLen = strlen(targ->prefix);
|
|
|
|
|
|
|
|
for (gln = tgn->children.first; gln != NULL; gln = gln->next) {
|
2021-02-11 01:51:11 +00:00
|
|
|
const char *base;
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
base = str_basename(sgn->name);
|
|
|
|
if (strncmp(base, targ->prefix, prefLen) != 0)
|
2021-01-14 01:24:34 +00:00
|
|
|
continue;
|
|
|
|
/* The node matches the prefix, see if it has a known suffix. */
|
2021-02-11 01:51:11 +00:00
|
|
|
suff = FindSuffixByName(base + prefLen);
|
2021-01-14 01:24:34 +00:00
|
|
|
if (suff == NULL)
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (Lst_FindDatum(&suff->parents, targ->suff) != NULL)
|
|
|
|
break;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
if (gln == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
#endif
|
|
|
|
CandidateSearcher_Add(cs, ret);
|
|
|
|
DEBUG1(SUFF, "\tusing existing source %s\n", sgn->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ExpandWildcards(GNodeListNode *cln, GNode *pgn)
|
|
|
|
{
|
|
|
|
GNode *cgn = cln->datum;
|
|
|
|
StringList expansions;
|
|
|
|
|
|
|
|
if (!Dir_HasWildcards(cgn->name))
|
|
|
|
return;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* Expand the word along the chosen path
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Init(&expansions);
|
2021-02-11 01:51:11 +00:00
|
|
|
SearchPath_Expand(Suff_FindPath(cgn), cgn->name, &expansions);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
while (!Lst_IsEmpty(&expansions)) {
|
|
|
|
GNode *gn;
|
|
|
|
/*
|
|
|
|
* Fetch next expansion off the list and find its GNode
|
|
|
|
*/
|
|
|
|
char *cp = Lst_Dequeue(&expansions);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG1(SUFF, "%s...", cp);
|
|
|
|
gn = Targ_GetNode(cp);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* 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);
|
|
|
|
|
|
|
|
DEBUG0(SUFF, "\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));
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Break the result into a vector of strings whose nodes we can find, then
|
|
|
|
* add those nodes to the members list.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2021-01-14 01:24:34 +00:00
|
|
|
* Unfortunately, we can't use Str_Words because it doesn't understand about
|
2021-06-25 18:16:24 +00:00
|
|
|
* variable expressions with spaces in them.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
ExpandChildrenRegular(char *cp, GNode *pgn, GNodeList *members)
|
|
|
|
{
|
|
|
|
char *start;
|
|
|
|
|
|
|
|
pp_skip_hspace(&cp);
|
|
|
|
start = cp;
|
|
|
|
while (*cp != '\0') {
|
2012-06-08 21:57:36 +00:00
|
|
|
if (*cp == ' ' || *cp == '\t') {
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2012-06-08 21:57:36 +00:00
|
|
|
} else if (*cp == '$') {
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Skip over the variable expression. */
|
|
|
|
const char *nested_p = cp;
|
|
|
|
FStr junk;
|
|
|
|
|
2021-06-25 18:16:24 +00:00
|
|
|
(void)Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY, &junk);
|
2021-01-14 01:24:34 +00:00
|
|
|
/* TODO: handle errors */
|
|
|
|
if (junk.str == var_Error) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-11-07 19:39:21 +00:00
|
|
|
"Malformed variable expression at \"%s\"",
|
|
|
|
cp);
|
2021-01-14 01:24:34 +00:00
|
|
|
cp++;
|
|
|
|
} else {
|
|
|
|
cp += nested_p - cp;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
FStr_Done(&junk);
|
2020-11-20 03:54:37 +00:00
|
|
|
} else if (cp[0] == '\\' && cp[1] != '\0') {
|
2021-01-14 01:24:34 +00:00
|
|
|
/* 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;
|
2020-11-07 19:39:21 +00:00
|
|
|
} else {
|
2021-01-14 01:24:34 +00:00
|
|
|
cp++;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (cp != start) {
|
2012-06-08 21:57:36 +00:00
|
|
|
/*
|
|
|
|
* Stuff left over -- add it to the list too
|
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
GNode *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
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* parent's unmade counter is decremented, but other nodes may be added.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* cln Child to examine
|
|
|
|
* pgn Parent node being processed
|
|
|
|
*/
|
2012-06-08 21:57:36 +00:00
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
ExpandChildren(GNodeListNode *cln, GNode *pgn)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
GNode *cgn = cln->datum;
|
|
|
|
char *cp; /* Expanded value */
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +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;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (cgn->type & OP_WAIT)
|
|
|
|
/* Ignore these (& OP_PHONY ?) */
|
|
|
|
return;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2021-01-14 01:24:34 +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.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
if (strchr(cgn->name, '$') == NULL) {
|
|
|
|
ExpandWildcards(cln, pgn);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG1(SUFF, "Expanding \"%s\"...", cgn->name);
|
2021-06-25 18:16:24 +00:00
|
|
|
(void)Var_Subst(cgn->name, pgn, VARE_UNDEFERR, &cp);
|
2021-01-14 01:24:34 +00:00
|
|
|
/* TODO: handle errors */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
{
|
|
|
|
GNodeList members = LST_INIT;
|
|
|
|
|
|
|
|
if (cgn->type & OP_ARCHV) {
|
|
|
|
/*
|
2021-02-11 01:51:11 +00:00
|
|
|
* Node was an 'archive(member)' target, so
|
2021-01-14 01:24:34 +00:00
|
|
|
* call on the Arch module to find the nodes for us,
|
2021-02-11 01:51:11 +00:00
|
|
|
* expanding variables in the parent's scope.
|
2021-01-14 01:24:34 +00:00
|
|
|
*/
|
|
|
|
char *p = cp;
|
|
|
|
(void)Arch_ParseArchive(&p, &members, pgn);
|
|
|
|
} else {
|
|
|
|
ExpandChildrenRegular(cp, pgn, &members);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Add all elements of the members list to the parent node.
|
|
|
|
*/
|
|
|
|
while (!Lst_IsEmpty(&members)) {
|
|
|
|
GNode *gn = Lst_Dequeue(&members);
|
|
|
|
|
|
|
|
DEBUG1(SUFF, "%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);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
free(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG0(SUFF, "\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +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);
|
|
|
|
Lst_Remove(&cgn->parents, Lst_FindDatum(&cgn->parents, pgn));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ExpandAllChildren(GNode *gn)
|
|
|
|
{
|
|
|
|
GNodeListNode *ln, *nln;
|
|
|
|
|
|
|
|
for (ln = gn->children.first; ln != NULL; ln = nln) {
|
|
|
|
nln = ln->next;
|
|
|
|
ExpandChildren(ln, gn);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +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 *
|
2021-01-14 01:24:34 +00:00
|
|
|
Suff_FindPath(GNode *gn)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
DEBUG1(SUFF, "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) {
|
|
|
|
DEBUG1(SUFF, "suffix is \"%s\"...\n", suff->name);
|
|
|
|
return suff->searchPath;
|
|
|
|
} else {
|
|
|
|
DEBUG0(SUFF, "\n");
|
|
|
|
return &dirSearchPath; /* Use default search path */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply a transformation rule, given the source and target nodes and
|
2020-09-05 16:11:04 +00:00
|
|
|
* 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:
|
2021-06-25 18:16:24 +00:00
|
|
|
* true if successful, false if not.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-06-25 18:16:24 +00:00
|
|
|
static bool
|
2021-01-14 01:24:34 +00:00
|
|
|
ApplyTransform(GNode *tgn, GNode *sgn, Suffix *tsuff, Suffix *ssuff)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
/* This can happen when linking an OP_MEMBER and OP_ARCHV node. */
|
2021-01-14 01:24:34 +00:00
|
|
|
if (gn == NULL)
|
2021-06-25 18:16:24 +00:00
|
|
|
return false;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG3(SUFF, "\tapplying %s -> %s to \"%s\"\n",
|
|
|
|
ssuff->name, tsuff->name, tgn->name);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Record last child; Make_HandleUse may add child nodes. */
|
|
|
|
ln = tgn->children.last;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Apply the rule. */
|
|
|
|
Make_HandleUse(gn, tgn);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-06-25 18:16:24 +00:00
|
|
|
return true;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ExpandMember(GNode *gn, const char *eoarch, GNode *mem, Suffix *memSuff)
|
|
|
|
{
|
|
|
|
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;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (ln != NULL) {
|
|
|
|
/* Got one -- apply it */
|
|
|
|
Suffix *suff = ln->datum;
|
|
|
|
if (!ApplyTransform(gn, mem, suff, memSuff)) {
|
|
|
|
DEBUG2(SUFF, "\tNo transformation from %s -> %s\n",
|
|
|
|
memSuff->name, suff->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FindDeps(GNode *, CandidateSearcher *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2021-01-14 01:24:34 +00:00
|
|
|
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 */
|
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* The node is an archive(member) pair. so we must find a
|
|
|
|
* suffix for both of them.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
eoarch = strchr(gn->name, '(');
|
|
|
|
eoname = strchr(eoarch, ')');
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +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
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
*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. */
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, PREFIX, GNode_VarPrefix(mem));
|
|
|
|
Var_Set(gn, TARGET, GNode_VarTarget(mem));
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
memSuff = mem->suffix;
|
|
|
|
if (memSuff == NULL) { /* Didn't know what it was. */
|
|
|
|
DEBUG0(SUFF, "using null suffix\n");
|
|
|
|
memSuff = nullSuff;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Set the other two local variables required for this target. */
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, MEMBER, name);
|
|
|
|
Var_Set(gn, ARCHIVE, gn->name);
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Set $@ for compatibility with other makes. */
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, TARGET, gn->name);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* Replace the opening and closing parens now we've no need of the
|
|
|
|
* separate pieces.
|
2020-11-07 19:39:21 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
*eoarch = '(';
|
|
|
|
*eoname = ')';
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +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-07 19:39:21 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
FindDepsLib(GNode *gn)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *suff = FindSuffixByName(LIBSUFF);
|
|
|
|
if (suff != NULL) {
|
|
|
|
Suffix_Reassign(&gn->suffix, suff);
|
|
|
|
Arch_FindLib(gn, suff->searchPath);
|
|
|
|
} else {
|
|
|
|
Suffix_Unassign(&gn->suffix);
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, TARGET, gn->name);
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +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.
|
|
|
|
*/
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, PREFIX, "");
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static void
|
|
|
|
FindDepsRegularKnown(const char *name, size_t nameLen, GNode *gn,
|
|
|
|
CandidateList *srcs, CandidateList *targs)
|
|
|
|
{
|
|
|
|
SuffixListNode *ln;
|
|
|
|
Candidate *targ;
|
|
|
|
char *pref;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
for (ln = sufflist.first; ln != NULL; ln = ln->next) {
|
|
|
|
Suffix *suff = ln->datum;
|
|
|
|
if (!Suffix_IsSuffix(suff, nameLen, name + nameLen))
|
|
|
|
continue;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
pref = bmake_strldup(name, (size_t)(nameLen - suff->nameLen));
|
|
|
|
targ = Candidate_New(bmake_strdup(gn->name), pref, suff, NULL,
|
|
|
|
gn);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateList_AddCandidatesFor(srcs, targ);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Record the target so we can nuke it. */
|
|
|
|
Lst_Append(targs, targ);
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
FindDepsRegularUnknown(GNode *gn, const char *sopref,
|
|
|
|
CandidateList *srcs, CandidateList *targs)
|
2020-11-07 19:39:21 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Candidate *targ;
|
|
|
|
|
|
|
|
if (!Lst_IsEmpty(targs) || nullSuff == NULL)
|
|
|
|
return;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG1(SUFF, "\tNo known suffix on %s. Using .NULL suffix\n", gn->name);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
targ = Candidate_New(bmake_strdup(gn->name), bmake_strdup(sopref),
|
|
|
|
nullSuff, NULL, gn);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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.
|
2020-11-07 19:39:21 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
if (Lst_IsEmpty(&gn->commands))
|
|
|
|
CandidateList_AddCandidatesFor(srcs, targ);
|
|
|
|
else {
|
|
|
|
DEBUG0(SUFF, "not ");
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG0(SUFF, "adding suffix rules\n");
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_Append(targs, targ);
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
free(gn->path);
|
|
|
|
gn->path = Dir_FindFile(gn->name,
|
|
|
|
(targ == NULL ? &dirSearchPath :
|
|
|
|
targ->suff->searchPath));
|
|
|
|
if (gn->path == NULL)
|
|
|
|
return;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, TARGET, gn->path);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix_Reassign(&gn->suffix, targ->suff);
|
|
|
|
|
|
|
|
savec = gn->path[savep];
|
|
|
|
gn->path[savep] = '\0';
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, PREFIX, str_basename(gn->path));
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
gn->path[savep] = savec;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The .PREFIX gets the full path if the target has no
|
|
|
|
* known suffix.
|
|
|
|
*/
|
|
|
|
Suffix_Unassign(&gn->suffix);
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, PREFIX, str_basename(gn->path));
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +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
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
const char *name = gn->name;
|
|
|
|
size_t nameLen = strlen(name);
|
|
|
|
|
|
|
|
#ifdef DEBUG_SRC
|
|
|
|
DEBUG1(SUFF, "FindDepsRegular \"%s\"\n", gn->name);
|
|
|
|
#endif
|
2012-06-08 21:57:36 +00:00
|
|
|
|
1996-10-06 15:57:15 +00:00
|
|
|
/*
|
2021-01-14 01:24:34 +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.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
bottom = NULL;
|
|
|
|
targ = NULL;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (!(gn->type & OP_PHONY)) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2021-01-14 01:24:34 +00:00
|
|
|
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, TARGET, GNode_Path(gn));
|
|
|
|
Var_Set(gn, PREFIX, targ != NULL ? targ->prefix : gn->name);
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targ == NULL) {
|
|
|
|
DEBUG1(SUFF, "\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.
|
|
|
|
*/
|
2021-12-18 07:27:22 +00:00
|
|
|
if (targ->suff->library)
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
if (bottom == NULL) {
|
|
|
|
/* No idea from where it can come -- return now. */
|
|
|
|
goto sfnd_abort;
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-01-14 01:24:34 +00:00
|
|
|
* 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.
|
1996-10-06 15:57:15 +00:00
|
|
|
*/
|
2021-01-14 01:24:34 +00:00
|
|
|
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;
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(targ->node, PREFIX, targ->prefix);
|
|
|
|
Var_Set(targ->node, TARGET, targ->node->name);
|
2021-01-14 01:24:34 +00:00
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix_Reassign(&gn->suffix, src->suff);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Nuke the transformation path and the candidates left over in the
|
|
|
|
* two lists.
|
|
|
|
*/
|
1996-10-06 15:57:15 +00:00
|
|
|
sfnd_return:
|
2021-01-14 01:24:34 +00:00
|
|
|
if (bottom != NULL)
|
|
|
|
CandidateSearcher_AddIfNew(cs, bottom);
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
while (RemoveCandidate(&srcs) || RemoveCandidate(&targs))
|
|
|
|
continue;
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateSearcher_MoveAll(cs, &srcs);
|
|
|
|
CandidateSearcher_MoveAll(cs, &targs);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
static void
|
|
|
|
CandidateSearcher_CleanUp(CandidateSearcher *cs)
|
|
|
|
{
|
|
|
|
while (RemoveCandidate(&cs->list))
|
|
|
|
continue;
|
|
|
|
assert(Lst_IsEmpty(&cs->list));
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find implicit sources for the target.
|
1996-10-06 15:57:15 +00:00
|
|
|
*
|
2021-01-14 01:24:34 +00:00
|
|
|
* Nodes are added to the graph as children of 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
|
2021-01-14 01:24:34 +00:00
|
|
|
* graph, which may pass through nonexistent targets, to an existing target.
|
2020-09-05 16:11:04 +00:00
|
|
|
* 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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateSearcher cs;
|
|
|
|
|
|
|
|
CandidateSearcher_Init(&cs);
|
|
|
|
|
|
|
|
FindDeps(gn, &cs);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
CandidateSearcher_CleanUp(&cs);
|
|
|
|
CandidateSearcher_Done(&cs);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-01-14 01:24:34 +00:00
|
|
|
FindDeps(GNode *gn, CandidateSearcher *cs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
if (gn->type & OP_DEPS_FOUND)
|
|
|
|
return;
|
|
|
|
gn->type |= OP_DEPS_FOUND;
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/* Make sure we have these set, may get revised below. */
|
2021-02-11 01:51:11 +00:00
|
|
|
Var_Set(gn, TARGET, GNode_Path(gn));
|
|
|
|
Var_Set(gn, PREFIX, gn->name);
|
2013-05-20 22:35:32 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
DEBUG1(SUFF, "SuffFindDeps \"%s\"\n", gn->name);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (gn->type & OP_ARCHV)
|
|
|
|
FindDepsArchive(gn, cs);
|
|
|
|
else if (gn->type & OP_LIB)
|
|
|
|
FindDepsLib(gn);
|
|
|
|
else
|
|
|
|
FindDepsRegular(gn, cs);
|
1996-10-06 15:57:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
/*
|
|
|
|
* Define which suffix is the null suffix.
|
2020-09-05 16:11:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
Suffix *suff = FindSuffixByName(name);
|
|
|
|
if (suff == NULL) {
|
|
|
|
Parse_Error(PARSE_WARNING,
|
2021-12-18 07:27:22 +00:00
|
|
|
"Desired null suffix %s not defined",
|
2020-11-07 19:39:21 +00:00
|
|
|
name);
|
2021-01-14 01:24:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
if (nullSuff != NULL)
|
2021-12-18 07:27:22 +00:00
|
|
|
nullSuff->isNull = false;
|
|
|
|
suff->isNull = true;
|
2021-01-14 01:24:34 +00:00
|
|
|
/* XXX: Here's where the transformation mangling would take place. */
|
|
|
|
nullSuff = 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
|
|
|
{
|
2021-01-14 01:24:34 +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.
|
|
|
|
*/
|
|
|
|
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
|
2021-01-14 01:24:34 +00:00
|
|
|
Lst_DoneCall(&sufflist, SuffFree);
|
|
|
|
Lst_DoneCall(&suffClean, SuffFree);
|
|
|
|
if (nullSuff != NULL)
|
|
|
|
SuffFree(nullSuff);
|
|
|
|
Lst_Done(&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
|
2021-12-18 07:27:22 +00:00
|
|
|
PrintSuffNames(const char *prefix, const SuffixList *suffs)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
SuffixListNode *ln;
|
2016-09-08 23:49:33 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("#\t%s: ", prefix);
|
|
|
|
for (ln = suffs->first; ln != NULL; ln = ln->next) {
|
2021-12-18 07:27:22 +00:00
|
|
|
const Suffix *suff = ln->datum;
|
2021-01-14 01:24:34 +00:00
|
|
|
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
|
2021-12-18 07:27:22 +00:00
|
|
|
Suffix_Print(const Suffix *suff)
|
1996-10-06 15:57:15 +00:00
|
|
|
{
|
2021-12-18 07:27:22 +00:00
|
|
|
Buffer buf;
|
|
|
|
|
|
|
|
Buf_InitSize(&buf, 16);
|
|
|
|
Buf_AddFlag(&buf, suff->include, "SUFF_INCLUDE");
|
|
|
|
Buf_AddFlag(&buf, suff->library, "SUFF_LIBRARY");
|
|
|
|
Buf_AddFlag(&buf, suff->isNull, "SUFF_NULL");
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("# \"%s\" (num %d, ref %d)",
|
|
|
|
suff->name, suff->sNum, suff->refCount);
|
2021-12-18 07:27:22 +00:00
|
|
|
if (buf.len > 0)
|
|
|
|
debug_printf(" (%s)", buf.data);
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("\n");
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
Buf_Done(&buf);
|
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
PrintSuffNames("To", &suff->parents);
|
|
|
|
PrintSuffNames("From", &suff->children);
|
2020-11-07 19:39:21 +00:00
|
|
|
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("#\tSearch Path: ");
|
|
|
|
SearchPath_Print(suff->searchPath);
|
|
|
|
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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("%-16s:", t->name);
|
|
|
|
Targ_PrintType(t->type);
|
|
|
|
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
|
|
|
{
|
2021-01-14 01:24:34 +00:00
|
|
|
debug_printf("#*** Suffixes:\n");
|
|
|
|
{
|
|
|
|
SuffixListNode *ln;
|
|
|
|
for (ln = sufflist.first; ln != NULL; ln = ln->next)
|
|
|
|
Suffix_Print(ln->datum);
|
|
|
|
}
|
1996-10-06 15:57:15 +00:00
|
|
|
|
2021-01-14 01:24:34 +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
|
|
|
}
|
2021-12-18 07:27:22 +00:00
|
|
|
|
|
|
|
const char *
|
|
|
|
Suff_NamesStr(void)
|
|
|
|
{
|
|
|
|
Buffer buf;
|
|
|
|
SuffixListNode *ln;
|
|
|
|
Suffix *suff;
|
|
|
|
|
|
|
|
Buf_InitSize(&buf, 16);
|
|
|
|
for (ln = sufflist.first; ln != NULL; ln = ln->next) {
|
|
|
|
suff = ln->datum;
|
|
|
|
if (ln != sufflist.first)
|
|
|
|
Buf_AddByte(&buf, ' ');
|
|
|
|
Buf_AddStr(&buf, suff->name);
|
|
|
|
}
|
|
|
|
return Buf_DoneData(&buf);
|
|
|
|
}
|