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