Annotation of src/usr.bin/make/make.c, Revision 1.23
1.23 ! espie 1: /* $OpenBSD: make.c,v 1.22 2000/09/14 13:46:45 espie Exp $ */
1.6 millert 2: /* $NetBSD: make.c,v 1.10 1996/11/06 17:59:15 christos Exp $ */
1.1 deraadt 3:
4: /*
1.4 millert 5: * Copyright (c) 1988, 1989, 1990, 1993
6: * The Regents of the University of California. All rights reserved.
1.1 deraadt 7: * Copyright (c) 1989 by Berkeley Softworks
8: * All rights reserved.
9: *
10: * This code is derived from software contributed to Berkeley by
11: * Adam de Boor.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: */
41:
42: /*-
43: * make.c --
44: * The functions which perform the examination of targets and
45: * their suitability for creation
46: *
47: * Interface:
48: * Make_Run Initialize things for the module and recreate
49: * whatever needs recreating. Returns TRUE if
50: * work was (or would have been) done and FALSE
51: * otherwise.
52: *
53: * Make_Update Update all parents of a given child. Performs
54: * various bookkeeping chores like the updating
55: * of the cmtime field of the parent, filling
56: * of the IMPSRC context variable, etc. It will
57: * place the parent on the toBeMade queue if it
58: * should be.
59: *
60: * Make_TimeStamp Function to set the parent's cmtime field
61: * based on a child's modification time.
62: *
63: * Make_DoAllVar Set up the various local variables for a
64: * target, including the .ALLSRC variable, making
65: * sure that any variable that needs to exist
66: * at the very least has the empty value.
67: *
68: * Make_OODate Determine if a target is out-of-date.
69: *
1.5 millert 70: * Make_HandleUse See if a child is a .USE node for a parent
1.1 deraadt 71: * and perform the .USE actions if so.
72: */
73:
1.22 espie 74: #include <stddef.h>
1.1 deraadt 75: #include "make.h"
1.22 espie 76: #include "ohash.h"
1.1 deraadt 77: #include "dir.h"
78: #include "job.h"
1.21 espie 79:
80: #ifndef lint
81: #if 0
82: static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
83: #else
84: UNUSED
1.23 ! espie 85: static char rcsid[] = "$OpenBSD: make.c,v 1.22 2000/09/14 13:46:45 espie Exp $";
1.21 espie 86: #endif
87: #endif /* not lint */
1.1 deraadt 88:
1.17 espie 89: static LIST toBeMade; /* The current fringe of the graph. These
1.1 deraadt 90: * are nodes which await examination by
91: * MakeOODate. It is added to by
92: * Make_Update and subtracted from by
93: * MakeStartJobs */
94: static int numNodes; /* Number of nodes to be processed. If this
95: * is non-zero when Job_Empty() returns
96: * TRUE, there's a cycle in the graph */
97:
1.16 espie 98: static void MakeAddChild __P((void *, void *));
99: static void MakeAddAllSrc __P((void *, void *));
100: static void MakeTimeStamp __P((void *, void *));
101: static void MakeHandleUse __P((void *, void *));
1.1 deraadt 102: static Boolean MakeStartJobs __P((void));
1.16 espie 103: static void MakePrintStatus __P((void *, void *));
1.1 deraadt 104: /*-
105: *-----------------------------------------------------------------------
106: * Make_TimeStamp --
107: * Set the cmtime field of a parent node based on the mtime stamp in its
1.4 millert 108: * child. Called from MakeOODate via Lst_ForEach.
1.1 deraadt 109: *
110: * Results:
1.4 millert 111: * Always returns 0.
1.1 deraadt 112: *
113: * Side Effects:
114: * The cmtime of the parent node will be changed if the mtime
115: * field of the child is greater than it.
116: *-----------------------------------------------------------------------
117: */
1.15 espie 118: void
119: Make_TimeStamp(pgn, cgn)
1.1 deraadt 120: GNode *pgn; /* the current parent */
121: GNode *cgn; /* the child we've just examined */
122: {
1.15 espie 123: if (cgn->mtime > pgn->cmtime)
1.1 deraadt 124: pgn->cmtime = cgn->mtime;
125: }
126:
1.15 espie 127: static void
128: MakeTimeStamp(pgn, cgn)
1.16 espie 129: void *pgn; /* the current parent */
130: void *cgn; /* the child we've just examined */
1.1 deraadt 131: {
1.15 espie 132: Make_TimeStamp((GNode *)pgn, (GNode *)cgn);
1.1 deraadt 133: }
134:
135: /*-
136: *-----------------------------------------------------------------------
137: * Make_OODate --
138: * See if a given node is out of date with respect to its sources.
139: * Used by Make_Run when deciding which nodes to place on the
140: * toBeMade queue initially and by Make_Update to screen out USE and
141: * EXEC nodes. In the latter case, however, any other sort of node
142: * must be considered out-of-date since at least one of its children
143: * will have been recreated.
144: *
145: * Results:
1.4 millert 146: * TRUE if the node is out of date. FALSE otherwise.
1.1 deraadt 147: *
148: * Side Effects:
149: * The mtime field of the node and the cmtime field of its parents
150: * will/may be changed.
151: *-----------------------------------------------------------------------
152: */
153: Boolean
154: Make_OODate (gn)
155: register GNode *gn; /* the node to check */
156: {
157: Boolean oodate;
158:
159: /*
160: * Certain types of targets needn't even be sought as their datedness
161: * doesn't depend on their modification time...
162: */
163: if ((gn->type & (OP_JOIN|OP_USE|OP_EXEC)) == 0) {
1.23 ! espie 164: (void)Dir_MTime(gn);
1.1 deraadt 165: if (DEBUG(MAKE)) {
1.23 ! espie 166: if (!is_out_of_date(gn->mtime)) {
1.1 deraadt 167: printf ("modified %s...", Targ_FmtTime(gn->mtime));
168: } else {
169: printf ("non-existent...");
170: }
171: }
172: }
173:
174: /*
175: * A target is remade in one of the following circumstances:
176: * its modification time is smaller than that of its youngest child
177: * and it would actually be run (has commands or type OP_NOP)
178: * it's the object of a force operator
179: * it has no children, was on the lhs of an operator and doesn't exist
180: * already.
181: *
182: * Libraries are only considered out-of-date if the archive module says
183: * they are.
184: *
185: * These weird rules are brought to you by Backward-Compatability and
186: * the strange people who wrote 'Make'.
187: */
188: if (gn->type & OP_USE) {
189: /*
190: * If the node is a USE node it is *never* out of date
191: * no matter *what*.
192: */
193: if (DEBUG(MAKE)) {
194: printf(".USE node...");
195: }
196: oodate = FALSE;
1.4 millert 197: } else if ((gn->type & OP_LIB) && Arch_IsLib(gn)) {
1.1 deraadt 198: if (DEBUG(MAKE)) {
199: printf("library...");
200: }
201:
202: /*
203: * always out of date if no children and :: target
204: */
205:
206: oodate = Arch_LibOODate (gn) ||
1.13 espie 207: (gn->cmtime == OUT_OF_DATE && (gn->type & OP_DOUBLEDEP));
1.1 deraadt 208: } else if (gn->type & OP_JOIN) {
209: /*
210: * A target with the .JOIN attribute is only considered
211: * out-of-date if any of its children was out-of-date.
212: */
213: if (DEBUG(MAKE)) {
214: printf(".JOIN node...");
215: }
216: oodate = gn->childMade;
1.2 niklas 217: } else if (gn->type & (OP_FORCE|OP_EXEC|OP_PHONY)) {
1.1 deraadt 218: /*
219: * A node which is the object of the force (!) operator or which has
220: * the .EXEC attribute is always considered out-of-date.
221: */
222: if (DEBUG(MAKE)) {
223: if (gn->type & OP_FORCE) {
224: printf("! operator...");
1.2 niklas 225: } else if (gn->type & OP_PHONY) {
226: printf(".PHONY node...");
1.1 deraadt 227: } else {
228: printf(".EXEC node...");
229: }
230: }
231: oodate = TRUE;
1.13 espie 232: } else if (gn->mtime < gn->cmtime ||
233: (gn->cmtime == OUT_OF_DATE &&
234: (gn->mtime == OUT_OF_DATE || (gn->type & OP_DOUBLEDEP))))
1.1 deraadt 235: {
236: /*
237: * A node whose modification time is less than that of its
1.13 espie 238: * youngest child or that has no children (cmtime == OUT_OF_DATE) and
239: * either doesn't exist (mtime == OUT_OF_DATE) or was the object of a
1.1 deraadt 240: * :: operator is out-of-date. Why? Because that's the way Make does
241: * it.
242: */
243: if (DEBUG(MAKE)) {
244: if (gn->mtime < gn->cmtime) {
245: printf("modified before source...");
1.13 espie 246: } else if (gn->mtime == OUT_OF_DATE) {
1.1 deraadt 247: printf("non-existent and no sources...");
248: } else {
249: printf(":: operator and no sources...");
250: }
251: }
252: oodate = TRUE;
253: } else {
254: #if 0
255: /* WHY? */
256: if (DEBUG(MAKE)) {
257: printf("source %smade...", gn->childMade ? "" : "not ");
258: }
259: oodate = gn->childMade;
260: #else
261: oodate = FALSE;
262: #endif /* 0 */
263: }
264:
265: /*
266: * If the target isn't out-of-date, the parents need to know its
267: * modification time. Note that targets that appear to be out-of-date
268: * but aren't, because they have no commands and aren't of type OP_NOP,
269: * have their mtime stay below their children's mtime to keep parents from
270: * thinking they're out-of-date.
271: */
1.15 espie 272: if (!oodate)
1.17 espie 273: Lst_ForEach(&gn->parents, MakeTimeStamp, gn);
1.1 deraadt 274:
275: return (oodate);
276: }
277:
278: /*-
279: *-----------------------------------------------------------------------
280: * MakeAddChild --
281: * Function used by Make_Run to add a child to the list l.
282: * It will only add the child if its make field is FALSE.
283: *
284: * Side Effects:
285: * The given list is extended
286: *-----------------------------------------------------------------------
287: */
1.15 espie 288: static void
289: MakeAddChild(gnp, lp)
1.16 espie 290: void *gnp; /* the node to add */
291: void *lp; /* the list to which to add it */
1.1 deraadt 292: {
1.15 espie 293: GNode *gn = (GNode *)gnp;
294: Lst l = (Lst)lp;
1.5 millert 295:
1.15 espie 296: if (!gn->make && !(gn->type & OP_USE))
1.14 espie 297: Lst_EnQueue(l, gn);
1.1 deraadt 298: }
1.5 millert 299:
300: /*-
301: *-----------------------------------------------------------------------
1.1 deraadt 302: * Make_HandleUse --
303: * Function called by Make_Run and SuffApplyTransform on the downward
304: * pass to handle .USE and transformation nodes. A callback function
305: * for Lst_ForEach, it implements the .USE and transformation
306: * functionality by copying the node's commands, type flags
307: * and children to the parent node. Should be called before the
308: * children are enqueued to be looked at by MakeAddChild.
309: *
310: * A .USE node is much like an explicit transformation rule, except
311: * its commands are always added to the target node, even if the
312: * target already has commands.
313: *
314: * Side Effects:
315: * Children and commands may be added to the parent and the parent's
316: * type may be changed.
317: *
318: *-----------------------------------------------------------------------
319: */
1.15 espie 320: void
321: Make_HandleUse(cgn, pgn)
322: GNode *cgn; /* The .USE node */
323: GNode *pgn; /* The target of the .USE node */
1.1 deraadt 324: {
1.15 espie 325: GNode *gn; /* A child of the .USE node */
326: LstNode ln; /* An element in the children list */
1.1 deraadt 327:
328: if (cgn->type & (OP_USE|OP_TRANSFORM)) {
1.17 espie 329: if ((cgn->type & OP_USE) || Lst_IsEmpty(&pgn->commands)) {
1.1 deraadt 330: /*
331: * .USE or transformation and target has no commands -- append
332: * the child's commands to the parent.
333: */
1.18 espie 334: Lst_Concat(&pgn->commands, &cgn->commands);
1.1 deraadt 335: }
1.4 millert 336:
1.19 espie 337: Lst_Open(&cgn->children);
338: while ((ln = Lst_Next(&cgn->children)) != NULL) {
339: gn = (GNode *)Lst_Datum(ln);
340:
341: if (Lst_Member(&pgn->children, gn) == NULL) {
342: Lst_AtEnd(&pgn->children, gn);
343: Lst_AtEnd(&gn->parents, pgn);
344: pgn->unmade += 1;
1.1 deraadt 345: }
346: }
1.19 espie 347: Lst_Close(&cgn->children);
1.4 millert 348:
1.1 deraadt 349: pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_TRANSFORM);
350:
351: /*
352: * This child node is now "made", so we decrement the count of
353: * unmade children in the parent... We also remove the child
354: * from the parent's list to accurately reflect the number of decent
355: * children the parent has. This is used by Make_Run to decide
356: * whether to queue the parent or examine its children...
357: */
1.6 millert 358: if (cgn->type & OP_USE) {
1.5 millert 359: pgn->unmade--;
1.1 deraadt 360: }
361: }
362: }
1.15 espie 363: static void
364: MakeHandleUse(pgn, cgn)
1.16 espie 365: void *pgn; /* the current parent */
366: void *cgn; /* the child we've just examined */
1.1 deraadt 367: {
1.15 espie 368: Make_HandleUse((GNode *)pgn, (GNode *)cgn);
1.1 deraadt 369: }
370:
371: /*-
372: *-----------------------------------------------------------------------
373: * Make_Update --
374: * Perform update on the parents of a node. Used by JobFinish once
375: * a node has been dealt with and by MakeStartJobs if it finds an
1.4 millert 376: * up-to-date node.
1.1 deraadt 377: *
378: * Results:
379: * Always returns 0
380: *
381: * Side Effects:
382: * The unmade field of pgn is decremented and pgn may be placed on
383: * the toBeMade queue if this field becomes 0.
384: *
385: * If the child was made, the parent's childMade field will be set true
386: * and its cmtime set to now.
387: *
388: * If the child wasn't made, the cmtime field of the parent will be
389: * altered if the child's mtime is big enough.
390: *
391: * Finally, if the child is the implied source for the parent, the
392: * parent's IMPSRC variable is set appropriately.
393: *
394: *-----------------------------------------------------------------------
395: */
396: void
397: Make_Update (cgn)
398: register GNode *cgn; /* the child node */
399: {
400: register GNode *pgn; /* the parent node */
401: register char *cname; /* the child's name */
402: register LstNode ln; /* Element in parents and iParents lists */
403:
1.20 espie 404: cname = Varq_Value(TARGET_INDEX, cgn);
1.1 deraadt 405:
406: /*
407: * If the child was actually made, see what its modification time is
408: * now -- some rules won't actually update the file. If the file still
409: * doesn't exist, make its mtime now.
410: */
411: if (cgn->made != UPTODATE) {
412: #ifndef RECHECK
413: /*
414: * We can't re-stat the thing, but we can at least take care of rules
415: * where a target depends on a source that actually creates the
416: * target, but only if it has changed, e.g.
417: *
418: * parse.h : parse.o
419: *
420: * parse.o : parse.y
421: * yacc -d parse.y
422: * cc -c y.tab.c
423: * mv y.tab.o parse.o
424: * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
425: *
426: * In this case, if the definitions produced by yacc haven't changed
427: * from before, parse.h won't have been updated and cgn->mtime will
428: * reflect the current modification time for parse.h. This is
429: * something of a kludge, I admit, but it's a useful one..
430: * XXX: People like to use a rule like
431: *
432: * FRC:
433: *
434: * To force things that depend on FRC to be made, so we have to
435: * check for gn->children being empty as well...
436: */
1.17 espie 437: if (!Lst_IsEmpty(&cgn->commands) || Lst_IsEmpty(&cgn->children)) {
1.1 deraadt 438: cgn->mtime = now;
439: }
440: #else
441: /*
442: * This is what Make does and it's actually a good thing, as it
443: * allows rules like
444: *
445: * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
446: *
447: * to function as intended. Unfortunately, thanks to the stateless
448: * nature of NFS (by which I mean the loose coupling of two clients
449: * using the same file from a common server), there are times
450: * when the modification time of a file created on a remote
451: * machine will not be modified before the local stat() implied by
452: * the Dir_MTime occurs, thus leading us to believe that the file
453: * is unchanged, wreaking havoc with files that depend on this one.
454: *
455: * I have decided it is better to make too much than to make too
456: * little, so this stuff is commented out unless you're sure it's ok.
457: * -- ardeb 1/12/88
458: */
459: /*
460: * Christos, 4/9/92: If we are saving commands pretend that
461: * the target is made now. Otherwise archives with ... rules
462: * don't work!
463: */
1.23 ! espie 464: if (noExecute || (cgn->type & OP_SAVE_CMDS) ||
! 465: is_out_of_date(Dir_MTime(cgn))) {
1.1 deraadt 466: cgn->mtime = now;
467: }
468: if (DEBUG(MAKE)) {
469: printf("update time: %s\n", Targ_FmtTime(cgn->mtime));
470: }
471: #endif
472: }
1.4 millert 473:
1.19 espie 474: Lst_Open(&cgn->parents);
475: while ((ln = Lst_Next(&cgn->parents)) != NULL) {
476: pgn = (GNode *)Lst_Datum(ln);
477: if (pgn->make) {
478: pgn->unmade -= 1;
479:
480: if ( ! (cgn->type & (OP_EXEC|OP_USE))) {
481: if (cgn->made == MADE) {
482: pgn->childMade = TRUE;
483: if (pgn->cmtime < cgn->mtime) {
484: pgn->cmtime = cgn->mtime;
1.1 deraadt 485: }
1.19 espie 486: } else {
487: (void)Make_TimeStamp (pgn, cgn);
1.1 deraadt 488: }
1.19 espie 489: }
490: if (pgn->unmade == 0) {
491: /*
492: * Queue the node up -- any unmade predecessors will
493: * be dealt with in MakeStartJobs.
494: */
495: Lst_EnQueue(&toBeMade, pgn);
496: } else if (pgn->unmade < 0) {
497: Error ("Graph cycles through %s", pgn->name);
1.1 deraadt 498: }
499: }
500: }
1.19 espie 501: Lst_Close(&cgn->parents);
1.1 deraadt 502: /*
503: * Deal with successor nodes. If any is marked for making and has an unmade
504: * count of 0, has not been made and isn't in the examination queue,
505: * it means we need to place it in the queue as it restrained itself
506: * before.
507: */
1.19 espie 508: for (ln = Lst_First(&cgn->successors); ln != NULL; ln = Lst_Adv(ln)) {
1.1 deraadt 509: GNode *succ = (GNode *)Lst_Datum(ln);
510:
511: if (succ->make && succ->unmade == 0 && succ->made == UNMADE &&
1.17 espie 512: Lst_Member(&toBeMade, succ) == NULL)
513: Lst_EnQueue(&toBeMade, succ);
1.1 deraadt 514: }
1.4 millert 515:
1.1 deraadt 516: /*
517: * Set the .PREFIX and .IMPSRC variables for all the implied parents
518: * of this node.
519: */
1.19 espie 520: {
1.20 espie 521: char *cpref = Varq_Value(PREFIX_INDEX, cgn);
1.1 deraadt 522:
1.19 espie 523: Lst_Open(&cgn->iParents);
1.17 espie 524: while ((ln = Lst_Next(&cgn->iParents)) != NULL) {
1.1 deraadt 525: pgn = (GNode *)Lst_Datum (ln);
526: if (pgn->make) {
1.20 espie 527: Varq_Set(IMPSRC_INDEX, cname, pgn);
528: Varq_Set(PREFIX_INDEX, cpref, pgn);
1.1 deraadt 529: }
530: }
1.17 espie 531: Lst_Close(&cgn->iParents);
1.1 deraadt 532: }
533: }
534:
535: /*-
536: *-----------------------------------------------------------------------
537: * MakeAddAllSrc --
538: * Add a child's name to the ALLSRC and OODATE variables of the given
539: * node. Called from Make_DoAllVar via Lst_ForEach. A child is added only
540: * if it has not been given the .EXEC, .USE or .INVISIBLE attributes.
541: * .EXEC and .USE children are very rarely going to be files, so...
542: * A child is added to the OODATE variable if its modification time is
543: * later than that of its parent, as defined by Make, except if the
544: * parent is a .JOIN node. In that case, it is only added to the OODATE
545: * variable if it was actually made (since .JOIN nodes don't have
546: * modification times, the comparison is rather unfair...)..
547: *
548: * Side Effects:
549: * The ALLSRC variable for the given node is extended.
550: *-----------------------------------------------------------------------
551: */
1.15 espie 552: static void
553: MakeAddAllSrc(cgnp, pgnp)
1.16 espie 554: void *cgnp; /* The child to add */
555: void *pgnp; /* The parent to whose ALLSRC variable it should be */
1.1 deraadt 556: /* added */
557: {
558: GNode *cgn = (GNode *) cgnp;
559: GNode *pgn = (GNode *) pgnp;
560: if ((cgn->type & (OP_EXEC|OP_USE|OP_INVISIBLE)) == 0) {
561: char *child;
562:
1.5 millert 563: if (OP_NOP(cgn->type) ||
1.20 espie 564: (child = Varq_Value(TARGET_INDEX, cgn)) == NULL) {
1.3 briggs 565: /*
566: * this node is only source; use the specific pathname for it
567: */
568: child = cgn->path ? cgn->path : cgn->name;
569: }
1.5 millert 570:
1.20 espie 571: Varq_Append(ALLSRC_INDEX, child, pgn);
1.1 deraadt 572: if (pgn->type & OP_JOIN) {
1.20 espie 573: if (cgn->made == MADE)
574: Varq_Append(OODATE_INDEX, child, pgn);
1.1 deraadt 575: } else if ((pgn->mtime < cgn->mtime) ||
576: (cgn->mtime >= now && cgn->made == MADE))
577: {
578: /*
579: * It goes in the OODATE variable if the parent is younger than the
580: * child or if the child has been modified more recently than
581: * the start of the make. This is to keep pmake from getting
582: * confused if something else updates the parent after the
583: * make starts (shouldn't happen, I know, but sometimes it
584: * does). In such a case, if we've updated the kid, the parent
585: * is likely to have a modification time later than that of
586: * the kid and anything that relies on the OODATE variable will
587: * be hosed.
588: *
589: * XXX: This will cause all made children to go in the OODATE
590: * variable, even if they're not touched, if RECHECK isn't defined,
591: * since cgn->mtime is set to now in Make_Update. According to
592: * some people, this is good...
593: */
1.20 espie 594: Varq_Append(OODATE_INDEX, child, pgn);
1.1 deraadt 595: }
596: }
597: }
598:
599: /*-
600: *-----------------------------------------------------------------------
601: * Make_DoAllVar --
602: * Set up the ALLSRC and OODATE variables. Sad to say, it must be
603: * done separately, rather than while traversing the graph. This is
604: * because Make defined OODATE to contain all sources whose modification
605: * times were later than that of the target, *not* those sources that
606: * were out-of-date. Since in both compatibility and native modes,
607: * the modification time of the parent isn't found until the child
608: * has been dealt with, we have to wait until now to fill in the
609: * variable. As for ALLSRC, the ordering is important and not
610: * guaranteed when in native mode, so it must be set here, too.
611: *
612: * Results:
613: * None
614: *
615: * Side Effects:
616: * The ALLSRC and OODATE variables of the given node is filled in.
617: * If the node is a .JOIN node, its TARGET variable will be set to
618: * match its ALLSRC variable.
619: *-----------------------------------------------------------------------
620: */
621: void
622: Make_DoAllVar (gn)
623: GNode *gn;
624: {
1.17 espie 625: Lst_ForEach(&gn->children, MakeAddAllSrc, gn);
1.1 deraadt 626:
1.20 espie 627: if (!Varq_Exists(OODATE_INDEX, gn))
628: Varq_Set(OODATE_INDEX, "", gn);
629: if (!Varq_Exists(ALLSRC_INDEX, gn))
630: Varq_Set(ALLSRC_INDEX, "", gn);
1.1 deraadt 631:
1.8 espie 632: if (gn->type & OP_JOIN)
1.20 espie 633: Varq_Set(TARGET_INDEX, Varq_Value(ALLSRC_INDEX, gn), gn);
1.1 deraadt 634: }
635:
636: /*-
637: *-----------------------------------------------------------------------
638: * MakeStartJobs --
639: * Start as many jobs as possible.
640: *
641: * Results:
642: * If the query flag was given to pmake, no job will be started,
643: * but as soon as an out-of-date target is found, this function
644: * returns TRUE. At all other times, this function returns FALSE.
645: *
646: * Side Effects:
647: * Nodes are removed from the toBeMade queue and job table slots
648: * are filled.
649: *
650: *-----------------------------------------------------------------------
651: */
652: static Boolean
653: MakeStartJobs ()
654: {
655: register GNode *gn;
1.4 millert 656:
1.17 espie 657: while (!Job_Full() && (gn = (GNode *)Lst_DeQueue(&toBeMade)) != NULL) {
1.1 deraadt 658: if (DEBUG(MAKE)) {
659: printf ("Examining %s...", gn->name);
660: }
661: /*
662: * Make sure any and all predecessors that are going to be made,
663: * have been.
664: */
1.17 espie 665: if (!Lst_IsEmpty(&gn->preds)) {
1.1 deraadt 666: LstNode ln;
667:
1.19 espie 668: for (ln = Lst_First(&gn->preds); ln != NULL; ln = Lst_Adv(ln)){
1.1 deraadt 669: GNode *pgn = (GNode *)Lst_Datum(ln);
670:
671: if (pgn->make && pgn->made == UNMADE) {
672: if (DEBUG(MAKE)) {
673: printf("predecessor %s not made yet.\n", pgn->name);
674: }
675: break;
676: }
677: }
678: /*
1.10 espie 679: * If ln isn't null, there's a predecessor as yet unmade, so we
1.1 deraadt 680: * just drop this node on the floor. When the node in question
681: * has been made, it will notice this node as being ready to
682: * make but as yet unmade and will place the node on the queue.
683: */
1.10 espie 684: if (ln != NULL) {
1.1 deraadt 685: continue;
686: }
687: }
1.4 millert 688:
1.1 deraadt 689: numNodes--;
690: if (Make_OODate (gn)) {
691: if (DEBUG(MAKE)) {
692: printf ("out-of-date\n");
693: }
694: if (queryFlag) {
695: return (TRUE);
696: }
697: Make_DoAllVar (gn);
698: Job_Make (gn);
699: } else {
700: if (DEBUG(MAKE)) {
701: printf ("up-to-date\n");
702: }
703: gn->made = UPTODATE;
704: if (gn->type & OP_JOIN) {
705: /*
706: * Even for an up-to-date .JOIN node, we need it to have its
707: * context variables so references to it get the correct
708: * value for .TARGET when building up the context variables
709: * of its parent(s)...
710: */
711: Make_DoAllVar (gn);
712: }
1.4 millert 713:
1.1 deraadt 714: Make_Update (gn);
715: }
716: }
717: return (FALSE);
718: }
719:
720: /*-
721: *-----------------------------------------------------------------------
722: * MakePrintStatus --
723: * Print the status of a top-level node, viz. it being up-to-date
724: * already or not created due to an error in a lower level.
725: * Callback function for Make_Run via Lst_ForEach.
726: *-----------------------------------------------------------------------
727: */
1.15 espie 728: static void
1.1 deraadt 729: MakePrintStatus(gnp, cyclep)
1.16 espie 730: void *gnp; /* Node to examine */
731: void *cyclep; /* True if gn->unmade being non-zero implies
1.1 deraadt 732: * a cycle in the graph, not an error in an
733: * inferior */
734: {
735: GNode *gn = (GNode *) gnp;
736: Boolean cycle = *(Boolean *) cyclep;
737: if (gn->made == UPTODATE) {
738: printf ("`%s' is up to date.\n", gn->name);
739: } else if (gn->unmade != 0) {
740: if (cycle) {
741: Boolean t = TRUE;
742: /*
743: * If printing cycles and came to one that has unmade children,
744: * print out the cycle by recursing on its children. Note a
745: * cycle like:
746: * a : b
747: * b : c
748: * c : b
749: * will cause this to erroneously complain about a being in
750: * the cycle, but this is a good approximation.
751: */
752: if (gn->made == CYCLE) {
753: Error("Graph cycles through `%s'", gn->name);
754: gn->made = ENDCYCLE;
1.17 espie 755: Lst_ForEach(&gn->children, MakePrintStatus, &t);
1.1 deraadt 756: gn->made = UNMADE;
757: } else if (gn->made != ENDCYCLE) {
758: gn->made = CYCLE;
1.17 espie 759: Lst_ForEach(&gn->children, MakePrintStatus, &t);
1.1 deraadt 760: }
761: } else {
762: printf ("`%s' not remade because of errors.\n", gn->name);
763: }
764: }
765: }
766:
1.5 millert 767:
1.1 deraadt 768: /*-
769: *-----------------------------------------------------------------------
1.6 millert 770: * Make_Run --
771: * Initialize the nodes to remake and the list of nodes which are
772: * ready to be made by doing a breadth-first traversal of the graph
773: * starting from the nodes in the given list. Once this traversal
774: * is finished, all the 'leaves' of the graph are in the toBeMade
775: * queue.
776: * Using this queue and the Job module, work back up the graph,
777: * calling on MakeStartJobs to keep the job table as full as
778: * possible.
779: *
1.1 deraadt 780: * Results:
1.6 millert 781: * TRUE if work was done. FALSE otherwise.
1.1 deraadt 782: *
783: * Side Effects:
1.6 millert 784: * The make field of all nodes involved in the creation of the given
785: * targets is set to 1. The toBeMade list is set to contain all the
786: * 'leaves' of these subgraphs.
1.1 deraadt 787: *-----------------------------------------------------------------------
788: */
1.6 millert 789: Boolean
1.17 espie 790: Make_Run(targs)
1.1 deraadt 791: Lst targs; /* the initial list of targets */
792: {
793: register GNode *gn; /* a temporary pointer */
1.18 espie 794: LIST examine; /* List of targets to examine */
1.6 millert 795: int errors; /* Number of errors the Job module reports */
1.1 deraadt 796:
1.17 espie 797: Lst_Init(&toBeMade);
1.1 deraadt 798:
1.18 espie 799: Lst_Clone(&examine, targs, NOCOPY);
1.1 deraadt 800: numNodes = 0;
1.4 millert 801:
1.1 deraadt 802: /*
803: * Make an initial downward pass over the graph, marking nodes to be made
804: * as we go down. We call Suff_FindDeps to find where a node is and
805: * to get some children for it if it has none and also has no commands.
806: * If the node is a leaf, we stick it on the toBeMade queue to
807: * be looked at in a minute, otherwise we add its children to our queue
1.4 millert 808: * and go on about our business.
1.1 deraadt 809: */
1.18 espie 810: while ((gn = (GNode *)Lst_DeQueue(&examine)) != NULL) {
1.4 millert 811:
1.1 deraadt 812: if (!gn->make) {
813: gn->make = TRUE;
814: numNodes++;
1.4 millert 815:
1.1 deraadt 816: /*
817: * Apply any .USE rules before looking for implicit dependencies
818: * to make sure everything has commands that should...
819: */
1.17 espie 820: Lst_ForEach(&gn->children, MakeHandleUse, gn);
1.1 deraadt 821: Suff_FindDeps (gn);
822:
1.6 millert 823: if (gn->unmade != 0) {
1.18 espie 824: Lst_ForEach(&gn->children, MakeAddChild, &examine);
1.1 deraadt 825: } else {
1.17 espie 826: Lst_EnQueue(&toBeMade, gn);
1.1 deraadt 827: }
828: }
829: }
1.4 millert 830:
1.18 espie 831: Lst_Destroy(&examine, NOFREE);
1.1 deraadt 832:
833: if (queryFlag) {
834: /*
835: * We wouldn't do any work unless we could start some jobs in the
836: * next loop... (we won't actually start any, of course, this is just
837: * to see if any of the targets was out of date)
838: */
839: return (MakeStartJobs());
840: } else {
841: /*
842: * Initialization. At the moment, no jobs are running and until some
843: * get started, nothing will happen since the remaining upward
844: * traversal of the graph is performed by the routines in job.c upon
845: * the finishing of a job. So we fill the Job table as much as we can
1.4 millert 846: * before going into our loop.
1.1 deraadt 847: */
848: (void) MakeStartJobs();
849: }
850:
851: /*
852: * Main Loop: The idea here is that the ending of jobs will take
853: * care of the maintenance of data structures and the waiting for output
854: * will cause us to be idle most of the time while our children run as
855: * much as possible. Because the job table is kept as full as possible,
856: * the only time when it will be empty is when all the jobs which need
857: * running have been run, so that is the end condition of this loop.
858: * Note that the Job module will exit if there were any errors unless the
859: * keepgoing flag was given.
860: */
861: while (!Job_Empty ()) {
862: Job_CatchOutput ();
863: Job_CatchChildren (!usePipes);
864: (void)MakeStartJobs();
865: }
866:
1.7 espie 867: errors = Job_Finish();
1.1 deraadt 868:
869: /*
870: * Print the final status of each target. E.g. if it wasn't made
871: * because some inferior reported an error.
872: */
873: errors = ((errors == 0) && (numNodes != 0));
1.14 espie 874: Lst_ForEach(targs, MakePrintStatus, &errors);
1.4 millert 875:
1.1 deraadt 876: return (TRUE);
877: }