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