targ.c revision 1.89 1 1.89 rillig /* $NetBSD: targ.c,v 1.89 2020/09/22 04:05:41 rillig Exp $ */
2 1.5 christos
3 1.1 cgd /*
4 1.10 christos * Copyright (c) 1988, 1989, 1990, 1993
5 1.10 christos * The Regents of the University of California. All rights reserved.
6 1.30 agc *
7 1.30 agc * This code is derived from software contributed to Berkeley by
8 1.30 agc * Adam de Boor.
9 1.30 agc *
10 1.30 agc * Redistribution and use in source and binary forms, with or without
11 1.30 agc * modification, are permitted provided that the following conditions
12 1.30 agc * are met:
13 1.30 agc * 1. Redistributions of source code must retain the above copyright
14 1.30 agc * notice, this list of conditions and the following disclaimer.
15 1.30 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.30 agc * notice, this list of conditions and the following disclaimer in the
17 1.30 agc * documentation and/or other materials provided with the distribution.
18 1.30 agc * 3. Neither the name of the University nor the names of its contributors
19 1.30 agc * may be used to endorse or promote products derived from this software
20 1.30 agc * without specific prior written permission.
21 1.30 agc *
22 1.30 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.30 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.30 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.30 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.30 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.30 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.30 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.30 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.30 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.30 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.30 agc * SUCH DAMAGE.
33 1.30 agc */
34 1.30 agc
35 1.30 agc /*
36 1.1 cgd * Copyright (c) 1989 by Berkeley Softworks
37 1.1 cgd * All rights reserved.
38 1.1 cgd *
39 1.1 cgd * This code is derived from software contributed to Berkeley by
40 1.1 cgd * Adam de Boor.
41 1.1 cgd *
42 1.1 cgd * Redistribution and use in source and binary forms, with or without
43 1.1 cgd * modification, are permitted provided that the following conditions
44 1.1 cgd * are met:
45 1.1 cgd * 1. Redistributions of source code must retain the above copyright
46 1.1 cgd * notice, this list of conditions and the following disclaimer.
47 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
48 1.1 cgd * notice, this list of conditions and the following disclaimer in the
49 1.1 cgd * documentation and/or other materials provided with the distribution.
50 1.1 cgd * 3. All advertising materials mentioning features or use of this software
51 1.1 cgd * must display the following acknowledgement:
52 1.1 cgd * This product includes software developed by the University of
53 1.1 cgd * California, Berkeley and its contributors.
54 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
55 1.1 cgd * may be used to endorse or promote products derived from this software
56 1.1 cgd * without specific prior written permission.
57 1.1 cgd *
58 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 cgd * SUCH DAMAGE.
69 1.1 cgd */
70 1.1 cgd
71 1.1 cgd /*-
72 1.1 cgd * targ.c --
73 1.1 cgd * Functions for maintaining the Lst allTargets. Target nodes are
74 1.77 rillig * kept in two structures: a Lst and a hash table.
75 1.1 cgd *
76 1.1 cgd * Interface:
77 1.1 cgd * Targ_Init Initialization procedure.
78 1.1 cgd *
79 1.4 jtc * Targ_End Cleanup the module
80 1.4 jtc *
81 1.12 christos * Targ_List Return the list of all targets so far.
82 1.12 christos *
83 1.1 cgd * Targ_NewGN Create a new GNode for the passed target
84 1.1 cgd * (string). The node is *not* placed in the
85 1.1 cgd * hash table, though all its fields are
86 1.1 cgd * initialized.
87 1.1 cgd *
88 1.1 cgd * Targ_FindNode Find the node for a given target, creating
89 1.1 cgd * and storing it if it doesn't exist and the
90 1.1 cgd * flags are right (TARG_CREATE)
91 1.1 cgd *
92 1.1 cgd * Targ_FindList Given a list of names, find nodes for all
93 1.1 cgd * of them. If a name doesn't exist and the
94 1.1 cgd * TARG_NOCREATE flag was given, an error message
95 1.1 cgd * is printed. Else, if a name doesn't exist,
96 1.1 cgd * its node is created.
97 1.1 cgd *
98 1.1 cgd * Targ_Ignore Return TRUE if errors should be ignored when
99 1.1 cgd * creating the given target.
100 1.1 cgd *
101 1.1 cgd * Targ_Silent Return TRUE if we should be silent when
102 1.1 cgd * creating the given target.
103 1.1 cgd *
104 1.1 cgd * Targ_Precious Return TRUE if the target is precious and
105 1.1 cgd * should not be removed if we are interrupted.
106 1.1 cgd *
107 1.42 apb * Targ_Propagate Propagate information between related
108 1.42 apb * nodes. Should be called after the
109 1.42 apb * makefiles are parsed but before any
110 1.42 apb * action is taken.
111 1.42 apb *
112 1.1 cgd * Debugging:
113 1.1 cgd * Targ_PrintGraph Print out the entire graphm all variables
114 1.1 cgd * and statistics for the directory cache. Should
115 1.1 cgd * print something for suffixes, too, but...
116 1.1 cgd */
117 1.1 cgd
118 1.1 cgd #include <stdio.h>
119 1.1 cgd #include <time.h>
120 1.28 wiz
121 1.1 cgd #include "make.h"
122 1.3 cgd #include "dir.h"
123 1.1 cgd
124 1.88 rillig /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
125 1.89 rillig MAKE_RCSID("$NetBSD: targ.c,v 1.89 2020/09/22 04:05:41 rillig Exp $");
126 1.88 rillig
127 1.89 rillig static GNodeList *allTargets; /* the list of all targets found so far */
128 1.18 mycroft #ifdef CLEANUP
129 1.89 rillig static GNodeList *allGNs; /* List of all the GNodes */
130 1.18 mycroft #endif
131 1.1 cgd static Hash_Table targets; /* a hash table of same */
132 1.1 cgd
133 1.55 dsl static int TargPrintOnlySrc(void *, void *);
134 1.18 mycroft #ifdef CLEANUP
135 1.55 dsl static void TargFreeGN(void *);
136 1.18 mycroft #endif
137 1.4 jtc
138 1.1 cgd void
139 1.28 wiz Targ_Init(void)
140 1.1 cgd {
141 1.65 rillig allTargets = Lst_Init();
142 1.83 rillig Hash_InitTable(&targets);
143 1.1 cgd }
144 1.1 cgd
145 1.4 jtc void
146 1.28 wiz Targ_End(void)
147 1.4 jtc {
148 1.64 sjg Targ_Stats();
149 1.18 mycroft #ifdef CLEANUP
150 1.76 rillig Lst_Free(allTargets);
151 1.73 rillig if (allGNs != NULL)
152 1.76 rillig Lst_Destroy(allGNs, TargFreeGN);
153 1.4 jtc Hash_DeleteTable(&targets);
154 1.18 mycroft #endif
155 1.12 christos }
156 1.12 christos
157 1.64 sjg void
158 1.64 sjg Targ_Stats(void)
159 1.64 sjg {
160 1.64 sjg Hash_DebugStats(&targets, "targets");
161 1.64 sjg }
162 1.64 sjg
163 1.77 rillig /* Return the list of all targets. */
164 1.89 rillig GNodeList *
165 1.28 wiz Targ_List(void)
166 1.12 christos {
167 1.12 christos return allTargets;
168 1.4 jtc }
169 1.4 jtc
170 1.77 rillig /* Create and initialize a new graph node. The gnode is added to the list of
171 1.77 rillig * all gnodes.
172 1.1 cgd *
173 1.28 wiz * Input:
174 1.77 rillig * name the name of the node, such as "clean", "src.c"
175 1.1 cgd */
176 1.1 cgd GNode *
177 1.29 christos Targ_NewGN(const char *name)
178 1.1 cgd {
179 1.28 wiz GNode *gn;
180 1.1 cgd
181 1.53 joerg gn = bmake_malloc(sizeof(GNode));
182 1.53 joerg gn->name = bmake_strdup(name);
183 1.11 christos gn->uname = NULL;
184 1.29 christos gn->path = NULL;
185 1.77 rillig gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
186 1.1 cgd gn->unmade = 0;
187 1.27 pk gn->unmade_cohorts = 0;
188 1.45 dsl gn->cohort_num[0] = 0;
189 1.27 pk gn->centurion = NULL;
190 1.1 cgd gn->made = UNMADE;
191 1.16 christos gn->flags = 0;
192 1.56 christos gn->checked = 0;
193 1.56 christos gn->mtime = 0;
194 1.56 christos gn->cmgn = NULL;
195 1.80 rillig gn->implicitParents = Lst_Init();
196 1.65 rillig gn->cohorts = Lst_Init();
197 1.65 rillig gn->parents = Lst_Init();
198 1.65 rillig gn->children = Lst_Init();
199 1.65 rillig gn->order_pred = Lst_Init();
200 1.65 rillig gn->order_succ = Lst_Init();
201 1.83 rillig Hash_InitTable(&gn->context);
202 1.65 rillig gn->commands = Lst_Init();
203 1.3 cgd gn->suffix = NULL;
204 1.77 rillig gn->fname = NULL;
205 1.21 christos gn->lineno = 0;
206 1.1 cgd
207 1.18 mycroft #ifdef CLEANUP
208 1.4 jtc if (allGNs == NULL)
209 1.65 rillig allGNs = Lst_Init();
210 1.76 rillig Lst_Append(allGNs, gn);
211 1.18 mycroft #endif
212 1.4 jtc
213 1.63 rillig return gn;
214 1.1 cgd }
215 1.1 cgd
216 1.18 mycroft #ifdef CLEANUP
217 1.4 jtc static void
218 1.55 dsl TargFreeGN(void *gnp)
219 1.4 jtc {
220 1.37 christos GNode *gn = (GNode *)gnp;
221 1.4 jtc
222 1.4 jtc free(gn->name);
223 1.61 christos free(gn->uname);
224 1.61 christos free(gn->path);
225 1.4 jtc
226 1.80 rillig Lst_Free(gn->implicitParents);
227 1.76 rillig Lst_Free(gn->cohorts);
228 1.76 rillig Lst_Free(gn->parents);
229 1.76 rillig Lst_Free(gn->children);
230 1.76 rillig Lst_Free(gn->order_succ);
231 1.76 rillig Lst_Free(gn->order_pred);
232 1.17 mycroft Hash_DeleteTable(&gn->context);
233 1.76 rillig Lst_Free(gn->commands);
234 1.77 rillig
235 1.77 rillig /* XXX: does gn->suffix need to be freed? It is reference-counted. */
236 1.77 rillig /* gn->fname points to name allocated when file was opened, don't free */
237 1.77 rillig
238 1.36 christos free(gn);
239 1.4 jtc }
240 1.18 mycroft #endif
241 1.4 jtc
242 1.4 jtc
243 1.77 rillig /* Find a node in the list using the given name for matching.
244 1.77 rillig * If the node is created, it is added to the .ALLTARGETS list.
245 1.1 cgd *
246 1.28 wiz * Input:
247 1.28 wiz * name the name to find
248 1.77 rillig * flags flags governing events when target not found
249 1.28 wiz *
250 1.1 cgd * Results:
251 1.77 rillig * The node in the list if it was. If it wasn't, return NULL if
252 1.1 cgd * flags was TARG_NOCREATE or the newly created and initialized node
253 1.1 cgd * if it was TARG_CREATE
254 1.1 cgd */
255 1.1 cgd GNode *
256 1.29 christos Targ_FindNode(const char *name, int flags)
257 1.1 cgd {
258 1.1 cgd GNode *gn; /* node in that element */
259 1.60 manu Hash_Entry *he = NULL; /* New or used hash entry for node */
260 1.1 cgd Boolean isNew; /* Set TRUE if Hash_CreateEntry had to create */
261 1.1 cgd /* an entry for the node */
262 1.1 cgd
263 1.45 dsl if (!(flags & (TARG_CREATE | TARG_NOHASH))) {
264 1.45 dsl he = Hash_FindEntry(&targets, name);
265 1.45 dsl if (he == NULL)
266 1.54 dsl return NULL;
267 1.45 dsl return (GNode *)Hash_GetValue(he);
268 1.45 dsl }
269 1.1 cgd
270 1.45 dsl if (!(flags & TARG_NOHASH)) {
271 1.34 christos he = Hash_CreateEntry(&targets, name, &isNew);
272 1.45 dsl if (!isNew)
273 1.45 dsl return (GNode *)Hash_GetValue(he);
274 1.1 cgd }
275 1.1 cgd
276 1.45 dsl gn = Targ_NewGN(name);
277 1.45 dsl if (!(flags & TARG_NOHASH))
278 1.45 dsl Hash_SetValue(he, gn);
279 1.45 dsl Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
280 1.76 rillig Lst_Append(allTargets, gn);
281 1.50 dsl if (doing_depend)
282 1.50 dsl gn->flags |= FROM_DEPEND;
283 1.45 dsl return gn;
284 1.1 cgd }
285 1.1 cgd
286 1.77 rillig /* Make a complete list of GNodes from the given list of names.
287 1.77 rillig * If flags is TARG_CREATE, nodes will be created for all names in
288 1.77 rillig * names which do not yet have graph nodes. If flags is TARG_NOCREATE,
289 1.77 rillig * an error message will be printed for each name which can't be found.
290 1.1 cgd *
291 1.28 wiz * Input:
292 1.28 wiz * name list of names to find
293 1.28 wiz * flags flags used if no node is found for a given name
294 1.28 wiz *
295 1.1 cgd * Results:
296 1.1 cgd * A complete list of graph nodes corresponding to all instances of all
297 1.10 christos * the names in names.
298 1.1 cgd */
299 1.89 rillig GNodeList *
300 1.89 rillig Targ_FindList(StringList *names, int flags)
301 1.1 cgd {
302 1.89 rillig GNodeList *nodes;
303 1.89 rillig StringListNode *ln;
304 1.1 cgd
305 1.65 rillig nodes = Lst_Init();
306 1.1 cgd
307 1.76 rillig Lst_Open(names);
308 1.76 rillig while ((ln = Lst_Next(names)) != NULL) {
309 1.89 rillig char *name = LstNode_Datum(ln);
310 1.89 rillig GNode *gn = Targ_FindNode(name, flags);
311 1.54 dsl if (gn != NULL) {
312 1.76 rillig Lst_Append(nodes, gn);
313 1.1 cgd } else if (flags == TARG_NOCREATE) {
314 1.34 christos Error("\"%s\" -- target unknown.", name);
315 1.1 cgd }
316 1.1 cgd }
317 1.76 rillig Lst_Close(names);
318 1.63 rillig return nodes;
319 1.1 cgd }
320 1.1 cgd
321 1.77 rillig /* Return true if should ignore errors when creating gn. */
322 1.1 cgd Boolean
323 1.28 wiz Targ_Ignore(GNode *gn)
324 1.1 cgd {
325 1.77 rillig return ignoreErrors || gn->type & OP_IGNORE;
326 1.1 cgd }
327 1.1 cgd
328 1.77 rillig /* Return true if be silent when creating gn. */
329 1.1 cgd Boolean
330 1.28 wiz Targ_Silent(GNode *gn)
331 1.1 cgd {
332 1.77 rillig return beSilent || gn->type & OP_SILENT;
333 1.1 cgd }
334 1.1 cgd
335 1.77 rillig /* See if the given target is precious. */
336 1.1 cgd Boolean
337 1.28 wiz Targ_Precious(GNode *gn)
338 1.1 cgd {
339 1.77 rillig return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
340 1.1 cgd }
341 1.1 cgd
342 1.1 cgd /******************* DEBUG INFO PRINTING ****************/
343 1.1 cgd
344 1.1 cgd static GNode *mainTarg; /* the main target, as set by Targ_SetMain */
345 1.77 rillig
346 1.77 rillig /* Set our idea of the main target we'll be creating. Used for debugging
347 1.77 rillig * output. */
348 1.1 cgd void
349 1.28 wiz Targ_SetMain(GNode *gn)
350 1.1 cgd {
351 1.1 cgd mainTarg = gn;
352 1.1 cgd }
353 1.1 cgd
354 1.86 rillig static void
355 1.89 rillig PrintNodeNames(GNodeList *gnodes)
356 1.1 cgd {
357 1.89 rillig GNodeListNode *node;
358 1.38 dsl
359 1.85 rillig for (node = Lst_First(gnodes); node != NULL; node = LstNode_Next(node)) {
360 1.85 rillig GNode *gn = LstNode_Datum(node);
361 1.85 rillig fprintf(debug_file, " %s%s", gn->name, gn->cohort_num);
362 1.85 rillig }
363 1.85 rillig }
364 1.38 dsl
365 1.85 rillig static void
366 1.89 rillig PrintNodeNamesLine(const char *label, GNodeList *gnodes)
367 1.85 rillig {
368 1.85 rillig if (Lst_IsEmpty(gnodes))
369 1.85 rillig return;
370 1.85 rillig fprintf(debug_file, "# %s:", label);
371 1.85 rillig PrintNodeNames(gnodes);
372 1.85 rillig fprintf(debug_file, "\n");
373 1.1 cgd }
374 1.1 cgd
375 1.84 rillig static int
376 1.84 rillig TargPrintCmd(void *cmd, void *dummy MAKE_ATTR_UNUSED)
377 1.1 cgd {
378 1.43 dsl fprintf(debug_file, "\t%s\n", (char *)cmd);
379 1.62 riastrad return 0;
380 1.1 cgd }
381 1.1 cgd
382 1.84 rillig void
383 1.84 rillig Targ_PrintCmds(GNode *gn)
384 1.84 rillig {
385 1.84 rillig Lst_ForEach(gn->commands, TargPrintCmd, NULL);
386 1.84 rillig }
387 1.84 rillig
388 1.77 rillig /* Format a modification time in some reasonable way and return it.
389 1.77 rillig * The time is placed in a static area, so it is overwritten with each call. */
390 1.1 cgd char *
391 1.28 wiz Targ_FmtTime(time_t tm)
392 1.1 cgd {
393 1.1 cgd struct tm *parts;
394 1.15 christos static char buf[128];
395 1.1 cgd
396 1.25 reinoud parts = localtime(&tm);
397 1.15 christos (void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
398 1.63 rillig return buf;
399 1.1 cgd }
400 1.10 christos
401 1.77 rillig /* Print out a type field giving only those attributes the user can set. */
402 1.1 cgd void
403 1.52 christos Targ_PrintType(int type)
404 1.1 cgd {
405 1.28 wiz int tbit;
406 1.10 christos
407 1.82 rillig #define PRINTBIT(attr) case CONCAT(OP_,attr): fprintf(debug_file, " ." #attr); break
408 1.82 rillig #define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))fprintf(debug_file, " ." #attr); break
409 1.1 cgd
410 1.1 cgd type &= ~OP_OPMASK;
411 1.1 cgd
412 1.1 cgd while (type) {
413 1.52 christos tbit = 1 << (ffs(type) - 1);
414 1.1 cgd type &= ~tbit;
415 1.1 cgd
416 1.1 cgd switch(tbit) {
417 1.1 cgd PRINTBIT(OPTIONAL);
418 1.1 cgd PRINTBIT(USE);
419 1.1 cgd PRINTBIT(EXEC);
420 1.1 cgd PRINTBIT(IGNORE);
421 1.1 cgd PRINTBIT(PRECIOUS);
422 1.1 cgd PRINTBIT(SILENT);
423 1.1 cgd PRINTBIT(MAKE);
424 1.1 cgd PRINTBIT(JOIN);
425 1.1 cgd PRINTBIT(INVISIBLE);
426 1.1 cgd PRINTBIT(NOTMAIN);
427 1.1 cgd PRINTDBIT(LIB);
428 1.1 cgd /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
429 1.82 rillig case OP_MEMBER: if (DEBUG(TARG))fprintf(debug_file, " .MEMBER"); break;
430 1.1 cgd PRINTDBIT(ARCHV);
431 1.26 pk PRINTDBIT(MADE);
432 1.26 pk PRINTDBIT(PHONY);
433 1.1 cgd }
434 1.1 cgd }
435 1.1 cgd }
436 1.1 cgd
437 1.45 dsl static const char *
438 1.71 rillig made_name(GNodeMade made)
439 1.45 dsl {
440 1.45 dsl switch (made) {
441 1.45 dsl case UNMADE: return "unmade";
442 1.45 dsl case DEFERRED: return "deferred";
443 1.45 dsl case REQUESTED: return "requested";
444 1.45 dsl case BEINGMADE: return "being made";
445 1.45 dsl case MADE: return "made";
446 1.45 dsl case UPTODATE: return "up-to-date";
447 1.45 dsl case ERROR: return "error when made";
448 1.45 dsl case ABORTED: return "aborted";
449 1.45 dsl default: return "unknown enum_made value";
450 1.45 dsl }
451 1.45 dsl }
452 1.45 dsl
453 1.87 rillig static int
454 1.87 rillig PrintNode(void *gnp, void *passp)
455 1.1 cgd {
456 1.87 rillig GNode *gn = gnp;
457 1.87 rillig int pass = *(const int *)passp;
458 1.45 dsl
459 1.72 rillig fprintf(debug_file, "# %s%s", gn->name, gn->cohort_num);
460 1.72 rillig GNode_FprintDetails(debug_file, ", ", gn, "\n");
461 1.45 dsl if (gn->flags == 0)
462 1.45 dsl return 0;
463 1.45 dsl
464 1.1 cgd if (!OP_NOP(gn->type)) {
465 1.43 dsl fprintf(debug_file, "#\n");
466 1.1 cgd if (gn == mainTarg) {
467 1.43 dsl fprintf(debug_file, "# *** MAIN TARGET ***\n");
468 1.1 cgd }
469 1.45 dsl if (pass >= 2) {
470 1.1 cgd if (gn->unmade) {
471 1.43 dsl fprintf(debug_file, "# %d unmade children\n", gn->unmade);
472 1.1 cgd } else {
473 1.43 dsl fprintf(debug_file, "# No unmade children\n");
474 1.1 cgd }
475 1.22 christos if (! (gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
476 1.1 cgd if (gn->mtime != 0) {
477 1.43 dsl fprintf(debug_file, "# last modified %s: %s\n",
478 1.1 cgd Targ_FmtTime(gn->mtime),
479 1.45 dsl made_name(gn->made));
480 1.1 cgd } else if (gn->made != UNMADE) {
481 1.43 dsl fprintf(debug_file, "# non-existent (maybe): %s\n",
482 1.45 dsl made_name(gn->made));
483 1.1 cgd } else {
484 1.43 dsl fprintf(debug_file, "# unmade\n");
485 1.1 cgd }
486 1.1 cgd }
487 1.85 rillig PrintNodeNamesLine("implicit parents", gn->implicitParents);
488 1.41 dsl } else {
489 1.41 dsl if (gn->unmade)
490 1.43 dsl fprintf(debug_file, "# %d unmade children\n", gn->unmade);
491 1.1 cgd }
492 1.85 rillig PrintNodeNamesLine("parents", gn->parents);
493 1.85 rillig PrintNodeNamesLine("order_pred", gn->order_pred);
494 1.85 rillig PrintNodeNamesLine("order_succ", gn->order_succ);
495 1.10 christos
496 1.43 dsl fprintf(debug_file, "%-16s", gn->name);
497 1.1 cgd switch (gn->type & OP_OPMASK) {
498 1.1 cgd case OP_DEPENDS:
499 1.82 rillig fprintf(debug_file, ":"); break;
500 1.1 cgd case OP_FORCE:
501 1.82 rillig fprintf(debug_file, "!"); break;
502 1.1 cgd case OP_DOUBLEDEP:
503 1.82 rillig fprintf(debug_file, "::"); break;
504 1.1 cgd }
505 1.34 christos Targ_PrintType(gn->type);
506 1.85 rillig PrintNodeNames(gn->children);
507 1.43 dsl fprintf(debug_file, "\n");
508 1.84 rillig Targ_PrintCmds(gn);
509 1.43 dsl fprintf(debug_file, "\n\n");
510 1.20 mycroft if (gn->type & OP_DOUBLEDEP) {
511 1.87 rillig Lst_ForEach(gn->cohorts, PrintNode, passp);
512 1.1 cgd }
513 1.1 cgd }
514 1.63 rillig return 0;
515 1.1 cgd }
516 1.1 cgd
517 1.87 rillig /* Print the contents of a node. */
518 1.87 rillig void
519 1.87 rillig Targ_PrintNode(GNode *gn, int pass)
520 1.87 rillig {
521 1.87 rillig PrintNode(gn, &pass);
522 1.87 rillig }
523 1.87 rillig
524 1.87 rillig void
525 1.89 rillig Targ_PrintNodes(GNodeList *gnodes, int pass)
526 1.87 rillig {
527 1.87 rillig Lst_ForEach(gnodes, PrintNode, &pass);
528 1.87 rillig }
529 1.87 rillig
530 1.77 rillig /* Print only those targets that are just a source.
531 1.77 rillig * The name of each file is printed, preceded by #\t. */
532 1.1 cgd static int
533 1.57 joerg TargPrintOnlySrc(void *gnp, void *dummy MAKE_ATTR_UNUSED)
534 1.4 jtc {
535 1.37 christos GNode *gn = (GNode *)gnp;
536 1.45 dsl if (!OP_NOP(gn->type))
537 1.45 dsl return 0;
538 1.4 jtc
539 1.82 rillig fprintf(debug_file, "#\t%s [%s]",
540 1.45 dsl gn->name, gn->path ? gn->path : gn->name);
541 1.45 dsl Targ_PrintType(gn->type);
542 1.45 dsl fprintf(debug_file, "\n");
543 1.45 dsl
544 1.45 dsl return 0;
545 1.1 cgd }
546 1.1 cgd
547 1.77 rillig /* Input:
548 1.77 rillig * pass 1 => before processing
549 1.77 rillig * 2 => after processing
550 1.77 rillig * 3 => after processing, an error occurred
551 1.1 cgd */
552 1.3 cgd void
553 1.28 wiz Targ_PrintGraph(int pass)
554 1.1 cgd {
555 1.43 dsl fprintf(debug_file, "#*** Input graph:\n");
556 1.87 rillig Lst_ForEach(allTargets, PrintNode, &pass);
557 1.43 dsl fprintf(debug_file, "\n\n");
558 1.43 dsl fprintf(debug_file, "#\n# Files that are only sources:\n");
559 1.76 rillig Lst_ForEach(allTargets, TargPrintOnlySrc, NULL);
560 1.43 dsl fprintf(debug_file, "#*** Global Variables:\n");
561 1.34 christos Var_Dump(VAR_GLOBAL);
562 1.43 dsl fprintf(debug_file, "#*** Command-line Variables:\n");
563 1.34 christos Var_Dump(VAR_CMD);
564 1.43 dsl fprintf(debug_file, "\n");
565 1.1 cgd Dir_PrintDirectories();
566 1.43 dsl fprintf(debug_file, "\n");
567 1.1 cgd Suff_PrintAll();
568 1.19 mycroft }
569 1.19 mycroft
570 1.78 rillig /* Propagate some type information to cohort nodes (those from the ::
571 1.78 rillig * dependency operator).
572 1.77 rillig *
573 1.78 rillig * Should be called after the makefiles are parsed but before any action is
574 1.78 rillig * taken. */
575 1.78 rillig void
576 1.78 rillig Targ_Propagate(void)
577 1.19 mycroft {
578 1.89 rillig GNodeListNode *pn, *cn;
579 1.45 dsl
580 1.78 rillig for (pn = Lst_First(allTargets); pn != NULL; pn = LstNode_Next(pn)) {
581 1.79 rillig GNode *pgn = LstNode_Datum(pn);
582 1.19 mycroft
583 1.78 rillig if (!(pgn->type & OP_DOUBLEDEP))
584 1.78 rillig continue;
585 1.42 apb
586 1.78 rillig for (cn = Lst_First(pgn->cohorts); cn != NULL; cn = LstNode_Next(cn)) {
587 1.79 rillig GNode *cgn = LstNode_Datum(cn);
588 1.42 apb
589 1.78 rillig cgn->type |= pgn->type & ~OP_OPMASK;
590 1.78 rillig }
591 1.78 rillig }
592 1.1 cgd }
593