Home | History | Annotate | Line # | Download | only in make
targ.c revision 1.175
      1  1.175    rillig /*	$NetBSD: targ.c,v 1.175 2022/01/07 20:37:25 rillig Exp $	*/
      2    1.5  christos 
      3    1.1       cgd /*
      4   1.10  christos  * Copyright (c) 1988, 1989, 1990, 1993
      5   1.10  christos  *	The Regents of the University of California.  All rights reserved.
      6   1.30       agc  *
      7   1.30       agc  * This code is derived from software contributed to Berkeley by
      8   1.30       agc  * Adam de Boor.
      9   1.30       agc  *
     10   1.30       agc  * Redistribution and use in source and binary forms, with or without
     11   1.30       agc  * modification, are permitted provided that the following conditions
     12   1.30       agc  * are met:
     13   1.30       agc  * 1. Redistributions of source code must retain the above copyright
     14   1.30       agc  *    notice, this list of conditions and the following disclaimer.
     15   1.30       agc  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.30       agc  *    notice, this list of conditions and the following disclaimer in the
     17   1.30       agc  *    documentation and/or other materials provided with the distribution.
     18   1.30       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.30       agc  *    may be used to endorse or promote products derived from this software
     20   1.30       agc  *    without specific prior written permission.
     21   1.30       agc  *
     22   1.30       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.30       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.30       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.30       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.30       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.30       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.30       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.30       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.30       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.30       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.30       agc  * SUCH DAMAGE.
     33   1.30       agc  */
     34   1.30       agc 
     35   1.30       agc /*
     36    1.1       cgd  * Copyright (c) 1989 by Berkeley Softworks
     37    1.1       cgd  * All rights reserved.
     38    1.1       cgd  *
     39    1.1       cgd  * This code is derived from software contributed to Berkeley by
     40    1.1       cgd  * Adam de Boor.
     41    1.1       cgd  *
     42    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     43    1.1       cgd  * modification, are permitted provided that the following conditions
     44    1.1       cgd  * are met:
     45    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     46    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     47    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     48    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     49    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     50    1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     51    1.1       cgd  *    must display the following acknowledgement:
     52    1.1       cgd  *	This product includes software developed by the University of
     53    1.1       cgd  *	California, Berkeley and its contributors.
     54    1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     55    1.1       cgd  *    may be used to endorse or promote products derived from this software
     56    1.1       cgd  *    without specific prior written permission.
     57    1.1       cgd  *
     58    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59    1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60    1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61    1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62    1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63    1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64    1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65    1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66    1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67    1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68    1.1       cgd  * SUCH DAMAGE.
     69    1.1       cgd  */
     70    1.1       cgd 
     71  1.132    rillig /*
     72  1.132    rillig  * Maintaining the targets and sources, which are both implemented as GNode.
     73    1.1       cgd  *
     74    1.1       cgd  * Interface:
     75  1.132    rillig  *	Targ_Init	Initialize the module.
     76    1.1       cgd  *
     77  1.132    rillig  *	Targ_End	Clean up the module.
     78    1.4       jtc  *
     79  1.106    rillig  *	Targ_List	Return the list of all targets so far.
     80   1.12  christos  *
     81  1.175    rillig  *	GNode_New	Create a new GNode with the given name, don't add it
     82  1.175    rillig  *			to allNodes.
     83    1.1       cgd  *
     84  1.106    rillig  *	Targ_FindNode	Find the node, or return NULL.
     85   1.98    rillig  *
     86  1.106    rillig  *	Targ_GetNode	Find the node, or create it.
     87   1.98    rillig  *
     88  1.106    rillig  *	Targ_NewInternalNode
     89  1.106    rillig  *			Create an internal node.
     90    1.1       cgd  *
     91  1.106    rillig  *	Targ_FindList	Given a list of names, find nodes for all
     92  1.106    rillig  *			of them, creating them as necessary.
     93    1.1       cgd  *
     94  1.106    rillig  *	Targ_Propagate	Propagate information between related nodes.
     95  1.106    rillig  *			Should be called after the makefiles are parsed
     96  1.106    rillig  *			but before any action is taken.
     97   1.42       apb  *
     98    1.1       cgd  * Debugging:
     99  1.106    rillig  *	Targ_PrintGraph
    100  1.148    rillig  *			Print out the entire graph, all variables and
    101  1.175    rillig  *			statistics for the directory cache.
    102    1.1       cgd  */
    103    1.1       cgd 
    104  1.111    rillig #include <time.h>
    105   1.28       wiz 
    106  1.111    rillig #include "make.h"
    107  1.111    rillig #include "dir.h"
    108    1.1       cgd 
    109   1.88    rillig /*	"@(#)targ.c	8.2 (Berkeley) 3/19/94"	*/
    110  1.175    rillig MAKE_RCSID("$NetBSD: targ.c,v 1.175 2022/01/07 20:37:25 rillig Exp $");
    111   1.88    rillig 
    112  1.136    rillig /*
    113  1.136    rillig  * All target nodes that appeared on the left-hand side of one of the
    114  1.136    rillig  * dependency operators ':', '::', '!'.
    115  1.136    rillig  */
    116  1.148    rillig static GNodeList allTargets = LST_INIT;
    117  1.133    rillig static HashTable allTargetsByName;
    118  1.130    rillig 
    119   1.18   mycroft #ifdef CLEANUP
    120  1.148    rillig static GNodeList allNodes = LST_INIT;
    121    1.1       cgd 
    122  1.129    rillig static void GNode_Free(void *);
    123   1.18   mycroft #endif
    124    1.4       jtc 
    125    1.1       cgd void
    126   1.28       wiz Targ_Init(void)
    127    1.1       cgd {
    128  1.150    rillig 	HashTable_Init(&allTargetsByName);
    129    1.1       cgd }
    130    1.1       cgd 
    131    1.4       jtc void
    132   1.28       wiz Targ_End(void)
    133    1.4       jtc {
    134  1.150    rillig 	Targ_Stats();
    135   1.18   mycroft #ifdef CLEANUP
    136  1.150    rillig 	Lst_Done(&allTargets);
    137  1.150    rillig 	HashTable_Done(&allTargetsByName);
    138  1.150    rillig 	Lst_DoneCall(&allNodes, GNode_Free);
    139   1.18   mycroft #endif
    140   1.12  christos }
    141   1.12  christos 
    142   1.64       sjg void
    143   1.64       sjg Targ_Stats(void)
    144   1.64       sjg {
    145  1.150    rillig 	HashTable_DebugStats(&allTargetsByName, "targets");
    146   1.64       sjg }
    147   1.64       sjg 
    148  1.132    rillig /*
    149  1.132    rillig  * Return the list of all targets, which are all nodes that appear on the
    150  1.132    rillig  * left-hand side of a dependency declaration such as "target: source".
    151  1.132    rillig  * The returned list does not contain pure sources.
    152  1.132    rillig  */
    153   1.89    rillig GNodeList *
    154   1.28       wiz Targ_List(void)
    155   1.12  christos {
    156  1.150    rillig 	return &allTargets;
    157    1.4       jtc }
    158    1.4       jtc 
    159  1.150    rillig /*
    160  1.150    rillig  * Create a new graph node, but don't register it anywhere.
    161    1.1       cgd  *
    162  1.132    rillig  * Graph nodes that appear on the left-hand side of a dependency line such
    163  1.132    rillig  * as "target: source" are called targets.  XXX: In some cases (like the
    164  1.132    rillig  * .ALLTARGETS variable), all nodes are called targets as well, even if they
    165  1.132    rillig  * never appear on the left-hand side.  This is a mistake.
    166  1.132    rillig  *
    167  1.132    rillig  * Typical names for graph nodes are:
    168  1.132    rillig  *	"src.c" (an ordinary file)
    169  1.132    rillig  *	"clean" (a .PHONY target)
    170  1.132    rillig  *	".END" (a special hook target)
    171  1.132    rillig  *	"-lm" (a library)
    172  1.132    rillig  *	"libc.a(isspace.o)" (an archive member)
    173    1.1       cgd  */
    174    1.1       cgd GNode *
    175  1.128    rillig GNode_New(const char *name)
    176    1.1       cgd {
    177  1.150    rillig 	GNode *gn;
    178    1.1       cgd 
    179  1.150    rillig 	gn = bmake_malloc(sizeof *gn);
    180  1.150    rillig 	gn->name = bmake_strdup(name);
    181  1.150    rillig 	gn->uname = NULL;
    182  1.150    rillig 	gn->path = NULL;
    183  1.152    rillig 	gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : OP_NONE;
    184  1.173    rillig 	memset(&gn->flags, 0, sizeof(gn->flags));
    185  1.150    rillig 	gn->made = UNMADE;
    186  1.150    rillig 	gn->unmade = 0;
    187  1.150    rillig 	gn->mtime = 0;
    188  1.150    rillig 	gn->youngestChild = NULL;
    189  1.150    rillig 	Lst_Init(&gn->implicitParents);
    190  1.150    rillig 	Lst_Init(&gn->parents);
    191  1.150    rillig 	Lst_Init(&gn->children);
    192  1.150    rillig 	Lst_Init(&gn->order_pred);
    193  1.150    rillig 	Lst_Init(&gn->order_succ);
    194  1.150    rillig 	Lst_Init(&gn->cohorts);
    195  1.150    rillig 	gn->cohort_num[0] = '\0';
    196  1.150    rillig 	gn->unmade_cohorts = 0;
    197  1.150    rillig 	gn->centurion = NULL;
    198  1.150    rillig 	gn->checked_seqno = 0;
    199  1.150    rillig 	HashTable_Init(&gn->vars);
    200  1.150    rillig 	Lst_Init(&gn->commands);
    201  1.150    rillig 	gn->suffix = NULL;
    202  1.150    rillig 	gn->fname = NULL;
    203  1.150    rillig 	gn->lineno = 0;
    204    1.1       cgd 
    205   1.18   mycroft #ifdef CLEANUP
    206  1.150    rillig 	Lst_Append(&allNodes, gn);
    207   1.18   mycroft #endif
    208    1.4       jtc 
    209  1.150    rillig 	return gn;
    210    1.1       cgd }
    211    1.1       cgd 
    212   1.18   mycroft #ifdef CLEANUP
    213    1.4       jtc static void
    214  1.129    rillig GNode_Free(void *gnp)
    215    1.4       jtc {
    216  1.150    rillig 	GNode *gn = gnp;
    217    1.4       jtc 
    218  1.150    rillig 	free(gn->name);
    219  1.150    rillig 	free(gn->uname);
    220  1.150    rillig 	free(gn->path);
    221  1.150    rillig 
    222  1.150    rillig 	/* Don't free gn->youngestChild since it is not owned by this node. */
    223  1.150    rillig 
    224  1.150    rillig 	/*
    225  1.150    rillig 	 * In the following lists, only free the list nodes, but not the
    226  1.150    rillig 	 * GNodes in them since these are not owned by this node.
    227  1.150    rillig 	 */
    228  1.150    rillig 	Lst_Done(&gn->implicitParents);
    229  1.150    rillig 	Lst_Done(&gn->parents);
    230  1.150    rillig 	Lst_Done(&gn->children);
    231  1.150    rillig 	Lst_Done(&gn->order_pred);
    232  1.150    rillig 	Lst_Done(&gn->order_succ);
    233  1.150    rillig 	Lst_Done(&gn->cohorts);
    234  1.150    rillig 
    235  1.150    rillig 	/*
    236  1.150    rillig 	 * Do not free the variables themselves, even though they are owned
    237  1.150    rillig 	 * by this node.
    238  1.150    rillig 	 *
    239  1.150    rillig 	 * XXX: For the nodes that represent targets or sources (and not
    240  1.164    rillig 	 * SCOPE_GLOBAL), it should be safe to free the variables as well,
    241  1.150    rillig 	 * since each node manages the memory for all its variables itself.
    242  1.150    rillig 	 *
    243  1.166    rillig 	 * XXX: The GNodes that are only used as variable scopes (SCOPE_CMD,
    244  1.164    rillig 	 * SCOPE_GLOBAL, SCOPE_INTERNAL) are not freed at all (see Var_End,
    245  1.164    rillig 	 * where they are not mentioned).  These might be freed at all, if
    246  1.164    rillig 	 * their variable values are indeed not used anywhere else (see
    247  1.164    rillig 	 * Trace_Init for the only suspicious use).
    248  1.150    rillig 	 */
    249  1.150    rillig 	HashTable_Done(&gn->vars);
    250  1.150    rillig 
    251  1.150    rillig 	/*
    252  1.150    rillig 	 * Do not free the commands themselves, as they may be shared with
    253  1.150    rillig 	 * other nodes.
    254  1.150    rillig 	 */
    255  1.150    rillig 	Lst_Done(&gn->commands);
    256  1.150    rillig 
    257  1.150    rillig 	/*
    258  1.150    rillig 	 * gn->suffix is not owned by this node.
    259  1.150    rillig 	 *
    260  1.150    rillig 	 * XXX: gn->suffix should be unreferenced here.  This requires a
    261  1.150    rillig 	 * thorough check that the reference counting is done correctly in
    262  1.150    rillig 	 * all places, otherwise a suffix might be freed too early.
    263  1.150    rillig 	 */
    264   1.77    rillig 
    265  1.150    rillig 	free(gn);
    266    1.4       jtc }
    267   1.18   mycroft #endif
    268    1.4       jtc 
    269   1.95    rillig /* Get the existing global node, or return NULL. */
    270   1.95    rillig GNode *
    271   1.95    rillig Targ_FindNode(const char *name)
    272   1.95    rillig {
    273  1.150    rillig 	return HashTable_FindValue(&allTargetsByName, name);
    274   1.95    rillig }
    275   1.95    rillig 
    276   1.95    rillig /* Get the existing global node, or create it. */
    277   1.95    rillig GNode *
    278   1.95    rillig Targ_GetNode(const char *name)
    279   1.95    rillig {
    280  1.167    rillig 	bool isNew;
    281  1.150    rillig 	HashEntry *he = HashTable_CreateEntry(&allTargetsByName, name, &isNew);
    282  1.150    rillig 	if (!isNew)
    283  1.150    rillig 		return HashEntry_Get(he);
    284  1.150    rillig 
    285  1.150    rillig 	{
    286  1.150    rillig 		GNode *gn = Targ_NewInternalNode(name);
    287  1.150    rillig 		HashEntry_Set(he, gn);
    288  1.150    rillig 		return gn;
    289  1.150    rillig 	}
    290   1.95    rillig }
    291   1.95    rillig 
    292  1.132    rillig /*
    293  1.132    rillig  * Create a node, register it in .ALLTARGETS but don't store it in the
    294   1.95    rillig  * table of global nodes.  This means it cannot be found by name.
    295   1.95    rillig  *
    296  1.132    rillig  * This is used for internal nodes, such as cohorts or .WAIT nodes.
    297  1.132    rillig  */
    298   1.95    rillig GNode *
    299   1.95    rillig Targ_NewInternalNode(const char *name)
    300   1.95    rillig {
    301  1.150    rillig 	GNode *gn = GNode_New(name);
    302  1.163    rillig 	Global_Append(".ALLTARGETS", name);
    303  1.150    rillig 	Lst_Append(&allTargets, gn);
    304  1.150    rillig 	DEBUG1(TARG, "Adding \"%s\" to all targets.\n", gn->name);
    305  1.150    rillig 	if (doing_depend)
    306  1.173    rillig 		gn->flags.fromDepend = true;
    307  1.150    rillig 	return gn;
    308   1.95    rillig }
    309   1.95    rillig 
    310  1.132    rillig /*
    311  1.132    rillig  * Return the .END node, which contains the commands to be run when
    312  1.132    rillig  * everything else has been made.
    313  1.132    rillig  */
    314  1.156    rillig GNode *
    315  1.156    rillig Targ_GetEndNode(void)
    316   1.90    rillig {
    317  1.150    rillig 	/*
    318  1.150    rillig 	 * Save the node locally to avoid having to search for it all
    319  1.150    rillig 	 * the time.
    320  1.150    rillig 	 */
    321  1.150    rillig 	static GNode *endNode = NULL;
    322  1.150    rillig 
    323  1.150    rillig 	if (endNode == NULL) {
    324  1.150    rillig 		endNode = Targ_GetNode(".END");
    325  1.150    rillig 		endNode->type = OP_SPECIAL;
    326  1.150    rillig 	}
    327  1.150    rillig 	return endNode;
    328   1.90    rillig }
    329   1.90    rillig 
    330  1.149    rillig /* Add the named nodes to the list, creating them as necessary. */
    331  1.147    rillig void
    332  1.149    rillig Targ_FindList(GNodeList *gns, StringList *names)
    333    1.1       cgd {
    334  1.150    rillig 	StringListNode *ln;
    335  1.149    rillig 
    336  1.150    rillig 	for (ln = names->first; ln != NULL; ln = ln->next) {
    337  1.150    rillig 		const char *name = ln->datum;
    338  1.150    rillig 		GNode *gn = Targ_GetNode(name);
    339  1.150    rillig 		Lst_Append(gns, gn);
    340  1.150    rillig 	}
    341    1.1       cgd }
    342    1.1       cgd 
    343  1.132    rillig /*
    344  1.132    rillig  * The main target to be made; only for debugging output.
    345  1.132    rillig  * See mainNode in parse.c for the definitive source.
    346  1.132    rillig  */
    347  1.132    rillig static GNode *mainTarg;
    348   1.77    rillig 
    349  1.132    rillig /* Remember the main target to make; only used for debugging. */
    350    1.1       cgd void
    351   1.28       wiz Targ_SetMain(GNode *gn)
    352    1.1       cgd {
    353  1.150    rillig 	mainTarg = gn;
    354    1.1       cgd }
    355    1.1       cgd 
    356   1.86    rillig static void
    357   1.89    rillig PrintNodeNames(GNodeList *gnodes)
    358    1.1       cgd {
    359  1.150    rillig 	GNodeListNode *ln;
    360   1.38       dsl 
    361  1.150    rillig 	for (ln = gnodes->first; ln != NULL; ln = ln->next) {
    362  1.150    rillig 		GNode *gn = ln->datum;
    363  1.150    rillig 		debug_printf(" %s%s", gn->name, gn->cohort_num);
    364  1.150    rillig 	}
    365   1.85    rillig }
    366   1.38       dsl 
    367   1.85    rillig static void
    368   1.89    rillig PrintNodeNamesLine(const char *label, GNodeList *gnodes)
    369   1.85    rillig {
    370  1.150    rillig 	if (Lst_IsEmpty(gnodes))
    371  1.150    rillig 		return;
    372  1.150    rillig 	debug_printf("# %s:", label);
    373  1.150    rillig 	PrintNodeNames(gnodes);
    374  1.150    rillig 	debug_printf("\n");
    375    1.1       cgd }
    376    1.1       cgd 
    377   1.84    rillig void
    378   1.84    rillig Targ_PrintCmds(GNode *gn)
    379   1.84    rillig {
    380  1.150    rillig 	StringListNode *ln;
    381  1.150    rillig 
    382  1.150    rillig 	for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
    383  1.150    rillig 		const char *cmd = ln->datum;
    384  1.150    rillig 		debug_printf("\t%s\n", cmd);
    385  1.150    rillig 	}
    386   1.84    rillig }
    387   1.84    rillig 
    388  1.150    rillig /*
    389  1.150    rillig  * Format a modification time in some reasonable way and return it.
    390  1.158    rillig  * The formatted time is placed in a static area, so it is overwritten
    391  1.158    rillig  * with each call.
    392  1.150    rillig  */
    393  1.157    rillig const char *
    394   1.28       wiz Targ_FmtTime(time_t tm)
    395    1.1       cgd {
    396  1.150    rillig 	static char buf[128];
    397    1.1       cgd 
    398  1.158    rillig 	struct tm *parts = localtime(&tm);
    399  1.168    rillig 	(void)strftime(buf, sizeof buf, "%H:%M:%S %b %d, %Y", parts);
    400  1.150    rillig 	return buf;
    401    1.1       cgd }
    402   1.10  christos 
    403   1.77    rillig /* Print out a type field giving only those attributes the user can set. */
    404    1.1       cgd void
    405  1.171    rillig Targ_PrintType(GNodeType type)
    406    1.1       cgd {
    407  1.169    rillig 	static const struct {
    408  1.169    rillig 		GNodeType bit;
    409  1.169    rillig 		bool internal;
    410  1.172    rillig 		const char name[10];
    411  1.169    rillig 	} names[] = {
    412  1.169    rillig 		{ OP_MEMBER,	true,	"MEMBER"	},
    413  1.169    rillig 		{ OP_LIB,	true,	"LIB"		},
    414  1.169    rillig 		{ OP_ARCHV,	true,	"ARCHV"		},
    415  1.169    rillig 		{ OP_PHONY,	true,	"PHONY"		},
    416  1.169    rillig 		{ OP_NOTMAIN,	false,	"NOTMAIN"	},
    417  1.169    rillig 		{ OP_INVISIBLE,	false,	"INVISIBLE"	},
    418  1.169    rillig 		{ OP_MADE,	true,	"MADE"		},
    419  1.169    rillig 		{ OP_JOIN,	false,	"JOIN"		},
    420  1.169    rillig 		{ OP_MAKE,	false,	"MAKE"		},
    421  1.169    rillig 		{ OP_SILENT,	false,	"SILENT"	},
    422  1.169    rillig 		{ OP_PRECIOUS,	false,	"PRECIOUS"	},
    423  1.169    rillig 		{ OP_IGNORE,	false,	"IGNORE"	},
    424  1.169    rillig 		{ OP_EXEC,	false,	"EXEC"		},
    425  1.169    rillig 		{ OP_USE,	false,	"USE"		},
    426  1.169    rillig 		{ OP_OPTIONAL,	false,	"OPTIONAL"	},
    427  1.169    rillig 	};
    428  1.170    rillig 	size_t i;
    429  1.169    rillig 
    430  1.170    rillig 	for (i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
    431  1.169    rillig 		if (type & names[i].bit) {
    432  1.169    rillig 			if (names[i].internal)
    433  1.169    rillig 				DEBUG1(TARG, " .%s", names[i].name);
    434  1.169    rillig 			else
    435  1.169    rillig 				debug_printf(" .%s", names[i].name);
    436  1.150    rillig 		}
    437    1.1       cgd 	}
    438    1.1       cgd }
    439    1.1       cgd 
    440  1.161    rillig const char *
    441  1.161    rillig GNodeMade_Name(GNodeMade made)
    442   1.45       dsl {
    443  1.150    rillig 	switch (made) {
    444  1.150    rillig 	case UNMADE:    return "unmade";
    445  1.150    rillig 	case DEFERRED:  return "deferred";
    446  1.150    rillig 	case REQUESTED: return "requested";
    447  1.150    rillig 	case BEINGMADE: return "being made";
    448  1.150    rillig 	case MADE:      return "made";
    449  1.150    rillig 	case UPTODATE:  return "up-to-date";
    450  1.150    rillig 	case ERROR:     return "error when made";
    451  1.150    rillig 	case ABORTED:   return "aborted";
    452  1.150    rillig 	default:        return "unknown enum_made value";
    453  1.150    rillig 	}
    454   1.45       dsl }
    455   1.45       dsl 
    456  1.114    rillig static const char *
    457  1.114    rillig GNode_OpName(const GNode *gn)
    458  1.114    rillig {
    459  1.150    rillig 	switch (gn->type & OP_OPMASK) {
    460  1.150    rillig 	case OP_DEPENDS:
    461  1.150    rillig 		return ":";
    462  1.150    rillig 	case OP_FORCE:
    463  1.150    rillig 		return "!";
    464  1.150    rillig 	case OP_DOUBLEDEP:
    465  1.150    rillig 		return "::";
    466  1.150    rillig 	}
    467  1.150    rillig 	return "";
    468  1.114    rillig }
    469  1.114    rillig 
    470  1.173    rillig static bool
    471  1.173    rillig GNodeFlags_IsNone(GNodeFlags flags)
    472  1.173    rillig {
    473  1.173    rillig 	return !flags.remake
    474  1.173    rillig 	       && !flags.childMade
    475  1.173    rillig 	       && !flags.force
    476  1.173    rillig 	       && !flags.doneWait
    477  1.173    rillig 	       && !flags.doneOrder
    478  1.173    rillig 	       && !flags.fromDepend
    479  1.173    rillig 	       && !flags.doneAllsrc
    480  1.173    rillig 	       && !flags.cycle
    481  1.173    rillig 	       && !flags.doneCycle;
    482  1.173    rillig }
    483  1.173    rillig 
    484  1.105    rillig /* Print the contents of a node. */
    485  1.105    rillig void
    486  1.105    rillig Targ_PrintNode(GNode *gn, int pass)
    487    1.1       cgd {
    488  1.150    rillig 	debug_printf("# %s%s", gn->name, gn->cohort_num);
    489  1.150    rillig 	GNode_FprintDetails(opts.debug_file, ", ", gn, "\n");
    490  1.173    rillig 	if (GNodeFlags_IsNone(gn->flags))
    491  1.150    rillig 		return;
    492  1.150    rillig 
    493  1.150    rillig 	if (!GNode_IsTarget(gn))
    494  1.150    rillig 		return;
    495   1.45       dsl 
    496  1.107    rillig 	debug_printf("#\n");
    497  1.150    rillig 	if (gn == mainTarg)
    498  1.150    rillig 		debug_printf("# *** MAIN TARGET ***\n");
    499  1.150    rillig 
    500   1.45       dsl 	if (pass >= 2) {
    501  1.150    rillig 		if (gn->unmade > 0)
    502  1.150    rillig 			debug_printf("# %d unmade children\n", gn->unmade);
    503  1.150    rillig 		else
    504  1.150    rillig 			debug_printf("# No unmade children\n");
    505  1.150    rillig 		if (!(gn->type & (OP_JOIN | OP_USE | OP_USEBEFORE | OP_EXEC))) {
    506  1.150    rillig 			if (gn->mtime != 0) {
    507  1.150    rillig 				debug_printf("# last modified %s: %s\n",
    508  1.150    rillig 				    Targ_FmtTime(gn->mtime),
    509  1.161    rillig 				    GNodeMade_Name(gn->made));
    510  1.150    rillig 			} else if (gn->made != UNMADE) {
    511  1.159    rillig 				debug_printf("# nonexistent (maybe): %s\n",
    512  1.161    rillig 				    GNodeMade_Name(gn->made));
    513  1.150    rillig 			} else
    514  1.150    rillig 				debug_printf("# unmade\n");
    515    1.1       cgd 		}
    516  1.150    rillig 		PrintNodeNamesLine("implicit parents", &gn->implicitParents);
    517   1.41       dsl 	} else {
    518  1.160    rillig 		if (gn->unmade != 0)
    519  1.150    rillig 			debug_printf("# %d unmade children\n", gn->unmade);
    520    1.1       cgd 	}
    521  1.150    rillig 
    522  1.143    rillig 	PrintNodeNamesLine("parents", &gn->parents);
    523  1.144    rillig 	PrintNodeNamesLine("order_pred", &gn->order_pred);
    524  1.144    rillig 	PrintNodeNamesLine("order_succ", &gn->order_succ);
    525   1.10  christos 
    526  1.114    rillig 	debug_printf("%-16s%s", gn->name, GNode_OpName(gn));
    527   1.34  christos 	Targ_PrintType(gn->type);
    528  1.143    rillig 	PrintNodeNames(&gn->children);
    529  1.107    rillig 	debug_printf("\n");
    530   1.84    rillig 	Targ_PrintCmds(gn);
    531  1.107    rillig 	debug_printf("\n\n");
    532  1.150    rillig 	if (gn->type & OP_DOUBLEDEP)
    533  1.150    rillig 		Targ_PrintNodes(&gn->cohorts, pass);
    534    1.1       cgd }
    535    1.1       cgd 
    536   1.87    rillig void
    537   1.89    rillig Targ_PrintNodes(GNodeList *gnodes, int pass)
    538   1.87    rillig {
    539  1.150    rillig 	GNodeListNode *ln;
    540  1.150    rillig 
    541  1.150    rillig 	for (ln = gnodes->first; ln != NULL; ln = ln->next)
    542  1.150    rillig 		Targ_PrintNode(ln->datum, pass);
    543   1.87    rillig }
    544   1.87    rillig 
    545  1.103       mrg static void
    546  1.100    rillig PrintOnlySources(void)
    547    1.4       jtc {
    548  1.150    rillig 	GNodeListNode *ln;
    549  1.100    rillig 
    550  1.150    rillig 	for (ln = allTargets.first; ln != NULL; ln = ln->next) {
    551  1.150    rillig 		GNode *gn = ln->datum;
    552  1.150    rillig 		if (GNode_IsTarget(gn))
    553  1.150    rillig 			continue;
    554  1.150    rillig 
    555  1.150    rillig 		debug_printf("#\t%s [%s]", gn->name, GNode_Path(gn));
    556  1.150    rillig 		Targ_PrintType(gn->type);
    557  1.150    rillig 		debug_printf("\n");
    558  1.150    rillig 	}
    559    1.1       cgd }
    560    1.1       cgd 
    561  1.150    rillig /*
    562  1.150    rillig  * Input:
    563   1.77    rillig  *	pass		1 => before processing
    564   1.77    rillig  *			2 => after processing
    565   1.77    rillig  *			3 => after processing, an error occurred
    566    1.1       cgd  */
    567    1.3       cgd void
    568   1.28       wiz Targ_PrintGraph(int pass)
    569    1.1       cgd {
    570  1.150    rillig 	debug_printf("#*** Input graph:\n");
    571  1.150    rillig 	Targ_PrintNodes(&allTargets, pass);
    572  1.150    rillig 	debug_printf("\n");
    573  1.150    rillig 	debug_printf("\n");
    574  1.135    rillig 
    575  1.150    rillig 	debug_printf("#\n");
    576  1.150    rillig 	debug_printf("#   Files that are only sources:\n");
    577  1.150    rillig 	PrintOnlySources();
    578  1.135    rillig 
    579  1.150    rillig 	debug_printf("#*** Global Variables:\n");
    580  1.164    rillig 	Var_Dump(SCOPE_GLOBAL);
    581  1.135    rillig 
    582  1.150    rillig 	debug_printf("#*** Command-line Variables:\n");
    583  1.164    rillig 	Var_Dump(SCOPE_CMDLINE);
    584  1.135    rillig 
    585  1.150    rillig 	debug_printf("\n");
    586  1.150    rillig 	Dir_PrintDirectories();
    587  1.150    rillig 	debug_printf("\n");
    588  1.135    rillig 
    589  1.150    rillig 	Suff_PrintAll();
    590   1.19   mycroft }
    591   1.19   mycroft 
    592  1.150    rillig /*
    593  1.150    rillig  * Propagate some type information to cohort nodes (those from the '::'
    594   1.78    rillig  * dependency operator).
    595   1.77    rillig  *
    596   1.78    rillig  * Should be called after the makefiles are parsed but before any action is
    597  1.150    rillig  * taken.
    598  1.150    rillig  */
    599   1.78    rillig void
    600   1.78    rillig Targ_Propagate(void)
    601   1.19   mycroft {
    602  1.150    rillig 	GNodeListNode *ln, *cln;
    603   1.45       dsl 
    604  1.150    rillig 	for (ln = allTargets.first; ln != NULL; ln = ln->next) {
    605  1.150    rillig 		GNode *gn = ln->datum;
    606  1.150    rillig 		GNodeType type = gn->type;
    607   1.19   mycroft 
    608  1.150    rillig 		if (!(type & OP_DOUBLEDEP))
    609  1.150    rillig 			continue;
    610   1.42       apb 
    611  1.150    rillig 		for (cln = gn->cohorts.first; cln != NULL; cln = cln->next) {
    612  1.150    rillig 			GNode *cohort = cln->datum;
    613   1.42       apb 
    614  1.150    rillig 			cohort->type |= type & ~OP_OPMASK;
    615  1.150    rillig 		}
    616   1.78    rillig 	}
    617    1.1       cgd }
    618