Home | History | Annotate | Line # | Download | only in make
targ.c revision 1.1.1.1
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
      3  1.1  cgd  * Copyright (c) 1988, 1989 by Adam de Boor
      4  1.1  cgd  * Copyright (c) 1989 by Berkeley Softworks
      5  1.1  cgd  * All rights reserved.
      6  1.1  cgd  *
      7  1.1  cgd  * This code is derived from software contributed to Berkeley by
      8  1.1  cgd  * Adam de Boor.
      9  1.1  cgd  *
     10  1.1  cgd  * Redistribution and use in source and binary forms, with or without
     11  1.1  cgd  * modification, are permitted provided that the following conditions
     12  1.1  cgd  * are met:
     13  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     18  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.1  cgd  *    must display the following acknowledgement:
     20  1.1  cgd  *	This product includes software developed by the University of
     21  1.1  cgd  *	California, Berkeley and its contributors.
     22  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.1  cgd  *    may be used to endorse or promote products derived from this software
     24  1.1  cgd  *    without specific prior written permission.
     25  1.1  cgd  *
     26  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1  cgd  * SUCH DAMAGE.
     37  1.1  cgd  */
     38  1.1  cgd 
     39  1.1  cgd #ifndef lint
     40  1.1  cgd static char sccsid[] = "@(#)targ.c	5.9 (Berkeley) 3/1/91";
     41  1.1  cgd #endif /* not lint */
     42  1.1  cgd 
     43  1.1  cgd /*-
     44  1.1  cgd  * targ.c --
     45  1.1  cgd  *	Functions for maintaining the Lst allTargets. Target nodes are
     46  1.1  cgd  * kept in two structures: a Lst, maintained by the list library, and a
     47  1.1  cgd  * hash table, maintained by the hash library.
     48  1.1  cgd  *
     49  1.1  cgd  * Interface:
     50  1.1  cgd  *	Targ_Init 	    	Initialization procedure.
     51  1.1  cgd  *
     52  1.1  cgd  *	Targ_NewGN	    	Create a new GNode for the passed target
     53  1.1  cgd  *	    	  	    	(string). The node is *not* placed in the
     54  1.1  cgd  *	    	  	    	hash table, though all its fields are
     55  1.1  cgd  *	    	  	    	initialized.
     56  1.1  cgd  *
     57  1.1  cgd  *	Targ_FindNode	    	Find the node for a given target, creating
     58  1.1  cgd  *	    	  	    	and storing it if it doesn't exist and the
     59  1.1  cgd  *	    	  	    	flags are right (TARG_CREATE)
     60  1.1  cgd  *
     61  1.1  cgd  *	Targ_FindList	    	Given a list of names, find nodes for all
     62  1.1  cgd  *	    	  	    	of them. If a name doesn't exist and the
     63  1.1  cgd  *	    	  	    	TARG_NOCREATE flag was given, an error message
     64  1.1  cgd  *	    	  	    	is printed. Else, if a name doesn't exist,
     65  1.1  cgd  *	    	  	    	its node is created.
     66  1.1  cgd  *
     67  1.1  cgd  *	Targ_Ignore	    	Return TRUE if errors should be ignored when
     68  1.1  cgd  *	    	  	    	creating the given target.
     69  1.1  cgd  *
     70  1.1  cgd  *	Targ_Silent	    	Return TRUE if we should be silent when
     71  1.1  cgd  *	    	  	    	creating the given target.
     72  1.1  cgd  *
     73  1.1  cgd  *	Targ_Precious	    	Return TRUE if the target is precious and
     74  1.1  cgd  *	    	  	    	should not be removed if we are interrupted.
     75  1.1  cgd  *
     76  1.1  cgd  * Debugging:
     77  1.1  cgd  *	Targ_PrintGraph	    	Print out the entire graphm all variables
     78  1.1  cgd  *	    	  	    	and statistics for the directory cache. Should
     79  1.1  cgd  *	    	  	    	print something for suffixes, too, but...
     80  1.1  cgd  */
     81  1.1  cgd 
     82  1.1  cgd #include	  <stdio.h>
     83  1.1  cgd #include	  <time.h>
     84  1.1  cgd #include	  "make.h"
     85  1.1  cgd #include	  "hash.h"
     86  1.1  cgd 
     87  1.1  cgd static Lst        allTargets;	/* the list of all targets found so far */
     88  1.1  cgd static Hash_Table targets;	/* a hash table of same */
     89  1.1  cgd 
     90  1.1  cgd #define HTSIZE	191		/* initial size of hash table */
     91  1.1  cgd 
     92  1.1  cgd /*-
     93  1.1  cgd  *-----------------------------------------------------------------------
     94  1.1  cgd  * Targ_Init --
     95  1.1  cgd  *	Initialize this module
     96  1.1  cgd  *
     97  1.1  cgd  * Results:
     98  1.1  cgd  *	None
     99  1.1  cgd  *
    100  1.1  cgd  * Side Effects:
    101  1.1  cgd  *	The allTargets list and the targets hash table are initialized
    102  1.1  cgd  *-----------------------------------------------------------------------
    103  1.1  cgd  */
    104  1.1  cgd void
    105  1.1  cgd Targ_Init ()
    106  1.1  cgd {
    107  1.1  cgd     allTargets = Lst_Init (FALSE);
    108  1.1  cgd     Hash_InitTable (&targets, HTSIZE);
    109  1.1  cgd }
    110  1.1  cgd 
    111  1.1  cgd /*-
    112  1.1  cgd  *-----------------------------------------------------------------------
    113  1.1  cgd  * Targ_NewGN  --
    114  1.1  cgd  *	Create and initialize a new graph node
    115  1.1  cgd  *
    116  1.1  cgd  * Results:
    117  1.1  cgd  *	An initialized graph node with the name field filled with a copy
    118  1.1  cgd  *	of the passed name
    119  1.1  cgd  *
    120  1.1  cgd  * Side Effects:
    121  1.1  cgd  *	None.
    122  1.1  cgd  *-----------------------------------------------------------------------
    123  1.1  cgd  */
    124  1.1  cgd GNode *
    125  1.1  cgd Targ_NewGN (name)
    126  1.1  cgd     char           *name;	/* the name to stick in the new node */
    127  1.1  cgd {
    128  1.1  cgd     register GNode *gn;
    129  1.1  cgd 
    130  1.1  cgd     gn = (GNode *) emalloc (sizeof (GNode));
    131  1.1  cgd     gn->name = strdup (name);
    132  1.1  cgd     gn->path = (char *) 0;
    133  1.1  cgd     if (name[0] == '-' && name[1] == 'l') {
    134  1.1  cgd 	gn->type = OP_LIB;
    135  1.1  cgd     } else {
    136  1.1  cgd 	gn->type = 0;
    137  1.1  cgd     }
    138  1.1  cgd     gn->unmade =    	0;
    139  1.1  cgd     gn->make = 	    	FALSE;
    140  1.1  cgd     gn->made = 	    	UNMADE;
    141  1.1  cgd     gn->childMade = 	FALSE;
    142  1.1  cgd     gn->mtime = gn->cmtime = 0;
    143  1.1  cgd     gn->iParents =  	Lst_Init (FALSE);
    144  1.1  cgd     gn->cohorts =   	Lst_Init (FALSE);
    145  1.1  cgd     gn->parents =   	Lst_Init (FALSE);
    146  1.1  cgd     gn->children =  	Lst_Init (FALSE);
    147  1.1  cgd     gn->successors = 	Lst_Init(FALSE);
    148  1.1  cgd     gn->preds =     	Lst_Init(FALSE);
    149  1.1  cgd     gn->context =   	Lst_Init (FALSE);
    150  1.1  cgd     gn->commands =  	Lst_Init (FALSE);
    151  1.1  cgd 
    152  1.1  cgd     return (gn);
    153  1.1  cgd }
    154  1.1  cgd 
    155  1.1  cgd /*-
    156  1.1  cgd  *-----------------------------------------------------------------------
    157  1.1  cgd  * Targ_FindNode  --
    158  1.1  cgd  *	Find a node in the list using the given name for matching
    159  1.1  cgd  *
    160  1.1  cgd  * Results:
    161  1.1  cgd  *	The node in the list if it was. If it wasn't, return NILGNODE of
    162  1.1  cgd  *	flags was TARG_NOCREATE or the newly created and initialized node
    163  1.1  cgd  *	if it was TARG_CREATE
    164  1.1  cgd  *
    165  1.1  cgd  * Side Effects:
    166  1.1  cgd  *	Sometimes a node is created and added to the list
    167  1.1  cgd  *-----------------------------------------------------------------------
    168  1.1  cgd  */
    169  1.1  cgd GNode *
    170  1.1  cgd Targ_FindNode (name, flags)
    171  1.1  cgd     char           *name;	/* the name to find */
    172  1.1  cgd     int             flags;	/* flags governing events when target not
    173  1.1  cgd 				 * found */
    174  1.1  cgd {
    175  1.1  cgd     GNode         *gn;	      /* node in that element */
    176  1.1  cgd     Hash_Entry	  *he;	      /* New or used hash entry for node */
    177  1.1  cgd     Boolean	  isNew;      /* Set TRUE if Hash_CreateEntry had to create */
    178  1.1  cgd 			      /* an entry for the node */
    179  1.1  cgd 
    180  1.1  cgd 
    181  1.1  cgd     if (flags & TARG_CREATE) {
    182  1.1  cgd 	he = Hash_CreateEntry (&targets, name, &isNew);
    183  1.1  cgd 	if (isNew) {
    184  1.1  cgd 	    gn = Targ_NewGN (name);
    185  1.1  cgd 	    Hash_SetValue (he, gn);
    186  1.1  cgd 	    (void) Lst_AtEnd (allTargets, (ClientData)gn);
    187  1.1  cgd 	}
    188  1.1  cgd     } else {
    189  1.1  cgd 	he = Hash_FindEntry (&targets, name);
    190  1.1  cgd     }
    191  1.1  cgd 
    192  1.1  cgd     if (he == (Hash_Entry *) NULL) {
    193  1.1  cgd 	return (NILGNODE);
    194  1.1  cgd     } else {
    195  1.1  cgd 	return ((GNode *) Hash_GetValue (he));
    196  1.1  cgd     }
    197  1.1  cgd }
    198  1.1  cgd 
    199  1.1  cgd /*-
    200  1.1  cgd  *-----------------------------------------------------------------------
    201  1.1  cgd  * Targ_FindList --
    202  1.1  cgd  *	Make a complete list of GNodes from the given list of names
    203  1.1  cgd  *
    204  1.1  cgd  * Results:
    205  1.1  cgd  *	A complete list of graph nodes corresponding to all instances of all
    206  1.1  cgd  *	the names in names.
    207  1.1  cgd  *
    208  1.1  cgd  * Side Effects:
    209  1.1  cgd  *	If flags is TARG_CREATE, nodes will be created for all names in
    210  1.1  cgd  *	names which do not yet have graph nodes. If flags is TARG_NOCREATE,
    211  1.1  cgd  *	an error message will be printed for each name which can't be found.
    212  1.1  cgd  * -----------------------------------------------------------------------
    213  1.1  cgd  */
    214  1.1  cgd Lst
    215  1.1  cgd Targ_FindList (names, flags)
    216  1.1  cgd     Lst        	   names;	/* list of names to find */
    217  1.1  cgd     int            flags;	/* flags used if no node is found for a given
    218  1.1  cgd 				 * name */
    219  1.1  cgd {
    220  1.1  cgd     Lst            nodes;	/* result list */
    221  1.1  cgd     register LstNode  ln;		/* name list element */
    222  1.1  cgd     register GNode *gn;		/* node in tLn */
    223  1.1  cgd     char    	  *name;
    224  1.1  cgd 
    225  1.1  cgd     nodes = Lst_Init (FALSE);
    226  1.1  cgd 
    227  1.1  cgd     if (Lst_Open (names) == FAILURE) {
    228  1.1  cgd 	return (nodes);
    229  1.1  cgd     }
    230  1.1  cgd     while ((ln = Lst_Next (names)) != NILLNODE) {
    231  1.1  cgd 	name = (char *)Lst_Datum(ln);
    232  1.1  cgd 	gn = Targ_FindNode (name, flags);
    233  1.1  cgd 	if (gn != NILGNODE) {
    234  1.1  cgd 	    /*
    235  1.1  cgd 	     * Note: Lst_AtEnd must come before the Lst_Concat so the nodes
    236  1.1  cgd 	     * are added to the list in the order in which they were
    237  1.1  cgd 	     * encountered in the makefile.
    238  1.1  cgd 	     */
    239  1.1  cgd 	    (void) Lst_AtEnd (nodes, (ClientData)gn);
    240  1.1  cgd 	    if (gn->type & OP_DOUBLEDEP) {
    241  1.1  cgd 		(void)Lst_Concat (nodes, gn->cohorts, LST_CONCNEW);
    242  1.1  cgd 	    }
    243  1.1  cgd 	} else if (flags == TARG_NOCREATE) {
    244  1.1  cgd 	    Error ("\"%s\" -- target unknown.", name);
    245  1.1  cgd 	}
    246  1.1  cgd     }
    247  1.1  cgd     Lst_Close (names);
    248  1.1  cgd     return (nodes);
    249  1.1  cgd }
    250  1.1  cgd 
    251  1.1  cgd /*-
    252  1.1  cgd  *-----------------------------------------------------------------------
    253  1.1  cgd  * Targ_Ignore  --
    254  1.1  cgd  *	Return true if should ignore errors when creating gn
    255  1.1  cgd  *
    256  1.1  cgd  * Results:
    257  1.1  cgd  *	TRUE if should ignore errors
    258  1.1  cgd  *
    259  1.1  cgd  * Side Effects:
    260  1.1  cgd  *	None
    261  1.1  cgd  *-----------------------------------------------------------------------
    262  1.1  cgd  */
    263  1.1  cgd Boolean
    264  1.1  cgd Targ_Ignore (gn)
    265  1.1  cgd     GNode          *gn;		/* node to check for */
    266  1.1  cgd {
    267  1.1  cgd     if (ignoreErrors || gn->type & OP_IGNORE) {
    268  1.1  cgd 	return (TRUE);
    269  1.1  cgd     } else {
    270  1.1  cgd 	return (FALSE);
    271  1.1  cgd     }
    272  1.1  cgd }
    273  1.1  cgd 
    274  1.1  cgd /*-
    275  1.1  cgd  *-----------------------------------------------------------------------
    276  1.1  cgd  * Targ_Silent  --
    277  1.1  cgd  *	Return true if be silent when creating gn
    278  1.1  cgd  *
    279  1.1  cgd  * Results:
    280  1.1  cgd  *	TRUE if should be silent
    281  1.1  cgd  *
    282  1.1  cgd  * Side Effects:
    283  1.1  cgd  *	None
    284  1.1  cgd  *-----------------------------------------------------------------------
    285  1.1  cgd  */
    286  1.1  cgd Boolean
    287  1.1  cgd Targ_Silent (gn)
    288  1.1  cgd     GNode          *gn;		/* node to check for */
    289  1.1  cgd {
    290  1.1  cgd     if (beSilent || gn->type & OP_SILENT) {
    291  1.1  cgd 	return (TRUE);
    292  1.1  cgd     } else {
    293  1.1  cgd 	return (FALSE);
    294  1.1  cgd     }
    295  1.1  cgd }
    296  1.1  cgd 
    297  1.1  cgd /*-
    298  1.1  cgd  *-----------------------------------------------------------------------
    299  1.1  cgd  * Targ_Precious --
    300  1.1  cgd  *	See if the given target is precious
    301  1.1  cgd  *
    302  1.1  cgd  * Results:
    303  1.1  cgd  *	TRUE if it is precious. FALSE otherwise
    304  1.1  cgd  *
    305  1.1  cgd  * Side Effects:
    306  1.1  cgd  *	None
    307  1.1  cgd  *-----------------------------------------------------------------------
    308  1.1  cgd  */
    309  1.1  cgd Boolean
    310  1.1  cgd Targ_Precious (gn)
    311  1.1  cgd     GNode          *gn;		/* the node to check */
    312  1.1  cgd {
    313  1.1  cgd     if (allPrecious || (gn->type & (OP_PRECIOUS|OP_DOUBLEDEP))) {
    314  1.1  cgd 	return (TRUE);
    315  1.1  cgd     } else {
    316  1.1  cgd 	return (FALSE);
    317  1.1  cgd     }
    318  1.1  cgd }
    319  1.1  cgd 
    320  1.1  cgd /******************* DEBUG INFO PRINTING ****************/
    321  1.1  cgd 
    322  1.1  cgd static GNode	  *mainTarg;	/* the main target, as set by Targ_SetMain */
    323  1.1  cgd /*-
    324  1.1  cgd  *-----------------------------------------------------------------------
    325  1.1  cgd  * Targ_SetMain --
    326  1.1  cgd  *	Set our idea of the main target we'll be creating. Used for
    327  1.1  cgd  *	debugging output.
    328  1.1  cgd  *
    329  1.1  cgd  * Results:
    330  1.1  cgd  *	None.
    331  1.1  cgd  *
    332  1.1  cgd  * Side Effects:
    333  1.1  cgd  *	"mainTarg" is set to the main target's node.
    334  1.1  cgd  *-----------------------------------------------------------------------
    335  1.1  cgd  */
    336  1.1  cgd void
    337  1.1  cgd Targ_SetMain (gn)
    338  1.1  cgd     GNode   *gn;  	/* The main target we'll create */
    339  1.1  cgd {
    340  1.1  cgd     mainTarg = gn;
    341  1.1  cgd }
    342  1.1  cgd 
    343  1.1  cgd static int
    344  1.1  cgd TargPrintName (gn, ppath)
    345  1.1  cgd     GNode          *gn;
    346  1.1  cgd     int		    ppath;
    347  1.1  cgd {
    348  1.1  cgd     printf ("%s ", gn->name);
    349  1.1  cgd #ifdef notdef
    350  1.1  cgd     if (ppath) {
    351  1.1  cgd 	if (gn->path) {
    352  1.1  cgd 	    printf ("[%s]  ", gn->path);
    353  1.1  cgd 	}
    354  1.1  cgd 	if (gn == mainTarg) {
    355  1.1  cgd 	    printf ("(MAIN NAME)  ");
    356  1.1  cgd 	}
    357  1.1  cgd     }
    358  1.1  cgd #endif notdef
    359  1.1  cgd     return (0);
    360  1.1  cgd }
    361  1.1  cgd 
    362  1.1  cgd 
    363  1.1  cgd int
    364  1.1  cgd Targ_PrintCmd (cmd)
    365  1.1  cgd     char           *cmd;
    366  1.1  cgd {
    367  1.1  cgd     printf ("\t%s\n", cmd);
    368  1.1  cgd     return (0);
    369  1.1  cgd }
    370  1.1  cgd 
    371  1.1  cgd /*-
    372  1.1  cgd  *-----------------------------------------------------------------------
    373  1.1  cgd  * Targ_FmtTime --
    374  1.1  cgd  *	Format a modification time in some reasonable way and return it.
    375  1.1  cgd  *
    376  1.1  cgd  * Results:
    377  1.1  cgd  *	The time reformatted.
    378  1.1  cgd  *
    379  1.1  cgd  * Side Effects:
    380  1.1  cgd  *	The time is placed in a static area, so it is overwritten
    381  1.1  cgd  *	with each call.
    382  1.1  cgd  *
    383  1.1  cgd  *-----------------------------------------------------------------------
    384  1.1  cgd  */
    385  1.1  cgd char *
    386  1.1  cgd Targ_FmtTime (time)
    387  1.1  cgd     time_t    time;
    388  1.1  cgd {
    389  1.1  cgd     struct tm	  	*parts;
    390  1.1  cgd     static char	  	buf[40];
    391  1.1  cgd     static char	  	*months[] = {
    392  1.1  cgd 	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
    393  1.1  cgd 	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    394  1.1  cgd     };
    395  1.1  cgd 
    396  1.1  cgd     parts = localtime(&time);
    397  1.1  cgd 
    398  1.1  cgd     sprintf (buf, "%d:%02d:%02d %s %d, 19%d",
    399  1.1  cgd 	     parts->tm_hour, parts->tm_min, parts->tm_sec,
    400  1.1  cgd 	     months[parts->tm_mon], parts->tm_mday, parts->tm_year);
    401  1.1  cgd     return(buf);
    402  1.1  cgd }
    403  1.1  cgd 
    404  1.1  cgd /*-
    405  1.1  cgd  *-----------------------------------------------------------------------
    406  1.1  cgd  * Targ_PrintType --
    407  1.1  cgd  *	Print out a type field giving only those attributes the user can
    408  1.1  cgd  *	set.
    409  1.1  cgd  *
    410  1.1  cgd  * Results:
    411  1.1  cgd  *
    412  1.1  cgd  * Side Effects:
    413  1.1  cgd  *
    414  1.1  cgd  *-----------------------------------------------------------------------
    415  1.1  cgd  */
    416  1.1  cgd void
    417  1.1  cgd Targ_PrintType (type)
    418  1.1  cgd     register int    type;
    419  1.1  cgd {
    420  1.1  cgd     register int    tbit;
    421  1.1  cgd 
    422  1.1  cgd #ifdef __STDC__
    423  1.1  cgd #define PRINTBIT(attr)	case CONCAT(OP_,attr): printf("." #attr " "); break
    424  1.1  cgd #define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG)) printf("." #attr " "); break
    425  1.1  cgd #else
    426  1.1  cgd #define PRINTBIT(attr) 	case CONCAT(OP_,attr): printf(".attr "); break
    427  1.1  cgd #define PRINTDBIT(attr)	case CONCAT(OP_,attr): if (DEBUG(TARG)) printf(".attr "); break
    428  1.1  cgd #endif /* __STDC__ */
    429  1.1  cgd 
    430  1.1  cgd     type &= ~OP_OPMASK;
    431  1.1  cgd 
    432  1.1  cgd     while (type) {
    433  1.1  cgd 	tbit = 1 << (ffs(type) - 1);
    434  1.1  cgd 	type &= ~tbit;
    435  1.1  cgd 
    436  1.1  cgd 	switch(tbit) {
    437  1.1  cgd 	    PRINTBIT(OPTIONAL);
    438  1.1  cgd 	    PRINTBIT(USE);
    439  1.1  cgd 	    PRINTBIT(EXEC);
    440  1.1  cgd 	    PRINTBIT(IGNORE);
    441  1.1  cgd 	    PRINTBIT(PRECIOUS);
    442  1.1  cgd 	    PRINTBIT(SILENT);
    443  1.1  cgd 	    PRINTBIT(MAKE);
    444  1.1  cgd 	    PRINTBIT(JOIN);
    445  1.1  cgd 	    PRINTBIT(INVISIBLE);
    446  1.1  cgd 	    PRINTBIT(NOTMAIN);
    447  1.1  cgd 	    PRINTDBIT(LIB);
    448  1.1  cgd 	    /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
    449  1.1  cgd 	    case OP_MEMBER: if (DEBUG(TARG)) printf(".MEMBER "); break;
    450  1.1  cgd 	    PRINTDBIT(ARCHV);
    451  1.1  cgd 	}
    452  1.1  cgd     }
    453  1.1  cgd }
    454  1.1  cgd 
    455  1.1  cgd /*-
    456  1.1  cgd  *-----------------------------------------------------------------------
    457  1.1  cgd  * TargPrintNode --
    458  1.1  cgd  *	print the contents of a node
    459  1.1  cgd  *-----------------------------------------------------------------------
    460  1.1  cgd  */
    461  1.1  cgd static int
    462  1.1  cgd TargPrintNode (gn, pass)
    463  1.1  cgd     GNode         *gn;
    464  1.1  cgd     int	    	  pass;
    465  1.1  cgd {
    466  1.1  cgd     if (!OP_NOP(gn->type)) {
    467  1.1  cgd 	printf("#\n");
    468  1.1  cgd 	if (gn == mainTarg) {
    469  1.1  cgd 	    printf("# *** MAIN TARGET ***\n");
    470  1.1  cgd 	}
    471  1.1  cgd 	if (pass == 2) {
    472  1.1  cgd 	    if (gn->unmade) {
    473  1.1  cgd 		printf("# %d unmade children\n", gn->unmade);
    474  1.1  cgd 	    } else {
    475  1.1  cgd 		printf("# No unmade children\n");
    476  1.1  cgd 	    }
    477  1.1  cgd 	    if (! (gn->type & (OP_JOIN|OP_USE|OP_EXEC))) {
    478  1.1  cgd 		if (gn->mtime != 0) {
    479  1.1  cgd 		    printf("# last modified %s: %s\n",
    480  1.1  cgd 			      Targ_FmtTime(gn->mtime),
    481  1.1  cgd 			      (gn->made == UNMADE ? "unmade" :
    482  1.1  cgd 			       (gn->made == MADE ? "made" :
    483  1.1  cgd 				(gn->made == UPTODATE ? "up-to-date" :
    484  1.1  cgd 				 "error when made"))));
    485  1.1  cgd 		} else if (gn->made != UNMADE) {
    486  1.1  cgd 		    printf("# non-existent (maybe): %s\n",
    487  1.1  cgd 			      (gn->made == MADE ? "made" :
    488  1.1  cgd 			       (gn->made == UPTODATE ? "up-to-date" :
    489  1.1  cgd 				(gn->made == ERROR ? "error when made" :
    490  1.1  cgd 				 "aborted"))));
    491  1.1  cgd 		} else {
    492  1.1  cgd 		    printf("# unmade\n");
    493  1.1  cgd 		}
    494  1.1  cgd 	    }
    495  1.1  cgd 	    if (!Lst_IsEmpty (gn->iParents)) {
    496  1.1  cgd 		printf("# implicit parents: ");
    497  1.1  cgd 		Lst_ForEach (gn->iParents, TargPrintName, (ClientData)0);
    498  1.1  cgd 		putc ('\n', stdout);
    499  1.1  cgd 	    }
    500  1.1  cgd 	}
    501  1.1  cgd 	if (!Lst_IsEmpty (gn->parents)) {
    502  1.1  cgd 	    printf("# parents: ");
    503  1.1  cgd 	    Lst_ForEach (gn->parents, TargPrintName, (ClientData)0);
    504  1.1  cgd 	    putc ('\n', stdout);
    505  1.1  cgd 	}
    506  1.1  cgd 
    507  1.1  cgd 	printf("%-16s", gn->name);
    508  1.1  cgd 	switch (gn->type & OP_OPMASK) {
    509  1.1  cgd 	    case OP_DEPENDS:
    510  1.1  cgd 		printf(": "); break;
    511  1.1  cgd 	    case OP_FORCE:
    512  1.1  cgd 		printf("! "); break;
    513  1.1  cgd 	    case OP_DOUBLEDEP:
    514  1.1  cgd 		printf(":: "); break;
    515  1.1  cgd 	}
    516  1.1  cgd 	Targ_PrintType (gn->type);
    517  1.1  cgd 	Lst_ForEach (gn->children, TargPrintName, (ClientData)0);
    518  1.1  cgd 	putc ('\n', stdout);
    519  1.1  cgd 	Lst_ForEach (gn->commands, Targ_PrintCmd, (ClientData)0);
    520  1.1  cgd 	printf("\n\n");
    521  1.1  cgd 	if (gn->type & OP_DOUBLEDEP) {
    522  1.1  cgd 	    Lst_ForEach (gn->cohorts, TargPrintNode, (ClientData)pass);
    523  1.1  cgd 	}
    524  1.1  cgd     }
    525  1.1  cgd     return (0);
    526  1.1  cgd }
    527  1.1  cgd 
    528  1.1  cgd /*-
    529  1.1  cgd  *-----------------------------------------------------------------------
    530  1.1  cgd  * TargPrintOnlySrc --
    531  1.1  cgd  *	Print only those targets that are just a source.
    532  1.1  cgd  *
    533  1.1  cgd  * Results:
    534  1.1  cgd  *	0.
    535  1.1  cgd  *
    536  1.1  cgd  * Side Effects:
    537  1.1  cgd  *	The name of each file is printed preceeded by #\t
    538  1.1  cgd  *
    539  1.1  cgd  *-----------------------------------------------------------------------
    540  1.1  cgd  */
    541  1.1  cgd static int
    542  1.1  cgd TargPrintOnlySrc(gn)
    543  1.1  cgd     GNode   	  *gn;
    544  1.1  cgd {
    545  1.1  cgd     if (OP_NOP(gn->type)) {
    546  1.1  cgd 	printf("#\t%s [%s]\n", gn->name,
    547  1.1  cgd 		  gn->path ? gn->path : gn->name);
    548  1.1  cgd     }
    549  1.1  cgd     return (0);
    550  1.1  cgd }
    551  1.1  cgd 
    552  1.1  cgd /*-
    553  1.1  cgd  *-----------------------------------------------------------------------
    554  1.1  cgd  * Targ_PrintGraph --
    555  1.1  cgd  *	print the entire graph. heh heh
    556  1.1  cgd  *
    557  1.1  cgd  * Results:
    558  1.1  cgd  *	none
    559  1.1  cgd  *
    560  1.1  cgd  * Side Effects:
    561  1.1  cgd  *	lots o' output
    562  1.1  cgd  *-----------------------------------------------------------------------
    563  1.1  cgd  */
    564  1.1  cgd Targ_PrintGraph (pass)
    565  1.1  cgd     int	    pass; 	/* Which pass this is. 1 => no processing
    566  1.1  cgd 			 * 2 => processing done */
    567  1.1  cgd {
    568  1.1  cgd     printf("#*** Input graph:\n");
    569  1.1  cgd     Lst_ForEach (allTargets, TargPrintNode, (ClientData)pass);
    570  1.1  cgd     printf("\n\n");
    571  1.1  cgd     printf("#\n#   Files that are only sources:\n");
    572  1.1  cgd     Lst_ForEach (allTargets, TargPrintOnlySrc);
    573  1.1  cgd     printf("#*** Global Variables:\n");
    574  1.1  cgd     Var_Dump (VAR_GLOBAL);
    575  1.1  cgd     printf("#*** Command-line Variables:\n");
    576  1.1  cgd     Var_Dump (VAR_CMD);
    577  1.1  cgd     printf("\n");
    578  1.1  cgd     Dir_PrintDirectories();
    579  1.1  cgd     printf("\n");
    580  1.1  cgd     Suff_PrintAll();
    581  1.1  cgd }
    582