targ.c revision 1.148 1 1.148 rillig /* $NetBSD: targ.c,v 1.148 2020/11/29 01:05:08 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.132 rillig /*
72 1.132 rillig * Maintaining the targets and sources, which are both implemented as GNode.
73 1.1 cgd *
74 1.1 cgd * Interface:
75 1.132 rillig * Targ_Init Initialize the module.
76 1.1 cgd *
77 1.132 rillig * Targ_End Clean up the module.
78 1.4 jtc *
79 1.106 rillig * Targ_List Return the list of all targets so far.
80 1.12 christos *
81 1.128 rillig * GNode_New Create a new GNode for the passed target
82 1.106 rillig * (string). The node is *not* placed in the
83 1.106 rillig * hash table, though all its fields are
84 1.106 rillig * initialized.
85 1.1 cgd *
86 1.106 rillig * Targ_FindNode Find the node, or return NULL.
87 1.98 rillig *
88 1.106 rillig * Targ_GetNode Find the node, or create it.
89 1.98 rillig *
90 1.106 rillig * Targ_NewInternalNode
91 1.106 rillig * Create an internal node.
92 1.1 cgd *
93 1.106 rillig * Targ_FindList Given a list of names, find nodes for all
94 1.106 rillig * of them, creating them as necessary.
95 1.1 cgd *
96 1.106 rillig * Targ_Ignore Return TRUE if errors should be ignored when
97 1.106 rillig * creating the given target.
98 1.1 cgd *
99 1.106 rillig * Targ_Silent Return TRUE if we should be silent when
100 1.106 rillig * creating the given target.
101 1.1 cgd *
102 1.106 rillig * Targ_Precious Return TRUE if the target is precious and
103 1.106 rillig * should not be removed if we are interrupted.
104 1.1 cgd *
105 1.106 rillig * Targ_Propagate Propagate information between related nodes.
106 1.106 rillig * Should be called after the makefiles are parsed
107 1.106 rillig * but before any action is taken.
108 1.42 apb *
109 1.1 cgd * Debugging:
110 1.106 rillig * Targ_PrintGraph
111 1.148 rillig * Print out the entire graph, all variables and
112 1.106 rillig * statistics for the directory cache. Should print
113 1.106 rillig * something for suffixes, too, but...
114 1.1 cgd */
115 1.1 cgd
116 1.111 rillig #include <time.h>
117 1.28 wiz
118 1.111 rillig #include "make.h"
119 1.111 rillig #include "dir.h"
120 1.1 cgd
121 1.88 rillig /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */
122 1.148 rillig MAKE_RCSID("$NetBSD: targ.c,v 1.148 2020/11/29 01:05:08 rillig Exp $");
123 1.88 rillig
124 1.136 rillig /*
125 1.136 rillig * All target nodes that appeared on the left-hand side of one of the
126 1.136 rillig * dependency operators ':', '::', '!'.
127 1.136 rillig */
128 1.148 rillig static GNodeList allTargets = LST_INIT;
129 1.133 rillig static HashTable allTargetsByName;
130 1.130 rillig
131 1.18 mycroft #ifdef CLEANUP
132 1.148 rillig static GNodeList allNodes = LST_INIT;
133 1.1 cgd
134 1.129 rillig static void GNode_Free(void *);
135 1.18 mycroft #endif
136 1.4 jtc
137 1.1 cgd void
138 1.28 wiz Targ_Init(void)
139 1.1 cgd {
140 1.133 rillig HashTable_Init(&allTargetsByName);
141 1.1 cgd }
142 1.1 cgd
143 1.4 jtc void
144 1.28 wiz Targ_End(void)
145 1.4 jtc {
146 1.64 sjg Targ_Stats();
147 1.18 mycroft #ifdef CLEANUP
148 1.148 rillig Lst_Done(&allTargets);
149 1.133 rillig HashTable_Done(&allTargetsByName);
150 1.148 rillig Lst_DoneCall(&allNodes, GNode_Free);
151 1.18 mycroft #endif
152 1.12 christos }
153 1.12 christos
154 1.64 sjg void
155 1.64 sjg Targ_Stats(void)
156 1.64 sjg {
157 1.133 rillig HashTable_DebugStats(&allTargetsByName, "targets");
158 1.64 sjg }
159 1.64 sjg
160 1.132 rillig /*
161 1.132 rillig * Return the list of all targets, which are all nodes that appear on the
162 1.132 rillig * left-hand side of a dependency declaration such as "target: source".
163 1.132 rillig * The returned list does not contain pure sources.
164 1.132 rillig */
165 1.89 rillig GNodeList *
166 1.28 wiz Targ_List(void)
167 1.12 christos {
168 1.148 rillig return &allTargets;
169 1.4 jtc }
170 1.4 jtc
171 1.132 rillig /* Create a new graph node, but don't register it anywhere.
172 1.1 cgd *
173 1.132 rillig * Graph nodes that appear on the left-hand side of a dependency line such
174 1.132 rillig * as "target: source" are called targets. XXX: In some cases (like the
175 1.132 rillig * .ALLTARGETS variable), all nodes are called targets as well, even if they
176 1.132 rillig * never appear on the left-hand side. This is a mistake.
177 1.132 rillig *
178 1.132 rillig * Typical names for graph nodes are:
179 1.132 rillig * "src.c" (an ordinary file)
180 1.132 rillig * "clean" (a .PHONY target)
181 1.132 rillig * ".END" (a special hook target)
182 1.132 rillig * "-lm" (a library)
183 1.132 rillig * "libc.a(isspace.o)" (an archive member)
184 1.1 cgd */
185 1.1 cgd GNode *
186 1.128 rillig GNode_New(const char *name)
187 1.1 cgd {
188 1.28 wiz GNode *gn;
189 1.1 cgd
190 1.127 rillig gn = bmake_malloc(sizeof *gn);
191 1.53 joerg gn->name = bmake_strdup(name);
192 1.11 christos gn->uname = NULL;
193 1.29 christos gn->path = NULL;
194 1.77 rillig gn->type = name[0] == '-' && name[1] == 'l' ? OP_LIB : 0;
195 1.134 rillig gn->flags = 0;
196 1.134 rillig gn->made = UNMADE;
197 1.106 rillig gn->unmade = 0;
198 1.106 rillig gn->mtime = 0;
199 1.122 rillig gn->youngestChild = NULL;
200 1.146 rillig Lst_Init(&gn->implicitParents);
201 1.143 rillig Lst_Init(&gn->parents);
202 1.143 rillig Lst_Init(&gn->children);
203 1.144 rillig Lst_Init(&gn->order_pred);
204 1.144 rillig Lst_Init(&gn->order_succ);
205 1.145 rillig Lst_Init(&gn->cohorts);
206 1.134 rillig gn->cohort_num[0] = '\0';
207 1.134 rillig gn->unmade_cohorts = 0;
208 1.134 rillig gn->centurion = NULL;
209 1.134 rillig gn->checked_seqno = 0;
210 1.139 rillig HashTable_Init(&gn->vars);
211 1.142 rillig Lst_Init(&gn->commands);
212 1.106 rillig gn->suffix = NULL;
213 1.106 rillig gn->fname = NULL;
214 1.106 rillig gn->lineno = 0;
215 1.1 cgd
216 1.18 mycroft #ifdef CLEANUP
217 1.148 rillig Lst_Append(&allNodes, gn);
218 1.18 mycroft #endif
219 1.4 jtc
220 1.63 rillig return gn;
221 1.1 cgd }
222 1.1 cgd
223 1.18 mycroft #ifdef CLEANUP
224 1.4 jtc static void
225 1.129 rillig GNode_Free(void *gnp)
226 1.4 jtc {
227 1.120 rillig GNode *gn = gnp;
228 1.4 jtc
229 1.4 jtc free(gn->name);
230 1.61 christos free(gn->uname);
231 1.61 christos free(gn->path);
232 1.134 rillig /* gn->youngestChild is not owned by this node. */
233 1.146 rillig Lst_Done(&gn->implicitParents); /* Do not free the nodes themselves, */
234 1.143 rillig Lst_Done(&gn->parents); /* as they are not owned by this node. */
235 1.143 rillig Lst_Done(&gn->children); /* likewise */
236 1.144 rillig Lst_Done(&gn->order_pred); /* likewise */
237 1.144 rillig Lst_Done(&gn->order_succ); /* likewise */
238 1.145 rillig Lst_Done(&gn->cohorts); /* likewise */
239 1.139 rillig HashTable_Done(&gn->vars); /* Do not free the variables themselves,
240 1.134 rillig * even though they are owned by this node.
241 1.134 rillig * XXX: they should probably be freed. */
242 1.142 rillig Lst_Done(&gn->commands); /* Do not free the commands themselves,
243 1.134 rillig * as they may be shared with other nodes. */
244 1.134 rillig /* gn->suffix is not owned by this node. */
245 1.134 rillig /* XXX: gn->suffix should be unreferenced here. This requires a thorough
246 1.134 rillig * check that the reference counting is done correctly in all places,
247 1.134 rillig * otherwise a suffix might be freed too early. */
248 1.77 rillig
249 1.36 christos free(gn);
250 1.4 jtc }
251 1.18 mycroft #endif
252 1.4 jtc
253 1.95 rillig /* Get the existing global node, or return NULL. */
254 1.95 rillig GNode *
255 1.95 rillig Targ_FindNode(const char *name)
256 1.95 rillig {
257 1.133 rillig return HashTable_FindValue(&allTargetsByName, name);
258 1.95 rillig }
259 1.95 rillig
260 1.95 rillig /* Get the existing global node, or create it. */
261 1.95 rillig GNode *
262 1.95 rillig Targ_GetNode(const char *name)
263 1.95 rillig {
264 1.96 rillig Boolean isNew;
265 1.133 rillig HashEntry *he = HashTable_CreateEntry(&allTargetsByName, name, &isNew);
266 1.96 rillig if (!isNew)
267 1.123 rillig return HashEntry_Get(he);
268 1.96 rillig
269 1.96 rillig {
270 1.96 rillig GNode *gn = Targ_NewInternalNode(name);
271 1.123 rillig HashEntry_Set(he, gn);
272 1.96 rillig return gn;
273 1.96 rillig }
274 1.95 rillig }
275 1.95 rillig
276 1.132 rillig /*
277 1.132 rillig * Create a node, register it in .ALLTARGETS but don't store it in the
278 1.95 rillig * table of global nodes. This means it cannot be found by name.
279 1.95 rillig *
280 1.132 rillig * This is used for internal nodes, such as cohorts or .WAIT nodes.
281 1.132 rillig */
282 1.95 rillig GNode *
283 1.95 rillig Targ_NewInternalNode(const char *name)
284 1.95 rillig {
285 1.128 rillig GNode *gn = GNode_New(name);
286 1.96 rillig Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
287 1.148 rillig Lst_Append(&allTargets, gn);
288 1.138 rillig DEBUG1(TARG, "Adding \"%s\" to all targets.\n", gn->name);
289 1.96 rillig if (doing_depend)
290 1.96 rillig gn->flags |= FROM_DEPEND;
291 1.96 rillig return gn;
292 1.95 rillig }
293 1.95 rillig
294 1.132 rillig /*
295 1.132 rillig * Return the .END node, which contains the commands to be run when
296 1.132 rillig * everything else has been made.
297 1.132 rillig */
298 1.90 rillig GNode *Targ_GetEndNode(void)
299 1.90 rillig {
300 1.90 rillig /* Save the node locally to avoid having to search for it all the time. */
301 1.90 rillig static GNode *endNode = NULL;
302 1.90 rillig if (endNode == NULL) {
303 1.95 rillig endNode = Targ_GetNode(".END");
304 1.90 rillig endNode->type = OP_SPECIAL;
305 1.90 rillig }
306 1.90 rillig return endNode;
307 1.90 rillig }
308 1.90 rillig
309 1.98 rillig /* Return the named nodes, creating them as necessary. */
310 1.147 rillig void
311 1.147 rillig Targ_FindList(GNodeList *nodes, StringList *names)
312 1.1 cgd {
313 1.89 rillig StringListNode *ln;
314 1.108 rillig for (ln = names->first; ln != NULL; ln = ln->next) {
315 1.108 rillig const char *name = ln->datum;
316 1.96 rillig GNode *gn = Targ_GetNode(name);
317 1.95 rillig Lst_Append(nodes, gn);
318 1.1 cgd }
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.131 rillig Targ_Ignore(const GNode *gn)
324 1.1 cgd {
325 1.125 rillig return opts.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.131 rillig Targ_Silent(const GNode *gn)
331 1.1 cgd {
332 1.125 rillig return opts.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.131 rillig Targ_Precious(const GNode *gn)
338 1.1 cgd {
339 1.131 rillig /* XXX: Why are '::' targets precious? */
340 1.77 rillig return allPrecious || gn->type & (OP_PRECIOUS | OP_DOUBLEDEP);
341 1.1 cgd }
342 1.1 cgd
343 1.132 rillig /*
344 1.132 rillig * The main target to be made; only for debugging output.
345 1.132 rillig * See mainNode in parse.c for the definitive source.
346 1.132 rillig */
347 1.132 rillig static GNode *mainTarg;
348 1.77 rillig
349 1.132 rillig /* Remember the main target to make; only used for debugging. */
350 1.1 cgd void
351 1.28 wiz Targ_SetMain(GNode *gn)
352 1.1 cgd {
353 1.1 cgd mainTarg = gn;
354 1.1 cgd }
355 1.1 cgd
356 1.86 rillig static void
357 1.89 rillig PrintNodeNames(GNodeList *gnodes)
358 1.1 cgd {
359 1.89 rillig GNodeListNode *node;
360 1.38 dsl
361 1.101 rillig for (node = gnodes->first; node != NULL; node = node->next) {
362 1.101 rillig GNode *gn = node->datum;
363 1.107 rillig debug_printf(" %s%s", gn->name, gn->cohort_num);
364 1.85 rillig }
365 1.85 rillig }
366 1.38 dsl
367 1.85 rillig static void
368 1.89 rillig PrintNodeNamesLine(const char *label, GNodeList *gnodes)
369 1.85 rillig {
370 1.85 rillig if (Lst_IsEmpty(gnodes))
371 1.85 rillig return;
372 1.107 rillig debug_printf("# %s:", label);
373 1.85 rillig PrintNodeNames(gnodes);
374 1.107 rillig debug_printf("\n");
375 1.1 cgd }
376 1.1 cgd
377 1.84 rillig void
378 1.84 rillig Targ_PrintCmds(GNode *gn)
379 1.84 rillig {
380 1.118 rillig StringListNode *ln;
381 1.142 rillig for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
382 1.118 rillig const char *cmd = ln->datum;
383 1.107 rillig debug_printf("\t%s\n", cmd);
384 1.93 rillig }
385 1.84 rillig }
386 1.84 rillig
387 1.77 rillig /* Format a modification time in some reasonable way and return it.
388 1.77 rillig * The time is placed in a static area, so it is overwritten with each call. */
389 1.1 cgd char *
390 1.28 wiz Targ_FmtTime(time_t tm)
391 1.1 cgd {
392 1.106 rillig struct tm *parts;
393 1.106 rillig static char buf[128];
394 1.1 cgd
395 1.140 rillig /* TODO: Add special case for 0, which often means ENOENT, to make it
396 1.140 rillig * independent from time zones. */
397 1.25 reinoud parts = localtime(&tm);
398 1.15 christos (void)strftime(buf, sizeof buf, "%k:%M:%S %b %d, %Y", parts);
399 1.63 rillig return buf;
400 1.1 cgd }
401 1.10 christos
402 1.77 rillig /* Print out a type field giving only those attributes the user can set. */
403 1.1 cgd void
404 1.52 christos Targ_PrintType(int type)
405 1.1 cgd {
406 1.28 wiz int tbit;
407 1.10 christos
408 1.107 rillig #define PRINTBIT(attr) case CONCAT(OP_,attr): debug_printf(" ." #attr); break
409 1.107 rillig #define PRINTDBIT(attr) case CONCAT(OP_,attr): if (DEBUG(TARG))debug_printf(" ." #attr); break
410 1.1 cgd
411 1.1 cgd type &= ~OP_OPMASK;
412 1.1 cgd
413 1.141 rillig while (type != 0) {
414 1.52 christos tbit = 1 << (ffs(type) - 1);
415 1.1 cgd type &= ~tbit;
416 1.1 cgd
417 1.1 cgd switch(tbit) {
418 1.96 rillig PRINTBIT(OPTIONAL);
419 1.96 rillig PRINTBIT(USE);
420 1.96 rillig PRINTBIT(EXEC);
421 1.96 rillig PRINTBIT(IGNORE);
422 1.96 rillig PRINTBIT(PRECIOUS);
423 1.96 rillig PRINTBIT(SILENT);
424 1.96 rillig PRINTBIT(MAKE);
425 1.96 rillig PRINTBIT(JOIN);
426 1.96 rillig PRINTBIT(INVISIBLE);
427 1.96 rillig PRINTBIT(NOTMAIN);
428 1.96 rillig PRINTDBIT(LIB);
429 1.1 cgd /*XXX: MEMBER is defined, so CONCAT(OP_,MEMBER) gives OP_"%" */
430 1.107 rillig case OP_MEMBER: if (DEBUG(TARG))debug_printf(" .MEMBER"); break;
431 1.96 rillig PRINTDBIT(ARCHV);
432 1.96 rillig PRINTDBIT(MADE);
433 1.96 rillig PRINTDBIT(PHONY);
434 1.1 cgd }
435 1.1 cgd }
436 1.1 cgd }
437 1.1 cgd
438 1.45 dsl static const char *
439 1.71 rillig made_name(GNodeMade made)
440 1.45 dsl {
441 1.45 dsl switch (made) {
442 1.45 dsl case UNMADE: return "unmade";
443 1.45 dsl case DEFERRED: return "deferred";
444 1.45 dsl case REQUESTED: return "requested";
445 1.45 dsl case BEINGMADE: return "being made";
446 1.45 dsl case MADE: return "made";
447 1.45 dsl case UPTODATE: return "up-to-date";
448 1.45 dsl case ERROR: return "error when made";
449 1.45 dsl case ABORTED: return "aborted";
450 1.45 dsl default: return "unknown enum_made value";
451 1.45 dsl }
452 1.45 dsl }
453 1.45 dsl
454 1.114 rillig static const char *
455 1.114 rillig GNode_OpName(const GNode *gn)
456 1.114 rillig {
457 1.114 rillig switch (gn->type & OP_OPMASK) {
458 1.114 rillig case OP_DEPENDS:
459 1.114 rillig return ":";
460 1.114 rillig case OP_FORCE:
461 1.114 rillig return "!";
462 1.114 rillig case OP_DOUBLEDEP:
463 1.114 rillig return "::";
464 1.114 rillig }
465 1.114 rillig return "";
466 1.114 rillig }
467 1.114 rillig
468 1.105 rillig /* Print the contents of a node. */
469 1.105 rillig void
470 1.105 rillig Targ_PrintNode(GNode *gn, int pass)
471 1.1 cgd {
472 1.107 rillig debug_printf("# %s%s", gn->name, gn->cohort_num);
473 1.125 rillig GNode_FprintDetails(opts.debug_file, ", ", gn, "\n");
474 1.45 dsl if (gn->flags == 0)
475 1.104 rillig return;
476 1.45 dsl
477 1.121 rillig if (GNode_IsTarget(gn)) {
478 1.107 rillig debug_printf("#\n");
479 1.1 cgd if (gn == mainTarg) {
480 1.107 rillig debug_printf("# *** MAIN TARGET ***\n");
481 1.1 cgd }
482 1.45 dsl if (pass >= 2) {
483 1.135 rillig if (gn->unmade > 0) {
484 1.107 rillig debug_printf("# %d unmade children\n", gn->unmade);
485 1.1 cgd } else {
486 1.107 rillig debug_printf("# No unmade children\n");
487 1.1 cgd }
488 1.135 rillig if (!(gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) {
489 1.1 cgd if (gn->mtime != 0) {
490 1.107 rillig debug_printf("# last modified %s: %s\n",
491 1.96 rillig Targ_FmtTime(gn->mtime),
492 1.96 rillig made_name(gn->made));
493 1.1 cgd } else if (gn->made != UNMADE) {
494 1.107 rillig debug_printf("# non-existent (maybe): %s\n",
495 1.96 rillig made_name(gn->made));
496 1.1 cgd } else {
497 1.107 rillig debug_printf("# unmade\n");
498 1.1 cgd }
499 1.1 cgd }
500 1.146 rillig PrintNodeNamesLine("implicit parents", &gn->implicitParents);
501 1.41 dsl } else {
502 1.41 dsl if (gn->unmade)
503 1.107 rillig debug_printf("# %d unmade children\n", gn->unmade);
504 1.1 cgd }
505 1.143 rillig PrintNodeNamesLine("parents", &gn->parents);
506 1.144 rillig PrintNodeNamesLine("order_pred", &gn->order_pred);
507 1.144 rillig PrintNodeNamesLine("order_succ", &gn->order_succ);
508 1.10 christos
509 1.114 rillig debug_printf("%-16s%s", gn->name, GNode_OpName(gn));
510 1.34 christos Targ_PrintType(gn->type);
511 1.143 rillig PrintNodeNames(&gn->children);
512 1.107 rillig debug_printf("\n");
513 1.84 rillig Targ_PrintCmds(gn);
514 1.107 rillig debug_printf("\n\n");
515 1.20 mycroft if (gn->type & OP_DOUBLEDEP) {
516 1.145 rillig Targ_PrintNodes(&gn->cohorts, pass);
517 1.1 cgd }
518 1.1 cgd }
519 1.1 cgd }
520 1.1 cgd
521 1.87 rillig void
522 1.89 rillig Targ_PrintNodes(GNodeList *gnodes, int pass)
523 1.87 rillig {
524 1.104 rillig GNodeListNode *ln;
525 1.104 rillig for (ln = gnodes->first; ln != NULL; ln = ln->next)
526 1.105 rillig Targ_PrintNode(ln->datum, pass);
527 1.87 rillig }
528 1.87 rillig
529 1.100 rillig /* Print only those targets that are just a source. */
530 1.103 mrg static void
531 1.100 rillig PrintOnlySources(void)
532 1.4 jtc {
533 1.100 rillig GNodeListNode *ln;
534 1.100 rillig
535 1.148 rillig for (ln = allTargets.first; ln != NULL; ln = ln->next) {
536 1.100 rillig GNode *gn = ln->datum;
537 1.121 rillig if (GNode_IsTarget(gn))
538 1.100 rillig continue;
539 1.4 jtc
540 1.124 rillig debug_printf("#\t%s [%s]", gn->name, GNode_Path(gn));
541 1.100 rillig Targ_PrintType(gn->type);
542 1.107 rillig debug_printf("\n");
543 1.100 rillig }
544 1.1 cgd }
545 1.1 cgd
546 1.77 rillig /* Input:
547 1.77 rillig * pass 1 => before processing
548 1.77 rillig * 2 => after processing
549 1.77 rillig * 3 => after processing, an error occurred
550 1.1 cgd */
551 1.3 cgd void
552 1.28 wiz Targ_PrintGraph(int pass)
553 1.1 cgd {
554 1.107 rillig debug_printf("#*** Input graph:\n");
555 1.148 rillig Targ_PrintNodes(&allTargets, pass);
556 1.135 rillig debug_printf("\n");
557 1.135 rillig debug_printf("\n");
558 1.135 rillig
559 1.135 rillig debug_printf("#\n");
560 1.135 rillig debug_printf("# Files that are only sources:\n");
561 1.100 rillig PrintOnlySources();
562 1.135 rillig
563 1.107 rillig debug_printf("#*** Global Variables:\n");
564 1.34 christos Var_Dump(VAR_GLOBAL);
565 1.135 rillig
566 1.107 rillig debug_printf("#*** Command-line Variables:\n");
567 1.126 rillig Var_Dump(VAR_CMDLINE);
568 1.135 rillig
569 1.107 rillig debug_printf("\n");
570 1.1 cgd Dir_PrintDirectories();
571 1.107 rillig debug_printf("\n");
572 1.135 rillig
573 1.1 cgd Suff_PrintAll();
574 1.19 mycroft }
575 1.19 mycroft
576 1.132 rillig /* Propagate some type information to cohort nodes (those from the '::'
577 1.78 rillig * dependency operator).
578 1.77 rillig *
579 1.78 rillig * Should be called after the makefiles are parsed but before any action is
580 1.78 rillig * taken. */
581 1.78 rillig void
582 1.78 rillig Targ_Propagate(void)
583 1.19 mycroft {
584 1.117 rillig GNodeListNode *ln, *cln;
585 1.45 dsl
586 1.148 rillig for (ln = allTargets.first; ln != NULL; ln = ln->next) {
587 1.117 rillig GNode *gn = ln->datum;
588 1.117 rillig GNodeType type = gn->type;
589 1.19 mycroft
590 1.117 rillig if (!(type & OP_DOUBLEDEP))
591 1.78 rillig continue;
592 1.42 apb
593 1.145 rillig for (cln = gn->cohorts.first; cln != NULL; cln = cln->next) {
594 1.117 rillig GNode *cohort = cln->datum;
595 1.42 apb
596 1.117 rillig cohort->type |= type & ~OP_OPMASK;
597 1.78 rillig }
598 1.78 rillig }
599 1.1 cgd }
600