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