Home | History | Annotate | Line # | Download | only in make
targ.c revision 1.49
      1 /*	$NetBSD: targ.c,v 1.49 2006/12/21 20:05:37 dsl Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1989, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Adam de Boor.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 /*
     36  * Copyright (c) 1989 by Berkeley Softworks
     37  * All rights reserved.
     38  *
     39  * This code is derived from software contributed to Berkeley by
     40  * Adam de Boor.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  * 3. All advertising materials mentioning features or use of this software
     51  *    must display the following acknowledgement:
     52  *	This product includes software developed by the University of
     53  *	California, Berkeley and its contributors.
     54  * 4. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  */
     70 
     71 #ifndef MAKE_NATIVE
     72 static char rcsid[] = "$NetBSD: targ.c,v 1.49 2006/12/21 20:05:37 dsl Exp $";
     73 #else
     74 #include <sys/cdefs.h>
     75 #ifndef lint
     76 #if 0
     77 static char sccsid[] = "@(#)targ.c	8.2 (Berkeley) 3/19/94";
     78 #else
     79 __RCSID("$NetBSD: targ.c,v 1.49 2006/12/21 20:05:37 dsl Exp $");
     80 #endif
     81 #endif /* not lint */
     82 #endif
     83 
     84 /*-
     85  * targ.c --
     86  *	Functions for maintaining the Lst allTargets. Target nodes are
     87  * kept in two structures: a Lst, maintained by the list library, and a
     88  * hash table, maintained by the hash library.
     89  *
     90  * Interface:
     91  *	Targ_Init 	    	Initialization procedure.
     92  *
     93  *	Targ_End 	    	Cleanup the module
     94  *
     95  *	Targ_List 	    	Return the list of all targets so far.
     96  *
     97  *	Targ_NewGN	    	Create a new GNode for the passed target
     98  *	    	  	    	(string). The node is *not* placed in the
     99  *	    	  	    	hash table, though all its fields are
    100  *	    	  	    	initialized.
    101  *
    102  *	Targ_FindNode	    	Find the node for a given target, creating
    103  *	    	  	    	and storing it if it doesn't exist and the
    104  *	    	  	    	flags are right (TARG_CREATE)
    105  *
    106  *	Targ_FindList	    	Given a list of names, find nodes for all
    107  *	    	  	    	of them. If a name doesn't exist and the
    108  *	    	  	    	TARG_NOCREATE flag was given, an error message
    109  *	    	  	    	is printed. Else, if a name doesn't exist,
    110  *	    	  	    	its node is created.
    111  *
    112  *	Targ_Ignore	    	Return TRUE if errors should be ignored when
    113  *	    	  	    	creating the given target.
    114  *
    115  *	Targ_Silent	    	Return TRUE if we should be silent when
    116  *	    	  	    	creating the given target.
    117  *
    118  *	Targ_Precious	    	Return TRUE if the target is precious and
    119  *	    	  	    	should not be removed if we are interrupted.
    120  *
    121  *	Targ_Propagate		Propagate information between related
    122  *				nodes.	Should be called after the
    123  *				makefiles are parsed but before any
    124  *				action is taken.
    125  *
    126  * Debugging:
    127  *	Targ_PrintGraph	    	Print out the entire graphm all variables
    128  *	    	  	    	and statistics for the directory cache. Should
    129  *	    	  	    	print something for suffixes, too, but...
    130  */
    131 
    132 #include	  <stdio.h>
    133 #include	  <time.h>
    134 
    135 #include	  "make.h"
    136 #include	  "hash.h"
    137 #include	  "dir.h"
    138 
    139 static Lst        allTargets;	/* the list of all targets found so far */
    140 #ifdef CLEANUP
    141 static Lst	  allGNs;	/* List of all the GNodes */
    142 #endif
    143 static Hash_Table targets;	/* a hash table of same */
    144 
    145 #define HTSIZE	191		/* initial size of hash table */
    146 
    147 static int TargPrintOnlySrc(ClientData, ClientData);
    148 static int TargPrintName(ClientData, ClientData);
    149 #ifdef CLEANUP
    150 static void TargFreeGN(ClientData);
    151 #endif
    152 static int TargPropagateCohort(ClientData, ClientData);
    153 static int TargPropagateNode(ClientData, ClientData);
    154 
    155 /*-
    156  *-----------------------------------------------------------------------
    157  * Targ_Init --
    158  *	Initialize this module
    159  *
    160  * Results:
    161  *	None
    162  *
    163  * Side Effects:
    164  *	The allTargets list and the targets hash table are initialized
    165  *-----------------------------------------------------------------------
    166  */
    167 void
    168 Targ_Init(void)
    169 {
    170     allTargets = Lst_Init(FALSE);
    171     Hash_InitTable(&targets, HTSIZE);
    172 }
    173 
    174 /*-
    175  *-----------------------------------------------------------------------
    176  * Targ_End --
    177  *	Finalize this module
    178  *
    179  * Results:
    180  *	None
    181  *
    182  * Side Effects:
    183  *	All lists and gnodes are cleared
    184  *-----------------------------------------------------------------------
    185  */
    186 void
    187 Targ_End(void)
    188 {
    189 #ifdef CLEANUP
    190     Lst_Destroy(allTargets, NOFREE);
    191     if (allGNs)
    192 	Lst_Destroy(allGNs, TargFreeGN);
    193     Hash_DeleteTable(&targets);
    194 #endif
    195 }
    196 
    197 /*-
    198  *-----------------------------------------------------------------------
    199  * Targ_List --
    200  *	Return the list of all targets
    201  *
    202  * Results:
    203  *	The list of all targets.
    204  *
    205  * Side Effects:
    206  *	None
    207  *-----------------------------------------------------------------------
    208  */
    209 Lst
    210 Targ_List(void)
    211 {
    212     return allTargets;
    213 }
    214 
    215 /*-
    216  *-----------------------------------------------------------------------
    217  * Targ_NewGN  --
    218  *	Create and initialize a new graph node
    219  *
    220  * Input:
    221  *	name		the name to stick in the new node
    222  *
    223  * Results:
    224  *	An initialized graph node with the name field filled with a copy
    225  *	of the passed name
    226  *
    227  * Side Effects:
    228  *	The gnode is added to the list of all gnodes.
    229  *-----------------------------------------------------------------------
    230  */
    231 GNode *
    232 Targ_NewGN(const char *name)
    233 {
    234     GNode *gn;
    235 
    236     gn = emalloc(sizeof(GNode));
    237     gn->name = estrdup(name);
    238     gn->uname = NULL;
    239     gn->path = NULL;
    240     if (name[0] == '-' && name[1] == 'l') {
    241 	gn->type = OP_LIB;
    242     } else {
    243 	gn->type = 0;
    244     }
    245     gn->unmade =    	0;
    246     gn->unmade_cohorts = 0;
    247     gn->cohort_num[0] = 0;
    248     gn->centurion =    	NULL;
    249     gn->made = 	    	UNMADE;
    250     gn->flags = 	0;
    251     gn->checked = 0;
    252     gn->mtime = gn->cmtime = 0;
    253     gn->iParents =  	Lst_Init(FALSE);
    254     gn->cohorts =   	Lst_Init(FALSE);
    255     gn->parents =   	Lst_Init(FALSE);
    256     gn->children =  	Lst_Init(FALSE);
    257     gn->order_pred =  	Lst_Init(FALSE);
    258     gn->order_succ =  	Lst_Init(FALSE);
    259     Hash_InitTable(&gn->context, 0);
    260     gn->commands =  	Lst_Init(FALSE);
    261     gn->suffix =	NULL;
    262     gn->lineno =	0;
    263     gn->fname = 	NULL;
    264 
    265 #ifdef CLEANUP
    266     if (allGNs == NULL)
    267 	allGNs = Lst_Init(FALSE);
    268     Lst_AtEnd(allGNs, gn);
    269 #endif
    270 
    271     return (gn);
    272 }
    273 
    274 #ifdef CLEANUP
    275 /*-
    276  *-----------------------------------------------------------------------
    277  * TargFreeGN  --
    278  *	Destroy a GNode
    279  *
    280  * Results:
    281  *	None.
    282  *
    283  * Side Effects:
    284  *	None.
    285  *-----------------------------------------------------------------------
    286  */
    287 static void
    288 TargFreeGN(ClientData gnp)
    289 {
    290     GNode *gn = (GNode *)gnp;
    291 
    292 
    293     free(gn->name);
    294     if (gn->uname)
    295 	free(gn->uname);
    296     if (gn->path)
    297 	free(gn->path);
    298     /* gn->fname points to name allocated when file was opened, don't free */
    299 
    300     Lst_Destroy(gn->iParents, NOFREE);
    301     Lst_Destroy(gn->cohorts, NOFREE);
    302     Lst_Destroy(gn->parents, NOFREE);
    303     Lst_Destroy(gn->children, NOFREE);
    304     Lst_Destroy(gn->order_succ, NOFREE);
    305     Lst_Destroy(gn->order_pred, NOFREE);
    306     Hash_DeleteTable(&gn->context);
    307     Lst_Destroy(gn->commands, NOFREE);
    308     free(gn);
    309 }
    310 #endif
    311 
    312 
    313 /*-
    314  *-----------------------------------------------------------------------
    315  * Targ_FindNode  --
    316  *	Find a node in the list using the given name for matching
    317  *
    318  * Input:
    319  *	name		the name to find
    320  *	flags		flags governing events when target not
    321  *			found
    322  *
    323  * Results:
    324  *	The node in the list if it was. If it wasn't, return NILGNODE of
    325  *	flags was TARG_NOCREATE or the newly created and initialized node
    326  *	if it was TARG_CREATE
    327  *
    328  * Side Effects:
    329  *	Sometimes a node is created and added to the list
    330  *-----------------------------------------------------------------------
    331  */
    332 GNode *
    333 Targ_FindNode(const char *name, int flags)
    334 {
    335     GNode         *gn;	      /* node in that element */
    336     Hash_Entry	  *he;	      /* New or used hash entry for node */
    337     Boolean	  isNew;      /* Set TRUE if Hash_CreateEntry had to create */
    338 			      /* an entry for the node */
    339 
    340     if (!(flags & (TARG_CREATE | TARG_NOHASH))) {
    341 	he = Hash_FindEntry(&targets, name);
    342 	if (he == NULL)
    343 	    return (NILGNODE);
    344 	return (GNode *)Hash_GetValue(he);
    345     }
    346 
    347     if (!(flags & TARG_NOHASH)) {
    348 	he = Hash_CreateEntry(&targets, name, &isNew);
    349 	if (!isNew)
    350 	    return (GNode *)Hash_GetValue(he);
    351     }
    352 
    353     gn = Targ_NewGN(name);
    354     if (!(flags & TARG_NOHASH))
    355 	Hash_SetValue(he, gn);
    356     Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
    357     (void)Lst_AtEnd(allTargets, gn);
    358     return gn;
    359 }
    360 
    361 /*-
    362  *-----------------------------------------------------------------------
    363  * Targ_FindList --
    364  *	Make a complete list of GNodes from the given list of names
    365  *
    366  * Input:
    367  *	name		list of names to find
    368  *	flags		flags used if no node is found for a given name
    369  *
    370  * Results:
    371  *	A complete list of graph nodes corresponding to all instances of all
    372  *	the names in names.
    373  *
    374  * Side Effects:
    375  *	If flags is TARG_CREATE, nodes will be created for all names in
    376  *	names which do not yet have graph nodes. If flags is TARG_NOCREATE,
    377  *	an error message will be printed for each name which can't be found.
    378  * -----------------------------------------------------------------------
    379  */
    380 Lst
    381 Targ_FindList(Lst names, int flags)
    382 {
    383     Lst            nodes;	/* result list */
    384     LstNode	   ln;		/* name list element */
    385     GNode	   *gn;		/* node in tLn */
    386     char    	   *name;
    387 
    388     nodes = Lst_Init(FALSE);
    389 
    390     if (Lst_Open(names) == FAILURE) {
    391 	return (nodes);
    392     }
    393     while ((ln = Lst_Next(names)) != NILLNODE) {
    394 	name = (char *)Lst_Datum(ln);
    395 	gn = Targ_FindNode(name, flags);
    396 	if (gn != NILGNODE) {
    397 	    /*
    398 	     * Note: Lst_AtEnd must come before the Lst_Concat so the nodes
    399 	     * are added to the list in the order in which they were
    400 	     * encountered in the makefile.
    401 	     */
    402 	    (void)Lst_AtEnd(nodes, gn);
    403 	} else if (flags == TARG_NOCREATE) {
    404 	    Error("\"%s\" -- target unknown.", name);
    405 	}
    406     }
    407     Lst_Close(names);
    408     return (nodes);
    409 }
    410 
    411 /*-
    412  *-----------------------------------------------------------------------
    413  * Targ_Ignore  --
    414  *	Return true if should ignore errors when creating gn
    415  *
    416  * Input:
    417  *	gn		node to check for
    418  *
    419  * Results:
    420  *	TRUE if should ignore errors
    421  *
    422  * Side Effects:
    423  *	None
    424  *-----------------------------------------------------------------------
    425  */
    426 Boolean
    427 Targ_Ignore(GNode *gn)
    428 {
    429     if (ignoreErrors || gn->type & OP_IGNORE) {
    430 	return (TRUE);
    431     } else {
    432 	return (FALSE);
    433     }
    434 }
    435 
    436 /*-
    437  *-----------------------------------------------------------------------
    438  * Targ_Silent  --
    439  *	Return true if be silent when creating gn
    440  *
    441  * Input:
    442  *	gn		node to check for
    443  *
    444  * Results:
    445  *	TRUE if should be silent
    446  *
    447  * Side Effects:
    448  *	None
    449  *-----------------------------------------------------------------------
    450  */
    451 Boolean
    452 Targ_Silent(GNode *gn)
    453 {
    454     if (beSilent || gn->type & OP_SILENT) {
    455 	return (TRUE);
    456     } else {
    457 	return (FALSE);
    458     }
    459 }
    460 
    461 /*-
    462  *-----------------------------------------------------------------------
    463  * Targ_Precious --
    464  *	See if the given target is precious
    465  *
    466  * Input:
    467  *	gn		the node to check
    468  *
    469  * Results:
    470  *	TRUE if it is precious. FALSE otherwise
    471  *
    472  * Side Effects:
    473  *	None
    474  *-----------------------------------------------------------------------
    475  */
    476 Boolean
    477 Targ_Precious(GNode *gn)
    478 {
    479     if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) {
    480 	return (TRUE);
    481     } else {
    482 	return (FALSE);
    483     }
    484 }
    485 
    486 /******************* DEBUG INFO PRINTING ****************/
    487 
    488 static GNode	  *mainTarg;	/* the main target, as set by Targ_SetMain */
    489 /*-
    490  *-----------------------------------------------------------------------
    491  * Targ_SetMain --
    492  *	Set our idea of the main target we'll be creating. Used for
    493  *	debugging output.
    494  *
    495  * Input:
    496  *	gn		The main target we'll create
    497  *
    498  * Results:
    499  *	None.
    500  *
    501  * Side Effects:
    502  *	"mainTarg" is set to the main target's node.
    503  *-----------------------------------------------------------------------
    504  */
    505 void
    506 Targ_SetMain(GNode *gn)
    507 {
    508     mainTarg = gn;
    509 }
    510 
    511 static int
    512 TargPrintName(ClientData gnp, ClientData pflags __unused)
    513 {
    514     GNode *gn = (GNode *)gnp;
    515 
    516     fprintf(debug_file, "%s%s ", gn->name, gn->cohort_num);
    517 
    518     return 0;
    519 }
    520 
    521 
    522 int
    523 Targ_PrintCmd(ClientData cmd, ClientData dummy)
    524 {
    525     fprintf(debug_file, "\t%s\n", (char *)cmd);
    526     return (dummy ? 0 : 0);
    527 }
    528 
    529 /*-
    530  *-----------------------------------------------------------------------
    531  * Targ_FmtTime --
    532  *	Format a modification time in some reasonable way and return it.
    533  *
    534  * Results:
    535  *	The time reformatted.
    536  *
    537  * Side Effects:
    538  *	The time is placed in a static area, so it is overwritten
    539  *	with each call.
    540  *
    541  *-----------------------------------------------------------------------
    542  */
    543 char *
    544 Targ_FmtTime(time_t tm)
    545 {
    546     struct tm	  	*parts;
    547     static char	  	buf[128];
    548 
    549     parts = localtime(&tm);
    550     (void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
    551     return(buf);
    552 }
    553 
    554 /*-
    555  *-----------------------------------------------------------------------
    556  * Targ_PrintType --
    557  *	Print out a type field giving only those attributes the user can
    558  *	set.
    559  *
    560  * Results:
    561  *
    562  * Side Effects:
    563  *
    564  *-----------------------------------------------------------------------
    565  */
    566 void
    567 Targ_PrintType(int type)
    568 {
    569     int    tbit;
    570 
    571 #define PRINTBIT(attr)	case CONCAT(OP_,attr): fprintf(debug_file, "." #attr " "); break
    572 #define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, "." #attr " "); break
    573 
    574     type &= ~OP_OPMASK;
    575 
    576     while (type) {
    577 	tbit = 1 << (ffs(type) - 1);
    578 	type &= ~tbit;
    579 
    580 	switch(tbit) {
    581 	    PRINTBIT(OPTIONAL);
    582 	    PRINTBIT(USE);
    583 	    PRINTBIT(EXEC);
    584 	    PRINTBIT(IGNORE);
    585 	    PRINTBIT(PRECIOUS);
    586 	    PRINTBIT(SILENT);
    587 	    PRINTBIT(MAKE);
    588 	    PRINTBIT(JOIN);
    589 	    PRINTBIT(INVISIBLE);
    590 	    PRINTBIT(NOTMAIN);
    591 	    PRINTDBIT(LIB);
    592 	    /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
    593 	    case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, ".MEMBER "); break;
    594 	    PRINTDBIT(ARCHV);
    595 	    PRINTDBIT(MADE);
    596 	    PRINTDBIT(PHONY);
    597 	}
    598     }
    599 }
    600 
    601 static const char *
    602 made_name(enum enum_made made)
    603 {
    604     switch (made) {
    605     case UNMADE:     return "unmade";
    606     case DEFERRED:   return "deferred";
    607     case REQUESTED:  return "requested";
    608     case BEINGMADE:  return "being made";
    609     case MADE:       return "made";
    610     case UPTODATE:   return "up-to-date";
    611     case ERROR:      return "error when made";
    612     case ABORTED:    return "aborted";
    613     default:         return "unknown enum_made value";
    614     }
    615 }
    616 
    617 /*-
    618  *-----------------------------------------------------------------------
    619  * TargPrintNode --
    620  *	print the contents of a node
    621  *-----------------------------------------------------------------------
    622  */
    623 int
    624 Targ_PrintNode(ClientData gnp, ClientData passp)
    625 {
    626     GNode         *gn = (GNode *)gnp;
    627     int	    	  pass = passp ? *(int *)passp : 0;
    628 
    629     fprintf(debug_file, "# %s%s, flags %x, type %x, made %d\n",
    630 	    gn->name, gn->cohort_num, gn->flags, gn->type, gn->made);
    631     if (gn->flags == 0)
    632 	return 0;
    633 
    634     if (!OP_NOP(gn->type)) {
    635 	fprintf(debug_file, "#\n");
    636 	if (gn == mainTarg) {
    637 	    fprintf(debug_file, "# *** MAIN TARGET ***\n");
    638 	}
    639 	if (pass >= 2) {
    640 	    if (gn->unmade) {
    641 		fprintf(debug_file, "# %d unmade children\n", gn->unmade);
    642 	    } else {
    643 		fprintf(debug_file, "# No unmade children\n");
    644 	    }
    645 	    if (! (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
    646 		if (gn->mtime != 0) {
    647 		    fprintf(debug_file, "# last modified %s: %s\n",
    648 			      Targ_FmtTime(gn->mtime),
    649 			      made_name(gn->made));
    650 		} else if (gn->made != UNMADE) {
    651 		    fprintf(debug_file, "# non-existent (maybe): %s\n",
    652 			      made_name(gn->made));
    653 		} else {
    654 		    fprintf(debug_file, "# unmade\n");
    655 		}
    656 	    }
    657 	    if (!Lst_IsEmpty (gn->iParents)) {
    658 		fprintf(debug_file, "# implicit parents: ");
    659 		Lst_ForEach(gn->iParents, TargPrintName, NULL);
    660 		fprintf(debug_file, "\n");
    661 	    }
    662 	} else {
    663 	    if (gn->unmade)
    664 		fprintf(debug_file, "# %d unmade children\n", gn->unmade);
    665 	}
    666 	if (!Lst_IsEmpty (gn->parents)) {
    667 	    fprintf(debug_file, "# parents: ");
    668 	    Lst_ForEach(gn->parents, TargPrintName, NULL);
    669 	    fprintf(debug_file, "\n");
    670 	}
    671 	if (!Lst_IsEmpty (gn->order_pred)) {
    672 	    fprintf(debug_file, "# order_pred: ");
    673 	    Lst_ForEach(gn->order_pred, TargPrintName, NULL);
    674 	    fprintf(debug_file, "\n");
    675 	}
    676 	if (!Lst_IsEmpty (gn->order_succ)) {
    677 	    fprintf(debug_file, "# order_succ: ");
    678 	    Lst_ForEach(gn->order_succ, TargPrintName, NULL);
    679 	    fprintf(debug_file, "\n");
    680 	}
    681 
    682 	fprintf(debug_file, "%-16s", gn->name);
    683 	switch (gn->type & OP_OPMASK) {
    684 	    case OP_DEPENDS:
    685 		fprintf(debug_file, ": "); break;
    686 	    case OP_FORCE:
    687 		fprintf(debug_file, "! "); break;
    688 	    case OP_DOUBLEDEP:
    689 		fprintf(debug_file, ":: "); break;
    690 	}
    691 	Targ_PrintType(gn->type);
    692 	Lst_ForEach(gn->children, TargPrintName, NULL);
    693 	fprintf(debug_file, "\n");
    694 	Lst_ForEach(gn->commands, Targ_PrintCmd, NULL);
    695 	fprintf(debug_file, "\n\n");
    696 	if (gn->type & OP_DOUBLEDEP) {
    697 	    Lst_ForEach(gn->cohorts, Targ_PrintNode, &pass);
    698 	}
    699     }
    700     return (0);
    701 }
    702 
    703 /*-
    704  *-----------------------------------------------------------------------
    705  * TargPrintOnlySrc --
    706  *	Print only those targets that are just a source.
    707  *
    708  * Results:
    709  *	0.
    710  *
    711  * Side Effects:
    712  *	The name of each file is printed preceded by #\t
    713  *
    714  *-----------------------------------------------------------------------
    715  */
    716 static int
    717 TargPrintOnlySrc(ClientData gnp, ClientData dummy __unused)
    718 {
    719     GNode   	  *gn = (GNode *)gnp;
    720     if (!OP_NOP(gn->type))
    721 	return 0;
    722 
    723     fprintf(debug_file, "#\t%s [%s] ",
    724 	    gn->name, gn->path ? gn->path : gn->name);
    725     Targ_PrintType(gn->type);
    726     fprintf(debug_file, "\n");
    727 
    728     return 0;
    729 }
    730 
    731 /*-
    732  *-----------------------------------------------------------------------
    733  * Targ_PrintGraph --
    734  *	print the entire graph. heh heh
    735  *
    736  * Input:
    737  *	pass		Which pass this is. 1 => no processing
    738  *			2 => processing done
    739  *
    740  * Results:
    741  *	none
    742  *
    743  * Side Effects:
    744  *	lots o' output
    745  *-----------------------------------------------------------------------
    746  */
    747 void
    748 Targ_PrintGraph(int pass)
    749 {
    750     fprintf(debug_file, "#*** Input graph:\n");
    751     Lst_ForEach(allTargets, Targ_PrintNode, &pass);
    752     fprintf(debug_file, "\n\n");
    753     fprintf(debug_file, "#\n#   Files that are only sources:\n");
    754     Lst_ForEach(allTargets, TargPrintOnlySrc, NULL);
    755     fprintf(debug_file, "#*** Global Variables:\n");
    756     Var_Dump(VAR_GLOBAL);
    757     fprintf(debug_file, "#*** Command-line Variables:\n");
    758     Var_Dump(VAR_CMD);
    759     fprintf(debug_file, "\n");
    760     Dir_PrintDirectories();
    761     fprintf(debug_file, "\n");
    762     Suff_PrintAll();
    763 }
    764 
    765 /*-
    766  *-----------------------------------------------------------------------
    767  * TargPropagateNode --
    768  *	Propagate information from a single node to related nodes if
    769  *	appropriate.
    770  *
    771  * Input:
    772  *	gnp		The node that we are processing.
    773  *
    774  * Results:
    775  *	Always returns 0, for the benefit of Lst_ForEach().
    776  *
    777  * Side Effects:
    778  *	Information is propagated from this node to cohort or child
    779  *	nodes.
    780  *
    781  *	If the node was defined with "::", then TargPropagateCohort()
    782  *	will be called for each cohort node.
    783  *
    784  *	If the node has recursive predecessors, then
    785  *	TargPropagateRecpred() will be called for each recursive
    786  *	predecessor.
    787  *-----------------------------------------------------------------------
    788  */
    789 static int
    790 TargPropagateNode(ClientData gnp, ClientData junk __unused)
    791 {
    792     GNode	  *gn = (GNode *)gnp;
    793 
    794     if (gn->type & OP_DOUBLEDEP)
    795 	Lst_ForEach(gn->cohorts, TargPropagateCohort, gnp);
    796     return (0);
    797 }
    798 
    799 /*-
    800  *-----------------------------------------------------------------------
    801  * TargPropagateCohort --
    802  *	Propagate some bits in the type mask from a node to
    803  *	a related cohort node.
    804  *
    805  * Input:
    806  *	cnp		The node that we are processing.
    807  *	gnp		Another node that has cnp as a cohort.
    808  *
    809  * Results:
    810  *	Always returns 0, for the benefit of Lst_ForEach().
    811  *
    812  * Side Effects:
    813  *	cnp's type bitmask is modified to incorporate some of the
    814  *	bits from gnp's type bitmask.  (XXX need a better explanation.)
    815  *-----------------------------------------------------------------------
    816  */
    817 static int
    818 TargPropagateCohort(ClientData cgnp, ClientData pgnp)
    819 {
    820     GNode	  *cgn = (GNode *)cgnp;
    821     GNode	  *pgn = (GNode *)pgnp;
    822 
    823     cgn->type |= pgn->type & ~OP_OPMASK;
    824     return (0);
    825 }
    826 
    827 /*-
    828  *-----------------------------------------------------------------------
    829  * Targ_Propagate --
    830  *	Propagate information between related nodes.  Should be called
    831  *	after the makefiles are parsed but before any action is taken.
    832  *
    833  * Results:
    834  *	none
    835  *
    836  * Side Effects:
    837  *	Information is propagated between related nodes throughout the
    838  *	graph.
    839  *-----------------------------------------------------------------------
    840  */
    841 void
    842 Targ_Propagate(void)
    843 {
    844     Lst_ForEach(allTargets, TargPropagateNode, NULL);
    845 }
    846