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