Home | History | Annotate | Line # | Download | only in make
targ.c revision 1.106
      1  1.106    rillig /*	$NetBSD: targ.c,v 1.106 2020/09/27 21:35:16 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.1       cgd /*-
     72    1.1       cgd  * targ.c --
     73    1.1       cgd  *	Functions for maintaining the Lst allTargets. Target nodes are
     74   1.77    rillig  *	kept in two structures: a Lst and a hash table.
     75    1.1       cgd  *
     76    1.1       cgd  * Interface:
     77  1.106    rillig  *	Targ_Init	Initialization procedure.
     78    1.1       cgd  *
     79  1.106    rillig  *	Targ_End	Cleanup the module
     80    1.4       jtc  *
     81  1.106    rillig  *	Targ_List	Return the list of all targets so far.
     82   1.12  christos  *
     83  1.106    rillig  *	Targ_NewGN	Create a new GNode for the passed target
     84  1.106    rillig  *			(string). The node is *not* placed in the
     85  1.106    rillig  *			hash table, though all its fields are
     86  1.106    rillig  *			initialized.
     87    1.1       cgd  *
     88  1.106    rillig  *	Targ_FindNode	Find the node, or return NULL.
     89   1.98    rillig  *
     90  1.106    rillig  *	Targ_GetNode	Find the node, or create it.
     91   1.98    rillig  *
     92  1.106    rillig  *	Targ_NewInternalNode
     93  1.106    rillig  *			Create an internal node.
     94    1.1       cgd  *
     95  1.106    rillig  *	Targ_FindList	Given a list of names, find nodes for all
     96  1.106    rillig  *			of them, creating them as necessary.
     97    1.1       cgd  *
     98  1.106    rillig  *	Targ_Ignore	Return TRUE if errors should be ignored when
     99  1.106    rillig  *			creating the given target.
    100    1.1       cgd  *
    101  1.106    rillig  *	Targ_Silent	Return TRUE if we should be silent when
    102  1.106    rillig  *			creating the given target.
    103    1.1       cgd  *
    104  1.106    rillig  *	Targ_Precious	Return TRUE if the target is precious and
    105  1.106    rillig  *			should not be removed if we are interrupted.
    106    1.1       cgd  *
    107  1.106    rillig  *	Targ_Propagate	Propagate information between related nodes.
    108  1.106    rillig  *			Should be called after the makefiles are parsed
    109  1.106    rillig  *			but before any action is taken.
    110   1.42       apb  *
    111    1.1       cgd  * Debugging:
    112  1.106    rillig  *	Targ_PrintGraph
    113  1.106    rillig  *			Print out the entire graphm all variables and
    114  1.106    rillig  *			statistics for the directory cache. Should print
    115  1.106    rillig  *			something for suffixes, too, but...
    116    1.1       cgd  */
    117    1.1       cgd 
    118    1.1       cgd #include	  <stdio.h>
    119    1.1       cgd #include	  <time.h>
    120   1.28       wiz 
    121    1.1       cgd #include	  "make.h"
    122    1.3       cgd #include	  "dir.h"
    123    1.1       cgd 
    124   1.88    rillig /*	"@(#)targ.c	8.2 (Berkeley) 3/19/94"	*/
    125  1.106    rillig MAKE_RCSID("$NetBSD: targ.c,v 1.106 2020/09/27 21:35:16 rillig Exp $");
    126   1.88    rillig 
    127   1.89    rillig static GNodeList *allTargets;	/* the list of all targets found so far */
    128   1.18   mycroft #ifdef CLEANUP
    129   1.89    rillig static GNodeList *allGNs;	/* List of all the GNodes */
    130   1.18   mycroft #endif
    131    1.1       cgd static Hash_Table targets;	/* a hash table of same */
    132    1.1       cgd 
    133   1.18   mycroft #ifdef CLEANUP
    134   1.55       dsl static void TargFreeGN(void *);
    135   1.18   mycroft #endif
    136    1.4       jtc 
    137    1.1       cgd void
    138   1.28       wiz Targ_Init(void)
    139    1.1       cgd {
    140   1.65    rillig     allTargets = Lst_Init();
    141   1.83    rillig     Hash_InitTable(&targets);
    142    1.1       cgd }
    143    1.1       cgd 
    144    1.4       jtc void
    145   1.28       wiz Targ_End(void)
    146    1.4       jtc {
    147   1.64       sjg     Targ_Stats();
    148   1.18   mycroft #ifdef CLEANUP
    149   1.76    rillig     Lst_Free(allTargets);
    150   1.73    rillig     if (allGNs != NULL)
    151   1.76    rillig 	Lst_Destroy(allGNs, TargFreeGN);
    152    1.4       jtc     Hash_DeleteTable(&targets);
    153   1.18   mycroft #endif
    154   1.12  christos }
    155   1.12  christos 
    156   1.64       sjg void
    157   1.64       sjg Targ_Stats(void)
    158   1.64       sjg {
    159   1.64       sjg     Hash_DebugStats(&targets, "targets");
    160   1.64       sjg }
    161   1.64       sjg 
    162   1.77    rillig /* Return the list of all targets. */
    163   1.89    rillig GNodeList *
    164   1.28       wiz Targ_List(void)
    165   1.12  christos {
    166   1.12  christos     return allTargets;
    167    1.4       jtc }
    168    1.4       jtc 
    169   1.77    rillig /* Create and initialize a new graph node. The gnode is added to the list of
    170   1.77    rillig  * all gnodes.
    171    1.1       cgd  *
    172   1.28       wiz  * Input:
    173   1.91    rillig  *	name		the name of the node, such as "clean", "src.c", ".END"
    174    1.1       cgd  */
    175    1.1       cgd GNode *
    176   1.29  christos Targ_NewGN(const char *name)
    177    1.1       cgd {
    178   1.28       wiz     GNode *gn;
    179    1.1       cgd 
    180   1.53     joerg     gn = bmake_malloc(sizeof(GNode));
    181   1.53     joerg     gn->name = bmake_strdup(name);
    182   1.11  christos     gn->uname = NULL;
    183   1.29  christos     gn->path = NULL;
    184   1.77    rillig     gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
    185  1.106    rillig     gn->unmade = 0;
    186   1.27        pk     gn->unmade_cohorts = 0;
    187   1.45       dsl     gn->cohort_num[0] = 0;
    188  1.106    rillig     gn->centurion = NULL;
    189  1.106    rillig     gn->made = UNMADE;
    190  1.106    rillig     gn->flags = 0;
    191  1.106    rillig     gn->checked = 0;
    192  1.106    rillig     gn->mtime = 0;
    193  1.106    rillig     gn->cmgn = NULL;
    194   1.80    rillig     gn->implicitParents = Lst_Init();
    195  1.106    rillig     gn->cohorts = Lst_Init();
    196  1.106    rillig     gn->parents = Lst_Init();
    197  1.106    rillig     gn->children = Lst_Init();
    198  1.106    rillig     gn->order_pred = Lst_Init();
    199  1.106    rillig     gn->order_succ = Lst_Init();
    200   1.83    rillig     Hash_InitTable(&gn->context);
    201  1.106    rillig     gn->commands = Lst_Init();
    202  1.106    rillig     gn->suffix = NULL;
    203  1.106    rillig     gn->fname = NULL;
    204  1.106    rillig     gn->lineno = 0;
    205    1.1       cgd 
    206   1.18   mycroft #ifdef CLEANUP
    207    1.4       jtc     if (allGNs == NULL)
    208   1.65    rillig 	allGNs = Lst_Init();
    209   1.76    rillig     Lst_Append(allGNs, gn);
    210   1.18   mycroft #endif
    211    1.4       jtc 
    212   1.63    rillig     return gn;
    213    1.1       cgd }
    214    1.1       cgd 
    215   1.18   mycroft #ifdef CLEANUP
    216    1.4       jtc static void
    217   1.55       dsl TargFreeGN(void *gnp)
    218    1.4       jtc {
    219   1.37  christos     GNode *gn = (GNode *)gnp;
    220    1.4       jtc 
    221    1.4       jtc     free(gn->name);
    222   1.61  christos     free(gn->uname);
    223   1.61  christos     free(gn->path);
    224    1.4       jtc 
    225   1.80    rillig     Lst_Free(gn->implicitParents);
    226   1.76    rillig     Lst_Free(gn->cohorts);
    227   1.76    rillig     Lst_Free(gn->parents);
    228   1.76    rillig     Lst_Free(gn->children);
    229   1.76    rillig     Lst_Free(gn->order_succ);
    230   1.76    rillig     Lst_Free(gn->order_pred);
    231   1.17   mycroft     Hash_DeleteTable(&gn->context);
    232   1.76    rillig     Lst_Free(gn->commands);
    233   1.77    rillig 
    234   1.77    rillig     /* XXX: does gn->suffix need to be freed? It is reference-counted. */
    235   1.77    rillig 
    236   1.36  christos     free(gn);
    237    1.4       jtc }
    238   1.18   mycroft #endif
    239    1.4       jtc 
    240   1.95    rillig /* Get the existing global node, or return NULL. */
    241   1.95    rillig GNode *
    242   1.95    rillig Targ_FindNode(const char *name)
    243   1.95    rillig {
    244   1.96    rillig     return Hash_FindValue(&targets, name);
    245   1.95    rillig }
    246   1.95    rillig 
    247   1.95    rillig /* Get the existing global node, or create it. */
    248   1.95    rillig GNode *
    249   1.95    rillig Targ_GetNode(const char *name)
    250   1.95    rillig {
    251   1.96    rillig     Boolean isNew;
    252   1.96    rillig     Hash_Entry *he = Hash_CreateEntry(&targets, name, &isNew);
    253   1.96    rillig     if (!isNew)
    254   1.96    rillig 	return Hash_GetValue(he);
    255   1.96    rillig 
    256   1.96    rillig     {
    257   1.96    rillig 	GNode *gn = Targ_NewInternalNode(name);
    258   1.96    rillig 	Hash_SetValue(he, gn);
    259   1.96    rillig 	return gn;
    260   1.96    rillig     }
    261   1.95    rillig }
    262   1.95    rillig 
    263   1.95    rillig /* Create a node, register it in .ALLTARGETS but don't store it in the
    264   1.95    rillig  * table of global nodes.  This means it cannot be found by name.
    265   1.95    rillig  *
    266   1.95    rillig  * This is used for internal nodes, such as cohorts or .WAIT nodes. */
    267   1.95    rillig GNode *
    268   1.95    rillig Targ_NewInternalNode(const char *name)
    269   1.95    rillig {
    270   1.96    rillig     GNode *gn = Targ_NewGN(name);
    271   1.96    rillig     Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
    272   1.96    rillig     Lst_Append(allTargets, gn);
    273   1.96    rillig     if (doing_depend)
    274   1.96    rillig 	gn->flags |= FROM_DEPEND;
    275   1.96    rillig     return gn;
    276   1.95    rillig }
    277   1.95    rillig 
    278   1.90    rillig /* Return the .END node, which contains the commands to be executed when
    279   1.90    rillig  * everything else is done. */
    280   1.90    rillig GNode *Targ_GetEndNode(void)
    281   1.90    rillig {
    282   1.90    rillig     /* Save the node locally to avoid having to search for it all the time. */
    283   1.90    rillig     static GNode *endNode = NULL;
    284   1.90    rillig     if (endNode == NULL) {
    285   1.95    rillig 	endNode = Targ_GetNode(".END");
    286   1.90    rillig 	endNode->type = OP_SPECIAL;
    287   1.90    rillig     }
    288   1.90    rillig     return endNode;
    289   1.90    rillig }
    290   1.90    rillig 
    291   1.98    rillig /* Return the named nodes, creating them as necessary. */
    292   1.89    rillig GNodeList *
    293   1.95    rillig Targ_FindList(StringList *names)
    294    1.1       cgd {
    295   1.89    rillig     GNodeList *nodes;
    296   1.89    rillig     StringListNode *ln;
    297    1.1       cgd 
    298   1.65    rillig     nodes = Lst_Init();
    299    1.1       cgd 
    300   1.76    rillig     Lst_Open(names);
    301   1.76    rillig     while ((ln = Lst_Next(names)) != NULL) {
    302   1.96    rillig 	char *name = LstNode_Datum(ln);
    303   1.96    rillig 	GNode *gn = Targ_GetNode(name);
    304   1.95    rillig 	Lst_Append(nodes, gn);
    305    1.1       cgd     }
    306   1.76    rillig     Lst_Close(names);
    307   1.63    rillig     return nodes;
    308    1.1       cgd }
    309    1.1       cgd 
    310   1.77    rillig /* Return true if should ignore errors when creating gn. */
    311    1.1       cgd Boolean
    312   1.28       wiz Targ_Ignore(GNode *gn)
    313    1.1       cgd {
    314   1.77    rillig     return ignoreErrors || gn->type & OP_IGNORE;
    315    1.1       cgd }
    316    1.1       cgd 
    317   1.77    rillig /* Return true if be silent when creating gn. */
    318    1.1       cgd Boolean
    319   1.28       wiz Targ_Silent(GNode *gn)
    320    1.1       cgd {
    321   1.77    rillig     return beSilent || gn->type & OP_SILENT;
    322    1.1       cgd }
    323    1.1       cgd 
    324   1.77    rillig /* See if the given target is precious. */
    325    1.1       cgd Boolean
    326   1.28       wiz Targ_Precious(GNode *gn)
    327    1.1       cgd {
    328   1.77    rillig     return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
    329    1.1       cgd }
    330    1.1       cgd 
    331    1.1       cgd /******************* DEBUG INFO PRINTING ****************/
    332    1.1       cgd 
    333    1.1       cgd static GNode	  *mainTarg;	/* the main target, as set by Targ_SetMain */
    334   1.77    rillig 
    335   1.77    rillig /* Set our idea of the main target we'll be creating. Used for debugging
    336   1.77    rillig  * output. */
    337    1.1       cgd void
    338   1.28       wiz Targ_SetMain(GNode *gn)
    339    1.1       cgd {
    340    1.1       cgd     mainTarg = gn;
    341    1.1       cgd }
    342    1.1       cgd 
    343   1.86    rillig static void
    344   1.89    rillig PrintNodeNames(GNodeList *gnodes)
    345    1.1       cgd {
    346   1.89    rillig     GNodeListNode *node;
    347   1.38       dsl 
    348  1.101    rillig     for (node = gnodes->first; node != NULL; node = node->next) {
    349  1.101    rillig 	GNode *gn = node->datum;
    350   1.85    rillig 	fprintf(debug_file, " %s%s", gn->name, gn->cohort_num);
    351   1.85    rillig     }
    352   1.85    rillig }
    353   1.38       dsl 
    354   1.85    rillig static void
    355   1.89    rillig PrintNodeNamesLine(const char *label, GNodeList *gnodes)
    356   1.85    rillig {
    357   1.85    rillig     if (Lst_IsEmpty(gnodes))
    358   1.85    rillig 	return;
    359   1.85    rillig     fprintf(debug_file, "# %s:", label);
    360   1.85    rillig     PrintNodeNames(gnodes);
    361   1.85    rillig     fprintf(debug_file, "\n");
    362    1.1       cgd }
    363    1.1       cgd 
    364   1.84    rillig void
    365   1.84    rillig Targ_PrintCmds(GNode *gn)
    366   1.84    rillig {
    367  1.101    rillig     StringListNode *node = gn->commands->first;
    368  1.101    rillig     for (; node != NULL; node = node->next) {
    369   1.93    rillig 	const char *cmd = LstNode_Datum(node);
    370   1.93    rillig 	fprintf(debug_file, "\t%s\n", cmd);
    371   1.93    rillig     }
    372   1.84    rillig }
    373   1.84    rillig 
    374   1.77    rillig /* Format a modification time in some reasonable way and return it.
    375   1.77    rillig  * The time is placed in a static area, so it is overwritten with each call. */
    376    1.1       cgd char *
    377   1.28       wiz Targ_FmtTime(time_t tm)
    378    1.1       cgd {
    379  1.106    rillig     struct tm *parts;
    380  1.106    rillig     static char buf[128];
    381    1.1       cgd 
    382   1.25   reinoud     parts = localtime(&tm);
    383   1.15  christos     (void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
    384   1.63    rillig     return buf;
    385    1.1       cgd }
    386   1.10  christos 
    387   1.77    rillig /* Print out a type field giving only those attributes the user can set. */
    388    1.1       cgd void
    389   1.52  christos Targ_PrintType(int type)
    390    1.1       cgd {
    391   1.28       wiz     int    tbit;
    392   1.10  christos 
    393   1.82    rillig #define PRINTBIT(attr)	case CONCAT(OP_,attr): fprintf(debug_file, " ." #attr); break
    394   1.82    rillig #define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, " ." #attr); break
    395    1.1       cgd 
    396    1.1       cgd     type &= ~OP_OPMASK;
    397    1.1       cgd 
    398    1.1       cgd     while (type) {
    399   1.52  christos 	tbit = 1 << (ffs(type) - 1);
    400    1.1       cgd 	type &= ~tbit;
    401    1.1       cgd 
    402    1.1       cgd 	switch(tbit) {
    403   1.96    rillig 	PRINTBIT(OPTIONAL);
    404   1.96    rillig 	PRINTBIT(USE);
    405   1.96    rillig 	PRINTBIT(EXEC);
    406   1.96    rillig 	PRINTBIT(IGNORE);
    407   1.96    rillig 	PRINTBIT(PRECIOUS);
    408   1.96    rillig 	PRINTBIT(SILENT);
    409   1.96    rillig 	PRINTBIT(MAKE);
    410   1.96    rillig 	PRINTBIT(JOIN);
    411   1.96    rillig 	PRINTBIT(INVISIBLE);
    412   1.96    rillig 	PRINTBIT(NOTMAIN);
    413   1.96    rillig 	PRINTDBIT(LIB);
    414    1.1       cgd 	    /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
    415   1.96    rillig 	case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, " .MEMBER"); break;
    416   1.96    rillig 	PRINTDBIT(ARCHV);
    417   1.96    rillig 	PRINTDBIT(MADE);
    418   1.96    rillig 	PRINTDBIT(PHONY);
    419    1.1       cgd 	}
    420    1.1       cgd     }
    421    1.1       cgd }
    422    1.1       cgd 
    423   1.45       dsl static const char *
    424   1.71    rillig made_name(GNodeMade made)
    425   1.45       dsl {
    426   1.45       dsl     switch (made) {
    427   1.45       dsl     case UNMADE:     return "unmade";
    428   1.45       dsl     case DEFERRED:   return "deferred";
    429   1.45       dsl     case REQUESTED:  return "requested";
    430   1.45       dsl     case BEINGMADE:  return "being made";
    431   1.45       dsl     case MADE:       return "made";
    432   1.45       dsl     case UPTODATE:   return "up-to-date";
    433   1.45       dsl     case ERROR:      return "error when made";
    434   1.45       dsl     case ABORTED:    return "aborted";
    435   1.45       dsl     default:         return "unknown enum_made value";
    436   1.45       dsl     }
    437   1.45       dsl }
    438   1.45       dsl 
    439  1.105    rillig /* Print the contents of a node. */
    440  1.105    rillig void
    441  1.105    rillig Targ_PrintNode(GNode *gn, int pass)
    442    1.1       cgd {
    443   1.72    rillig     fprintf(debug_file, "# %s%s", gn->name, gn->cohort_num);
    444   1.72    rillig     GNode_FprintDetails(debug_file, ", ", gn, "\n");
    445   1.45       dsl     if (gn->flags == 0)
    446  1.104    rillig 	return;
    447   1.45       dsl 
    448    1.1       cgd     if (!OP_NOP(gn->type)) {
    449   1.43       dsl 	fprintf(debug_file, "#\n");
    450    1.1       cgd 	if (gn == mainTarg) {
    451   1.43       dsl 	    fprintf(debug_file, "# *** MAIN TARGET ***\n");
    452    1.1       cgd 	}
    453   1.45       dsl 	if (pass >= 2) {
    454    1.1       cgd 	    if (gn->unmade) {
    455   1.43       dsl 		fprintf(debug_file, "# %d unmade children\n", gn->unmade);
    456    1.1       cgd 	    } else {
    457   1.43       dsl 		fprintf(debug_file, "# No unmade children\n");
    458    1.1       cgd 	    }
    459   1.22  christos 	    if (! (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
    460    1.1       cgd 		if (gn->mtime != 0) {
    461   1.43       dsl 		    fprintf(debug_file, "# last modified %s: %s\n",
    462   1.96    rillig 			    Targ_FmtTime(gn->mtime),
    463   1.96    rillig 			    made_name(gn->made));
    464    1.1       cgd 		} else if (gn->made != UNMADE) {
    465   1.43       dsl 		    fprintf(debug_file, "# non-existent (maybe): %s\n",
    466   1.96    rillig 			    made_name(gn->made));
    467    1.1       cgd 		} else {
    468   1.43       dsl 		    fprintf(debug_file, "# unmade\n");
    469    1.1       cgd 		}
    470    1.1       cgd 	    }
    471   1.85    rillig 	    PrintNodeNamesLine("implicit parents", gn->implicitParents);
    472   1.41       dsl 	} else {
    473   1.41       dsl 	    if (gn->unmade)
    474   1.43       dsl 		fprintf(debug_file, "# %d unmade children\n", gn->unmade);
    475    1.1       cgd 	}
    476   1.85    rillig 	PrintNodeNamesLine("parents", gn->parents);
    477   1.85    rillig 	PrintNodeNamesLine("order_pred", gn->order_pred);
    478   1.85    rillig 	PrintNodeNamesLine("order_succ", gn->order_succ);
    479   1.10  christos 
    480   1.43       dsl 	fprintf(debug_file, "%-16s", gn->name);
    481    1.1       cgd 	switch (gn->type & OP_OPMASK) {
    482   1.96    rillig 	case OP_DEPENDS:
    483   1.96    rillig 	    fprintf(debug_file, ":"); break;
    484   1.96    rillig 	case OP_FORCE:
    485   1.96    rillig 	    fprintf(debug_file, "!"); break;
    486   1.96    rillig 	case OP_DOUBLEDEP:
    487   1.96    rillig 	    fprintf(debug_file, "::"); break;
    488    1.1       cgd 	}
    489   1.34  christos 	Targ_PrintType(gn->type);
    490   1.85    rillig 	PrintNodeNames(gn->children);
    491   1.43       dsl 	fprintf(debug_file, "\n");
    492   1.84    rillig 	Targ_PrintCmds(gn);
    493   1.43       dsl 	fprintf(debug_file, "\n\n");
    494   1.20   mycroft 	if (gn->type & OP_DOUBLEDEP) {
    495  1.104    rillig 	    Targ_PrintNodes(gn->cohorts, pass);
    496    1.1       cgd 	}
    497    1.1       cgd     }
    498    1.1       cgd }
    499    1.1       cgd 
    500   1.87    rillig void
    501   1.89    rillig Targ_PrintNodes(GNodeList *gnodes, int pass)
    502   1.87    rillig {
    503  1.104    rillig     GNodeListNode *ln;
    504  1.104    rillig     for (ln = gnodes->first; ln != NULL; ln = ln->next)
    505  1.105    rillig 	Targ_PrintNode(ln->datum, pass);
    506   1.87    rillig }
    507   1.87    rillig 
    508  1.100    rillig /* Print only those targets that are just a source. */
    509  1.103       mrg static void
    510  1.100    rillig PrintOnlySources(void)
    511    1.4       jtc {
    512  1.100    rillig     GNodeListNode *ln;
    513  1.100    rillig 
    514  1.100    rillig     for (ln = allTargets->first; ln != NULL; ln = ln->next) {
    515  1.100    rillig 	GNode *gn = ln->datum;
    516  1.100    rillig 	if (!OP_NOP(gn->type))
    517  1.100    rillig 	    continue;
    518    1.4       jtc 
    519  1.100    rillig 	fprintf(debug_file, "#\t%s [%s]",
    520  1.100    rillig 		gn->name, gn->path ? gn->path : gn->name);
    521  1.100    rillig 	Targ_PrintType(gn->type);
    522  1.100    rillig 	fprintf(debug_file, "\n");
    523  1.100    rillig     }
    524    1.1       cgd }
    525    1.1       cgd 
    526   1.77    rillig /* Input:
    527   1.77    rillig  *	pass		1 => before processing
    528   1.77    rillig  *			2 => after processing
    529   1.77    rillig  *			3 => after processing, an error occurred
    530    1.1       cgd  */
    531    1.3       cgd void
    532   1.28       wiz Targ_PrintGraph(int pass)
    533    1.1       cgd {
    534   1.43       dsl     fprintf(debug_file, "#*** Input graph:\n");
    535  1.100    rillig     Targ_PrintNodes(allTargets, pass);
    536   1.43       dsl     fprintf(debug_file, "\n\n");
    537   1.43       dsl     fprintf(debug_file, "#\n#   Files that are only sources:\n");
    538  1.100    rillig     PrintOnlySources();
    539   1.43       dsl     fprintf(debug_file, "#*** Global Variables:\n");
    540   1.34  christos     Var_Dump(VAR_GLOBAL);
    541   1.43       dsl     fprintf(debug_file, "#*** Command-line Variables:\n");
    542   1.34  christos     Var_Dump(VAR_CMD);
    543   1.43       dsl     fprintf(debug_file, "\n");
    544    1.1       cgd     Dir_PrintDirectories();
    545   1.43       dsl     fprintf(debug_file, "\n");
    546    1.1       cgd     Suff_PrintAll();
    547   1.19   mycroft }
    548   1.19   mycroft 
    549   1.78    rillig /* Propagate some type information to cohort nodes (those from the ::
    550   1.78    rillig  * dependency operator).
    551   1.77    rillig  *
    552   1.78    rillig  * Should be called after the makefiles are parsed but before any action is
    553   1.78    rillig  * taken. */
    554   1.78    rillig void
    555   1.78    rillig Targ_Propagate(void)
    556   1.19   mycroft {
    557   1.89    rillig     GNodeListNode *pn, *cn;
    558   1.45       dsl 
    559  1.101    rillig     for (pn = allTargets->first; pn != NULL; pn = pn->next) {
    560  1.101    rillig 	GNode *pgn = pn->datum;
    561   1.19   mycroft 
    562   1.78    rillig 	if (!(pgn->type & OP_DOUBLEDEP))
    563   1.78    rillig 	    continue;
    564   1.42       apb 
    565  1.101    rillig 	for (cn = pgn->cohorts->first; cn != NULL; cn = cn->next) {
    566  1.101    rillig 	    GNode *cgn = cn->datum;
    567   1.42       apb 
    568   1.78    rillig 	    cgn->type |= pgn->type & ~OP_OPMASK;
    569   1.78    rillig 	}
    570   1.78    rillig     }
    571    1.1       cgd }
    572