2020-11-07 19:39:21 +00:00
|
|
|
/* $NetBSD: targ.c,v 1.126 2020/10/30 07:19:30 rillig Exp $ */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. 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. 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* targ.c --
|
|
|
|
* Functions for maintaining the Lst allTargets. Target nodes are
|
2020-09-05 16:11:04 +00:00
|
|
|
* kept in two structures: a Lst and a hash table.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* Interface:
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_Init Initialization procedure.
|
|
|
|
*
|
|
|
|
* Targ_End Clean up the module
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_List Return the list of all targets so far.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_NewGN Create a new GNode for the passed target
|
|
|
|
* (string). The node is *not* placed in the
|
|
|
|
* hash table, though all its fields are
|
|
|
|
* initialized.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_FindNode Find the node, or return NULL.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_GetNode Find the node, or create it.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_NewInternalNode
|
|
|
|
* Create an internal node.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_FindList Given a list of names, find nodes for all
|
|
|
|
* of them, creating them as necessary.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_Ignore Return TRUE if errors should be ignored when
|
|
|
|
* creating the given target.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_Silent Return TRUE if we should be silent when
|
|
|
|
* creating the given target.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_Precious Return TRUE if the target is precious and
|
|
|
|
* should not be removed if we are interrupted.
|
|
|
|
*
|
|
|
|
* Targ_Propagate Propagate information between related nodes.
|
|
|
|
* Should be called after the makefiles are parsed
|
|
|
|
* but before any action is taken.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* Debugging:
|
2020-11-07 19:39:21 +00:00
|
|
|
* Targ_PrintGraph
|
|
|
|
* Print out the entire graphm all variables and
|
|
|
|
* statistics for the directory cache. Should print
|
|
|
|
* something for suffixes, too, but...
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "make.h"
|
|
|
|
#include "dir.h"
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
|
|
|
|
MAKE_RCSID("$NetBSD: targ.c,v 1.126 2020/10/30 07:19:30 rillig Exp $");
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static GNodeList *allTargets; /* the list of all targets found so far */
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2020-11-07 19:39:21 +00:00
|
|
|
static GNodeList *allGNs; /* List of all the GNodes */
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
2020-11-07 19:39:21 +00:00
|
|
|
static HashTable targets; /* a hash table of same */
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
#ifdef CLEANUP
|
|
|
|
static void TargFreeGN(void *);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
Targ_Init(void)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
allTargets = Lst_New();
|
|
|
|
HashTable_Init(&targets);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Targ_End(void)
|
|
|
|
{
|
2020-09-05 16:11:04 +00:00
|
|
|
Targ_Stats();
|
2012-06-08 21:57:36 +00:00
|
|
|
#ifdef CLEANUP
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(allTargets);
|
|
|
|
if (allGNs != NULL)
|
2012-06-08 21:57:36 +00:00
|
|
|
Lst_Destroy(allGNs, TargFreeGN);
|
2020-11-07 19:39:21 +00:00
|
|
|
HashTable_Done(&targets);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
void
|
|
|
|
Targ_Stats(void)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
HashTable_DebugStats(&targets, "targets");
|
2020-09-05 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the list of all targets. */
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeList *
|
2012-06-08 21:57:36 +00:00
|
|
|
Targ_List(void)
|
|
|
|
{
|
|
|
|
return allTargets;
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Create and initialize a new graph node. The gnode is added to the list of
|
|
|
|
* all gnodes.
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
|
|
|
* Input:
|
2020-11-07 19:39:21 +00:00
|
|
|
* name the name of the node, such as "clean", "src.c", ".END"
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
|
|
|
GNode *
|
|
|
|
Targ_NewGN(const char *name)
|
|
|
|
{
|
|
|
|
GNode *gn;
|
|
|
|
|
|
|
|
gn = bmake_malloc(sizeof(GNode));
|
|
|
|
gn->name = bmake_strdup(name);
|
|
|
|
gn->uname = NULL;
|
|
|
|
gn->path = NULL;
|
2020-09-05 16:11:04 +00:00
|
|
|
gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
|
2020-11-07 19:39:21 +00:00
|
|
|
gn->unmade = 0;
|
2012-06-08 21:57:36 +00:00
|
|
|
gn->unmade_cohorts = 0;
|
2020-11-07 19:39:21 +00:00
|
|
|
gn->cohort_num[0] = '\0';
|
|
|
|
gn->centurion = NULL;
|
|
|
|
gn->made = UNMADE;
|
|
|
|
gn->flags = 0;
|
|
|
|
gn->checked_seqno = 0;
|
|
|
|
gn->mtime = 0;
|
|
|
|
gn->youngestChild = NULL;
|
|
|
|
gn->implicitParents = Lst_New();
|
|
|
|
gn->cohorts = Lst_New();
|
|
|
|
gn->parents = Lst_New();
|
|
|
|
gn->children = Lst_New();
|
|
|
|
gn->order_pred = Lst_New();
|
|
|
|
gn->order_succ = Lst_New();
|
|
|
|
HashTable_Init(&gn->context);
|
|
|
|
gn->commands = Lst_New();
|
|
|
|
gn->suffix = NULL;
|
|
|
|
gn->fname = NULL;
|
|
|
|
gn->lineno = 0;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
#ifdef CLEANUP
|
|
|
|
if (allGNs == NULL)
|
2020-11-07 19:39:21 +00:00
|
|
|
allGNs = Lst_New();
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(allGNs, gn);
|
2012-06-08 21:57:36 +00:00
|
|
|
#endif
|
|
|
|
|
2020-07-08 18:32:15 +00:00
|
|
|
return gn;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CLEANUP
|
|
|
|
static void
|
|
|
|
TargFreeGN(void *gnp)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNode *gn = gnp;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
free(gn->name);
|
2016-03-11 00:37:02 +00:00
|
|
|
free(gn->uname);
|
|
|
|
free(gn->path);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(gn->implicitParents);
|
|
|
|
Lst_Free(gn->cohorts);
|
|
|
|
Lst_Free(gn->parents);
|
|
|
|
Lst_Free(gn->children);
|
|
|
|
Lst_Free(gn->order_succ);
|
|
|
|
Lst_Free(gn->order_pred);
|
2020-11-07 19:39:21 +00:00
|
|
|
HashTable_Done(&gn->context);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Free(gn->commands);
|
|
|
|
|
|
|
|
/* XXX: does gn->suffix need to be freed? It is reference-counted. */
|
|
|
|
|
2012-06-08 21:57:36 +00:00
|
|
|
free(gn);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Get the existing global node, or return NULL. */
|
2012-06-08 21:57:36 +00:00
|
|
|
GNode *
|
2020-11-07 19:39:21 +00:00
|
|
|
Targ_FindNode(const char *name)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
return HashTable_FindValue(&targets, name);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Get the existing global node, or create it. */
|
|
|
|
GNode *
|
|
|
|
Targ_GetNode(const char *name)
|
|
|
|
{
|
|
|
|
Boolean isNew;
|
|
|
|
HashEntry *he = HashTable_CreateEntry(&targets, name, &isNew);
|
|
|
|
if (!isNew)
|
|
|
|
return HashEntry_Get(he);
|
|
|
|
|
|
|
|
{
|
|
|
|
GNode *gn = Targ_NewInternalNode(name);
|
|
|
|
HashEntry_Set(he, gn);
|
|
|
|
return gn;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Create a node, register it in .ALLTARGETS but don't store it in the
|
|
|
|
* table of global nodes. This means it cannot be found by name.
|
|
|
|
*
|
|
|
|
* This is used for internal nodes, such as cohorts or .WAIT nodes. */
|
|
|
|
GNode *
|
|
|
|
Targ_NewInternalNode(const char *name)
|
|
|
|
{
|
|
|
|
GNode *gn = Targ_NewGN(name);
|
2012-06-08 21:57:36 +00:00
|
|
|
Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
|
2020-09-05 16:11:04 +00:00
|
|
|
Lst_Append(allTargets, gn);
|
2012-06-08 21:57:36 +00:00
|
|
|
if (doing_depend)
|
|
|
|
gn->flags |= FROM_DEPEND;
|
|
|
|
return gn;
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Return the .END node, which contains the commands to be executed when
|
|
|
|
* everything else is done. */
|
|
|
|
GNode *Targ_GetEndNode(void)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Save the node locally to avoid having to search for it all the time. */
|
|
|
|
static GNode *endNode = NULL;
|
|
|
|
if (endNode == NULL) {
|
|
|
|
endNode = Targ_GetNode(".END");
|
|
|
|
endNode->type = OP_SPECIAL;
|
|
|
|
}
|
|
|
|
return endNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the named nodes, creating them as necessary. */
|
|
|
|
GNodeList *
|
|
|
|
Targ_FindList(StringList *names)
|
|
|
|
{
|
|
|
|
StringListNode *ln;
|
|
|
|
GNodeList *nodes = Lst_New();
|
|
|
|
for (ln = names->first; ln != NULL; ln = ln->next) {
|
|
|
|
const char *name = ln->datum;
|
|
|
|
GNode *gn = Targ_GetNode(name);
|
|
|
|
Lst_Append(nodes, gn);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
2020-07-08 18:32:15 +00:00
|
|
|
return nodes;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Return true if should ignore errors when creating gn. */
|
2012-06-08 21:57:36 +00:00
|
|
|
Boolean
|
|
|
|
Targ_Ignore(GNode *gn)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
return opts.ignoreErrors || gn->type & OP_IGNORE;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Return true if be silent when creating gn. */
|
2012-06-08 21:57:36 +00:00
|
|
|
Boolean
|
|
|
|
Targ_Silent(GNode *gn)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
return opts.beSilent || gn->type & OP_SILENT;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* See if the given target is precious. */
|
2012-06-08 21:57:36 +00:00
|
|
|
Boolean
|
|
|
|
Targ_Precious(GNode *gn)
|
|
|
|
{
|
2020-09-05 16:11:04 +00:00
|
|
|
return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************* DEBUG INFO PRINTING ****************/
|
|
|
|
|
|
|
|
static GNode *mainTarg; /* the main target, as set by Targ_SetMain */
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
/* Set our idea of the main target we'll be creating. Used for debugging
|
|
|
|
* output. */
|
2012-06-08 21:57:36 +00:00
|
|
|
void
|
|
|
|
Targ_SetMain(GNode *gn)
|
|
|
|
{
|
|
|
|
mainTarg = gn;
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
PrintNodeNames(GNodeList *gnodes)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeListNode *node;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (node = gnodes->first; node != NULL; node = node->next) {
|
|
|
|
GNode *gn = node->datum;
|
|
|
|
debug_printf(" %s%s", gn->name, gn->cohort_num);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static void
|
|
|
|
PrintNodeNamesLine(const char *label, GNodeList *gnodes)
|
|
|
|
{
|
|
|
|
if (Lst_IsEmpty(gnodes))
|
|
|
|
return;
|
|
|
|
debug_printf("# %s:", label);
|
|
|
|
PrintNodeNames(gnodes);
|
|
|
|
debug_printf("\n");
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
void
|
|
|
|
Targ_PrintCmds(GNode *gn)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
StringListNode *ln;
|
|
|
|
for (ln = gn->commands->first; ln != NULL; ln = ln->next) {
|
|
|
|
const char *cmd = ln->datum;
|
|
|
|
debug_printf("\t%s\n", cmd);
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Format a modification time in some reasonable way and return it.
|
|
|
|
* The time is placed in a static area, so it is overwritten with each call. */
|
2012-06-08 21:57:36 +00:00
|
|
|
char *
|
|
|
|
Targ_FmtTime(time_t tm)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
struct tm *parts;
|
|
|
|
static char buf[128];
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
parts = localtime(&tm);
|
|
|
|
(void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
|
2020-07-08 18:32:15 +00:00
|
|
|
return buf;
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Print out a type field giving only those attributes the user can set. */
|
2012-06-08 21:57:36 +00:00
|
|
|
void
|
|
|
|
Targ_PrintType(int type)
|
|
|
|
{
|
|
|
|
int tbit;
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#define PRINTBIT(attr) case CONCAT(OP_,attr): debug_printf(" ." #attr); break
|
|
|
|
#define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))debug_printf(" ." #attr); break
|
2012-06-08 21:57:36 +00:00
|
|
|
|
|
|
|
type &= ~OP_OPMASK;
|
|
|
|
|
|
|
|
while (type) {
|
|
|
|
tbit = 1 << (ffs(type) - 1);
|
|
|
|
type &= ~tbit;
|
|
|
|
|
|
|
|
switch(tbit) {
|
2020-11-07 19:39:21 +00:00
|
|
|
PRINTBIT(OPTIONAL);
|
|
|
|
PRINTBIT(USE);
|
|
|
|
PRINTBIT(EXEC);
|
|
|
|
PRINTBIT(IGNORE);
|
|
|
|
PRINTBIT(PRECIOUS);
|
|
|
|
PRINTBIT(SILENT);
|
|
|
|
PRINTBIT(MAKE);
|
|
|
|
PRINTBIT(JOIN);
|
|
|
|
PRINTBIT(INVISIBLE);
|
|
|
|
PRINTBIT(NOTMAIN);
|
|
|
|
PRINTDBIT(LIB);
|
2012-06-08 21:57:36 +00:00
|
|
|
/*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
|
2020-11-07 19:39:21 +00:00
|
|
|
case OP_MEMBER: if (DEBUG(TARG))debug_printf(" .MEMBER"); break;
|
|
|
|
PRINTDBIT(ARCHV);
|
|
|
|
PRINTDBIT(MADE);
|
|
|
|
PRINTDBIT(PHONY);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2020-09-05 16:11:04 +00:00
|
|
|
made_name(GNodeMade made)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
|
|
|
switch (made) {
|
|
|
|
case UNMADE: return "unmade";
|
|
|
|
case DEFERRED: return "deferred";
|
|
|
|
case REQUESTED: return "requested";
|
|
|
|
case BEINGMADE: return "being made";
|
|
|
|
case MADE: return "made";
|
|
|
|
case UPTODATE: return "up-to-date";
|
|
|
|
case ERROR: return "error when made";
|
|
|
|
case ABORTED: return "aborted";
|
|
|
|
default: return "unknown enum_made value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
static const char *
|
|
|
|
GNode_OpName(const GNode *gn)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
switch (gn->type & OP_OPMASK) {
|
|
|
|
case OP_DEPENDS:
|
|
|
|
return ":";
|
|
|
|
case OP_FORCE:
|
|
|
|
return "!";
|
|
|
|
case OP_DOUBLEDEP:
|
|
|
|
return "::";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
/* Print the contents of a node. */
|
|
|
|
void
|
|
|
|
Targ_PrintNode(GNode *gn, int pass)
|
|
|
|
{
|
|
|
|
debug_printf("# %s%s", gn->name, gn->cohort_num);
|
|
|
|
GNode_FprintDetails(opts.debug_file, ", ", gn, "\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
if (gn->flags == 0)
|
2020-11-07 19:39:21 +00:00
|
|
|
return;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (GNode_IsTarget(gn)) {
|
|
|
|
debug_printf("#\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
if (gn == mainTarg) {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# *** MAIN TARGET ***\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
if (pass >= 2) {
|
|
|
|
if (gn->unmade) {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# %d unmade children\n", gn->unmade);
|
2012-06-08 21:57:36 +00:00
|
|
|
} else {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# No unmade children\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
if (! (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
|
|
|
|
if (gn->mtime != 0) {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# last modified %s: %s\n",
|
|
|
|
Targ_FmtTime(gn->mtime),
|
|
|
|
made_name(gn->made));
|
2012-06-08 21:57:36 +00:00
|
|
|
} else if (gn->made != UNMADE) {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# non-existent (maybe): %s\n",
|
|
|
|
made_name(gn->made));
|
2012-06-08 21:57:36 +00:00
|
|
|
} else {
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# unmade\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
PrintNodeNamesLine("implicit parents", gn->implicitParents);
|
2012-06-08 21:57:36 +00:00
|
|
|
} else {
|
|
|
|
if (gn->unmade)
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("# %d unmade children\n", gn->unmade);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
2020-11-07 19:39:21 +00:00
|
|
|
PrintNodeNamesLine("parents", gn->parents);
|
|
|
|
PrintNodeNamesLine("order_pred", gn->order_pred);
|
|
|
|
PrintNodeNamesLine("order_succ", gn->order_succ);
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("%-16s%s", gn->name, GNode_OpName(gn));
|
2012-06-08 21:57:36 +00:00
|
|
|
Targ_PrintType(gn->type);
|
2020-11-07 19:39:21 +00:00
|
|
|
PrintNodeNames(gn->children);
|
|
|
|
debug_printf("\n");
|
|
|
|
Targ_PrintCmds(gn);
|
|
|
|
debug_printf("\n\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
if (gn->type & OP_DOUBLEDEP) {
|
2020-11-07 19:39:21 +00:00
|
|
|
Targ_PrintNodes(gn->cohorts, pass);
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
void
|
|
|
|
Targ_PrintNodes(GNodeList *gnodes, int pass)
|
|
|
|
{
|
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = gnodes->first; ln != NULL; ln = ln->next)
|
|
|
|
Targ_PrintNode(ln->datum, pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print only those targets that are just a source. */
|
|
|
|
static void
|
|
|
|
PrintOnlySources(void)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeListNode *ln;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = allTargets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
if (GNode_IsTarget(gn))
|
|
|
|
continue;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#\t%s [%s]", gn->name, GNode_Path(gn));
|
|
|
|
Targ_PrintType(gn->type);
|
|
|
|
debug_printf("\n");
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Input:
|
|
|
|
* pass 1 => before processing
|
|
|
|
* 2 => after processing
|
|
|
|
* 3 => after processing, an error occurred
|
2012-06-08 21:57:36 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
Targ_PrintGraph(int pass)
|
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#*** Input graph:\n");
|
|
|
|
Targ_PrintNodes(allTargets, pass);
|
|
|
|
debug_printf("\n\n");
|
|
|
|
debug_printf("#\n# Files that are only sources:\n");
|
|
|
|
PrintOnlySources();
|
|
|
|
debug_printf("#*** Global Variables:\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
Var_Dump(VAR_GLOBAL);
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("#*** Command-line Variables:\n");
|
|
|
|
Var_Dump(VAR_CMDLINE);
|
|
|
|
debug_printf("\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
Dir_PrintDirectories();
|
2020-11-07 19:39:21 +00:00
|
|
|
debug_printf("\n");
|
2012-06-08 21:57:36 +00:00
|
|
|
Suff_PrintAll();
|
|
|
|
}
|
|
|
|
|
2020-09-05 16:11:04 +00:00
|
|
|
/* Propagate some type information to cohort nodes (those from the ::
|
|
|
|
* dependency operator).
|
2012-06-08 21:57:36 +00:00
|
|
|
*
|
2020-09-05 16:11:04 +00:00
|
|
|
* Should be called after the makefiles are parsed but before any action is
|
|
|
|
* taken. */
|
|
|
|
void
|
|
|
|
Targ_Propagate(void)
|
2012-06-08 21:57:36 +00:00
|
|
|
{
|
2020-11-07 19:39:21 +00:00
|
|
|
GNodeListNode *ln, *cln;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (ln = allTargets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
GNodeType type = gn->type;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
if (!(type & OP_DOUBLEDEP))
|
2020-09-05 16:11:04 +00:00
|
|
|
continue;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
for (cln = gn->cohorts->first; cln != NULL; cln = cln->next) {
|
|
|
|
GNode *cohort = cln->datum;
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
cohort->type |= type & ~OP_OPMASK;
|
2020-09-05 16:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 21:57:36 +00:00
|
|
|
}
|