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