libpthread: Add pthread_mutex_timedlock() reference to some manual pages.
[dragonfly.git] / contrib / bmake / make.c
blob5ea04fc0a8bc3a0c797ff7d0f8959860d4803836
1 /* $NetBSD: make.c,v 1.95 2016/02/18 18:29:14 christos Exp $ */
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
36 * Copyright (c) 1989 by Berkeley Softworks
37 * All rights reserved.
39 * This code is derived from software contributed to Berkeley by
40 * Adam de Boor.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the University of
53 * California, Berkeley and its contributors.
54 * 4. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
71 #ifndef MAKE_NATIVE
72 static char rcsid[] = "$NetBSD: make.c,v 1.95 2016/02/18 18:29:14 christos Exp $";
73 #else
74 #include <sys/cdefs.h>
75 #ifndef lint
76 #if 0
77 static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
78 #else
79 __RCSID("$NetBSD: make.c,v 1.95 2016/02/18 18:29:14 christos Exp $");
80 #endif
81 #endif /* not lint */
82 #endif
84 /*-
85 * make.c --
86 * The functions which perform the examination of targets and
87 * their suitability for creation
89 * Interface:
90 * Make_Run Initialize things for the module and recreate
91 * whatever needs recreating. Returns TRUE if
92 * work was (or would have been) done and FALSE
93 * otherwise.
95 * Make_Update Update all parents of a given child. Performs
96 * various bookkeeping chores like the updating
97 * of the cmgn field of the parent, filling
98 * of the IMPSRC context variable, etc. It will
99 * place the parent on the toBeMade queue if it
100 * should be.
102 * Make_TimeStamp Function to set the parent's cmgn field
103 * based on a child's modification time.
105 * Make_DoAllVar Set up the various local variables for a
106 * target, including the .ALLSRC variable, making
107 * sure that any variable that needs to exist
108 * at the very least has the empty value.
110 * Make_OODate Determine if a target is out-of-date.
112 * Make_HandleUse See if a child is a .USE node for a parent
113 * and perform the .USE actions if so.
115 * Make_ExpandUse Expand .USE nodes
118 #include "make.h"
119 #include "hash.h"
120 #include "dir.h"
121 #include "job.h"
123 static unsigned int checked = 1;/* Sequence # to detect recursion */
124 static Lst toBeMade; /* The current fringe of the graph. These
125 * are nodes which await examination by
126 * MakeOODate. It is added to by
127 * Make_Update and subtracted from by
128 * MakeStartJobs */
130 static int MakeAddChild(void *, void *);
131 static int MakeFindChild(void *, void *);
132 static int MakeUnmark(void *, void *);
133 static int MakeAddAllSrc(void *, void *);
134 static int MakeTimeStamp(void *, void *);
135 static int MakeHandleUse(void *, void *);
136 static Boolean MakeStartJobs(void);
137 static int MakePrintStatus(void *, void *);
138 static int MakeCheckOrder(void *, void *);
139 static int MakeBuildChild(void *, void *);
140 static int MakeBuildParent(void *, void *);
142 MAKE_ATTR_DEAD static void
143 make_abort(GNode *gn, int line)
145 static int two = 2;
147 fprintf(debug_file, "make_abort from line %d\n", line);
148 Targ_PrintNode(gn, &two);
149 Lst_ForEach(toBeMade, Targ_PrintNode, &two);
150 Targ_PrintGraph(3);
151 abort();
155 *-----------------------------------------------------------------------
156 * Make_TimeStamp --
157 * Set the cmgn field of a parent node based on the mtime stamp in its
158 * child. Called from MakeOODate via Lst_ForEach.
160 * Input:
161 * pgn the current parent
162 * cgn the child we've just examined
164 * Results:
165 * Always returns 0.
167 * Side Effects:
168 * The cmgn of the parent node will be changed if the mtime
169 * field of the child is greater than it.
170 *-----------------------------------------------------------------------
173 Make_TimeStamp(GNode *pgn, GNode *cgn)
175 if (pgn->cmgn == NULL || cgn->mtime > pgn->cmgn->mtime) {
176 pgn->cmgn = cgn;
178 return (0);
182 * Input:
183 * pgn the current parent
184 * cgn the child we've just examined
187 static int
188 MakeTimeStamp(void *pgn, void *cgn)
190 return Make_TimeStamp((GNode *)pgn, (GNode *)cgn);
194 *-----------------------------------------------------------------------
195 * Make_OODate --
196 * See if a given node is out of date with respect to its sources.
197 * Used by Make_Run when deciding which nodes to place on the
198 * toBeMade queue initially and by Make_Update to screen out USE and
199 * EXEC nodes. In the latter case, however, any other sort of node
200 * must be considered out-of-date since at least one of its children
201 * will have been recreated.
203 * Input:
204 * gn the node to check
206 * Results:
207 * TRUE if the node is out of date. FALSE otherwise.
209 * Side Effects:
210 * The mtime field of the node and the cmgn field of its parents
211 * will/may be changed.
212 *-----------------------------------------------------------------------
214 Boolean
215 Make_OODate(GNode *gn)
217 Boolean oodate;
220 * Certain types of targets needn't even be sought as their datedness
221 * doesn't depend on their modification time...
223 if ((gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC)) == 0) {
224 (void)Dir_MTime(gn, 1);
225 if (DEBUG(MAKE)) {
226 if (gn->mtime != 0) {
227 fprintf(debug_file, "modified %s...", Targ_FmtTime(gn->mtime));
228 } else {
229 fprintf(debug_file, "non-existent...");
235 * A target is remade in one of the following circumstances:
236 * its modification time is smaller than that of its youngest child
237 * and it would actually be run (has commands or type OP_NOP)
238 * it's the object of a force operator
239 * it has no children, was on the lhs of an operator and doesn't exist
240 * already.
242 * Libraries are only considered out-of-date if the archive module says
243 * they are.
245 * These weird rules are brought to you by Backward-Compatibility and
246 * the strange people who wrote 'Make'.
248 if (gn->type & (OP_USE|OP_USEBEFORE)) {
250 * If the node is a USE node it is *never* out of date
251 * no matter *what*.
253 if (DEBUG(MAKE)) {
254 fprintf(debug_file, ".USE node...");
256 oodate = FALSE;
257 } else if ((gn->type & OP_LIB) &&
258 ((gn->mtime==0) || Arch_IsLib(gn))) {
259 if (DEBUG(MAKE)) {
260 fprintf(debug_file, "library...");
264 * always out of date if no children and :: target
265 * or non-existent.
267 oodate = (gn->mtime == 0 || Arch_LibOODate(gn) ||
268 (gn->cmgn == NULL && (gn->type & OP_DOUBLEDEP)));
269 } else if (gn->type & OP_JOIN) {
271 * A target with the .JOIN attribute is only considered
272 * out-of-date if any of its children was out-of-date.
274 if (DEBUG(MAKE)) {
275 fprintf(debug_file, ".JOIN node...");
277 if (DEBUG(MAKE)) {
278 fprintf(debug_file, "source %smade...", gn->flags & CHILDMADE ? "" : "not ");
280 oodate = (gn->flags & CHILDMADE) ? TRUE : FALSE;
281 } else if (gn->type & (OP_FORCE|OP_EXEC|OP_PHONY)) {
283 * A node which is the object of the force (!) operator or which has
284 * the .EXEC attribute is always considered out-of-date.
286 if (DEBUG(MAKE)) {
287 if (gn->type & OP_FORCE) {
288 fprintf(debug_file, "! operator...");
289 } else if (gn->type & OP_PHONY) {
290 fprintf(debug_file, ".PHONY node...");
291 } else {
292 fprintf(debug_file, ".EXEC node...");
295 oodate = TRUE;
296 } else if ((gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime) ||
297 (gn->cmgn == NULL &&
298 ((gn->mtime == 0 && !(gn->type & OP_OPTIONAL))
299 || gn->type & OP_DOUBLEDEP)))
302 * A node whose modification time is less than that of its
303 * youngest child or that has no children (cmgn == NULL) and
304 * either doesn't exist (mtime == 0) and it isn't optional
305 * or was the object of a * :: operator is out-of-date.
306 * Why? Because that's the way Make does it.
308 if (DEBUG(MAKE)) {
309 if (gn->cmgn != NULL && gn->mtime < gn->cmgn->mtime) {
310 fprintf(debug_file, "modified before source %s...",
311 gn->cmgn->path);
312 } else if (gn->mtime == 0) {
313 fprintf(debug_file, "non-existent and no sources...");
314 } else {
315 fprintf(debug_file, ":: operator and no sources...");
318 oodate = TRUE;
319 } else {
321 * When a non-existing child with no sources
322 * (such as a typically used FORCE source) has been made and
323 * the target of the child (usually a directory) has the same
324 * timestamp as the timestamp just given to the non-existing child
325 * after it was considered made.
327 if (DEBUG(MAKE)) {
328 if (gn->flags & FORCE)
329 fprintf(debug_file, "non existing child...");
331 oodate = (gn->flags & FORCE) ? TRUE : FALSE;
334 #ifdef USE_META
335 if (useMeta) {
336 oodate = meta_oodate(gn, oodate);
338 #endif
341 * If the target isn't out-of-date, the parents need to know its
342 * modification time. Note that targets that appear to be out-of-date
343 * but aren't, because they have no commands and aren't of type OP_NOP,
344 * have their mtime stay below their children's mtime to keep parents from
345 * thinking they're out-of-date.
347 if (!oodate) {
348 Lst_ForEach(gn->parents, MakeTimeStamp, gn);
351 return (oodate);
355 *-----------------------------------------------------------------------
356 * MakeAddChild --
357 * Function used by Make_Run to add a child to the list l.
358 * It will only add the child if its make field is FALSE.
360 * Input:
361 * gnp the node to add
362 * lp the list to which to add it
364 * Results:
365 * Always returns 0
367 * Side Effects:
368 * The given list is extended
369 *-----------------------------------------------------------------------
371 static int
372 MakeAddChild(void *gnp, void *lp)
374 GNode *gn = (GNode *)gnp;
375 Lst l = (Lst) lp;
377 if ((gn->flags & REMAKE) == 0 && !(gn->type & (OP_USE|OP_USEBEFORE))) {
378 if (DEBUG(MAKE))
379 fprintf(debug_file, "MakeAddChild: need to examine %s%s\n",
380 gn->name, gn->cohort_num);
381 (void)Lst_EnQueue(l, gn);
383 return (0);
387 *-----------------------------------------------------------------------
388 * MakeFindChild --
389 * Function used by Make_Run to find the pathname of a child
390 * that was already made.
392 * Input:
393 * gnp the node to find
395 * Results:
396 * Always returns 0
398 * Side Effects:
399 * The path and mtime of the node and the cmgn of the parent are
400 * updated; the unmade children count of the parent is decremented.
401 *-----------------------------------------------------------------------
403 static int
404 MakeFindChild(void *gnp, void *pgnp)
406 GNode *gn = (GNode *)gnp;
407 GNode *pgn = (GNode *)pgnp;
409 (void)Dir_MTime(gn, 0);
410 Make_TimeStamp(pgn, gn);
411 pgn->unmade--;
413 return (0);
417 *-----------------------------------------------------------------------
418 * Make_HandleUse --
419 * Function called by Make_Run and SuffApplyTransform on the downward
420 * pass to handle .USE and transformation nodes. It implements the
421 * .USE and transformation functionality by copying the node's commands,
422 * type flags and children to the parent node.
424 * A .USE node is much like an explicit transformation rule, except
425 * its commands are always added to the target node, even if the
426 * target already has commands.
428 * Input:
429 * cgn The .USE node
430 * pgn The target of the .USE node
432 * Results:
433 * none
435 * Side Effects:
436 * Children and commands may be added to the parent and the parent's
437 * type may be changed.
439 *-----------------------------------------------------------------------
441 void
442 Make_HandleUse(GNode *cgn, GNode *pgn)
444 LstNode ln; /* An element in the children list */
446 #ifdef DEBUG_SRC
447 if ((cgn->type & (OP_USE|OP_USEBEFORE|OP_TRANSFORM)) == 0) {
448 fprintf(debug_file, "Make_HandleUse: called for plain node %s\n", cgn->name);
449 return;
451 #endif
453 if ((cgn->type & (OP_USE|OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) {
454 if (cgn->type & OP_USEBEFORE) {
456 * .USEBEFORE --
457 * prepend the child's commands to the parent.
459 Lst cmds = pgn->commands;
460 pgn->commands = Lst_Duplicate(cgn->commands, NULL);
461 (void)Lst_Concat(pgn->commands, cmds, LST_CONCNEW);
462 Lst_Destroy(cmds, NULL);
463 } else {
465 * .USE or target has no commands --
466 * append the child's commands to the parent.
468 (void)Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW);
472 if (Lst_Open(cgn->children) == SUCCESS) {
473 while ((ln = Lst_Next(cgn->children)) != NULL) {
474 GNode *tgn, *gn = (GNode *)Lst_Datum(ln);
477 * Expand variables in the .USE node's name
478 * and save the unexpanded form.
479 * We don't need to do this for commands.
480 * They get expanded properly when we execute.
482 if (gn->uname == NULL) {
483 gn->uname = gn->name;
484 } else {
485 free(gn->name);
487 gn->name = Var_Subst(NULL, gn->uname, pgn, VARF_WANTRES);
488 if (gn->name && gn->uname && strcmp(gn->name, gn->uname) != 0) {
489 /* See if we have a target for this node. */
490 tgn = Targ_FindNode(gn->name, TARG_NOCREATE);
491 if (tgn != NULL)
492 gn = tgn;
495 (void)Lst_AtEnd(pgn->children, gn);
496 (void)Lst_AtEnd(gn->parents, pgn);
497 pgn->unmade += 1;
499 Lst_Close(cgn->children);
502 pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_USEBEFORE|OP_TRANSFORM);
506 *-----------------------------------------------------------------------
507 * MakeHandleUse --
508 * Callback function for Lst_ForEach, used by Make_Run on the downward
509 * pass to handle .USE nodes. Should be called before the children
510 * are enqueued to be looked at by MakeAddChild.
511 * This function calls Make_HandleUse to copy the .USE node's commands,
512 * type flags and children to the parent node.
514 * Input:
515 * cgnp the child we've just examined
516 * pgnp the current parent
518 * Results:
519 * returns 0.
521 * Side Effects:
522 * After expansion, .USE child nodes are removed from the parent
524 *-----------------------------------------------------------------------
526 static int
527 MakeHandleUse(void *cgnp, void *pgnp)
529 GNode *cgn = (GNode *)cgnp;
530 GNode *pgn = (GNode *)pgnp;
531 LstNode ln; /* An element in the children list */
532 int unmarked;
534 unmarked = ((cgn->type & OP_MARK) == 0);
535 cgn->type |= OP_MARK;
537 if ((cgn->type & (OP_USE|OP_USEBEFORE)) == 0)
538 return (0);
540 if (unmarked)
541 Make_HandleUse(cgn, pgn);
544 * This child node is now "made", so we decrement the count of
545 * unmade children in the parent... We also remove the child
546 * from the parent's list to accurately reflect the number of decent
547 * children the parent has. This is used by Make_Run to decide
548 * whether to queue the parent or examine its children...
550 if ((ln = Lst_Member(pgn->children, cgn)) != NULL) {
551 Lst_Remove(pgn->children, ln);
552 pgn->unmade--;
554 return (0);
559 *-----------------------------------------------------------------------
560 * Make_Recheck --
561 * Check the modification time of a gnode, and update it as described
562 * in the comments below.
564 * Results:
565 * returns 0 if the gnode does not exist, or its filesystem
566 * time if it does.
568 * Side Effects:
569 * the gnode's modification time and path name are affected.
571 *-----------------------------------------------------------------------
573 time_t
574 Make_Recheck(GNode *gn)
576 time_t mtime = Dir_MTime(gn, 1);
578 #ifndef RECHECK
580 * We can't re-stat the thing, but we can at least take care of rules
581 * where a target depends on a source that actually creates the
582 * target, but only if it has changed, e.g.
584 * parse.h : parse.o
586 * parse.o : parse.y
587 * yacc -d parse.y
588 * cc -c y.tab.c
589 * mv y.tab.o parse.o
590 * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
592 * In this case, if the definitions produced by yacc haven't changed
593 * from before, parse.h won't have been updated and gn->mtime will
594 * reflect the current modification time for parse.h. This is
595 * something of a kludge, I admit, but it's a useful one..
596 * XXX: People like to use a rule like
598 * FRC:
600 * To force things that depend on FRC to be made, so we have to
601 * check for gn->children being empty as well...
603 if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
604 gn->mtime = now;
606 #else
608 * This is what Make does and it's actually a good thing, as it
609 * allows rules like
611 * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
613 * to function as intended. Unfortunately, thanks to the stateless
614 * nature of NFS (by which I mean the loose coupling of two clients
615 * using the same file from a common server), there are times
616 * when the modification time of a file created on a remote
617 * machine will not be modified before the local stat() implied by
618 * the Dir_MTime occurs, thus leading us to believe that the file
619 * is unchanged, wreaking havoc with files that depend on this one.
621 * I have decided it is better to make too much than to make too
622 * little, so this stuff is commented out unless you're sure it's ok.
623 * -- ardeb 1/12/88
626 * Christos, 4/9/92: If we are saving commands pretend that
627 * the target is made now. Otherwise archives with ... rules
628 * don't work!
630 if (NoExecute(gn) || (gn->type & OP_SAVE_CMDS) ||
631 (mtime == 0 && !(gn->type & OP_WAIT))) {
632 if (DEBUG(MAKE)) {
633 fprintf(debug_file, " recheck(%s): update time from %s to now\n",
634 gn->name, Targ_FmtTime(gn->mtime));
636 gn->mtime = now;
638 else {
639 if (DEBUG(MAKE)) {
640 fprintf(debug_file, " recheck(%s): current update time: %s\n",
641 gn->name, Targ_FmtTime(gn->mtime));
644 #endif
645 return mtime;
649 *-----------------------------------------------------------------------
650 * Make_Update --
651 * Perform update on the parents of a node. Used by JobFinish once
652 * a node has been dealt with and by MakeStartJobs if it finds an
653 * up-to-date node.
655 * Input:
656 * cgn the child node
658 * Results:
659 * Always returns 0
661 * Side Effects:
662 * The unmade field of pgn is decremented and pgn may be placed on
663 * the toBeMade queue if this field becomes 0.
665 * If the child was made, the parent's flag CHILDMADE field will be
666 * set true.
668 * If the child is not up-to-date and still does not exist,
669 * set the FORCE flag on the parents.
671 * If the child wasn't made, the cmgn field of the parent will be
672 * altered if the child's mtime is big enough.
674 * Finally, if the child is the implied source for the parent, the
675 * parent's IMPSRC variable is set appropriately.
677 *-----------------------------------------------------------------------
679 void
680 Make_Update(GNode *cgn)
682 GNode *pgn; /* the parent node */
683 char *cname; /* the child's name */
684 LstNode ln; /* Element in parents and iParents lists */
685 time_t mtime = -1;
686 char *p1;
687 Lst parents;
688 GNode *centurion;
690 /* It is save to re-examine any nodes again */
691 checked++;
693 cname = Var_Value(TARGET, cgn, &p1);
694 free(p1);
696 if (DEBUG(MAKE))
697 fprintf(debug_file, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num);
700 * If the child was actually made, see what its modification time is
701 * now -- some rules won't actually update the file. If the file still
702 * doesn't exist, make its mtime now.
704 if (cgn->made != UPTODATE) {
705 mtime = Make_Recheck(cgn);
709 * If this is a `::' node, we must consult its first instance
710 * which is where all parents are linked.
712 if ((centurion = cgn->centurion) != NULL) {
713 if (!Lst_IsEmpty(cgn->parents))
714 Punt("%s%s: cohort has parents", cgn->name, cgn->cohort_num);
715 centurion->unmade_cohorts -= 1;
716 if (centurion->unmade_cohorts < 0)
717 Error("Graph cycles through centurion %s", centurion->name);
718 } else {
719 centurion = cgn;
721 parents = centurion->parents;
723 /* If this was a .ORDER node, schedule the RHS */
724 Lst_ForEach(centurion->order_succ, MakeBuildParent, Lst_First(toBeMade));
726 /* Now mark all the parents as having one less unmade child */
727 if (Lst_Open(parents) == SUCCESS) {
728 while ((ln = Lst_Next(parents)) != NULL) {
729 pgn = (GNode *)Lst_Datum(ln);
730 if (DEBUG(MAKE))
731 fprintf(debug_file, "inspect parent %s%s: flags %x, "
732 "type %x, made %d, unmade %d ",
733 pgn->name, pgn->cohort_num, pgn->flags,
734 pgn->type, pgn->made, pgn->unmade-1);
736 if (!(pgn->flags & REMAKE)) {
737 /* This parent isn't needed */
738 if (DEBUG(MAKE))
739 fprintf(debug_file, "- not needed\n");
740 continue;
742 if (mtime == 0 && !(cgn->type & OP_WAIT))
743 pgn->flags |= FORCE;
746 * If the parent has the .MADE attribute, its timestamp got
747 * updated to that of its newest child, and its unmake
748 * child count got set to zero in Make_ExpandUse().
749 * However other things might cause us to build one of its
750 * children - and so we mustn't do any processing here when
751 * the child build finishes.
753 if (pgn->type & OP_MADE) {
754 if (DEBUG(MAKE))
755 fprintf(debug_file, "- .MADE\n");
756 continue;
759 if ( ! (cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE))) {
760 if (cgn->made == MADE)
761 pgn->flags |= CHILDMADE;
762 (void)Make_TimeStamp(pgn, cgn);
766 * A parent must wait for the completion of all instances
767 * of a `::' dependency.
769 if (centurion->unmade_cohorts != 0 || centurion->made < MADE) {
770 if (DEBUG(MAKE))
771 fprintf(debug_file,
772 "- centurion made %d, %d unmade cohorts\n",
773 centurion->made, centurion->unmade_cohorts);
774 continue;
777 /* One more child of this parent is now made */
778 pgn->unmade -= 1;
779 if (pgn->unmade < 0) {
780 if (DEBUG(MAKE)) {
781 fprintf(debug_file, "Graph cycles through %s%s\n",
782 pgn->name, pgn->cohort_num);
783 Targ_PrintGraph(2);
785 Error("Graph cycles through %s%s", pgn->name, pgn->cohort_num);
788 /* We must always rescan the parents of .WAIT and .ORDER nodes. */
789 if (pgn->unmade != 0 && !(centurion->type & OP_WAIT)
790 && !(centurion->flags & DONE_ORDER)) {
791 if (DEBUG(MAKE))
792 fprintf(debug_file, "- unmade children\n");
793 continue;
795 if (pgn->made != DEFERRED) {
797 * Either this parent is on a different branch of the tree,
798 * or it on the RHS of a .WAIT directive
799 * or it is already on the toBeMade list.
801 if (DEBUG(MAKE))
802 fprintf(debug_file, "- not deferred\n");
803 continue;
805 if (pgn->order_pred
806 && Lst_ForEach(pgn->order_pred, MakeCheckOrder, 0)) {
807 /* A .ORDER rule stops us building this */
808 continue;
810 if (DEBUG(MAKE)) {
811 static int two = 2;
812 fprintf(debug_file, "- %s%s made, schedule %s%s (made %d)\n",
813 cgn->name, cgn->cohort_num,
814 pgn->name, pgn->cohort_num, pgn->made);
815 Targ_PrintNode(pgn, &two);
817 /* Ok, we can schedule the parent again */
818 pgn->made = REQUESTED;
819 (void)Lst_EnQueue(toBeMade, pgn);
821 Lst_Close(parents);
825 * Set the .PREFIX and .IMPSRC variables for all the implied parents
826 * of this node.
828 if (Lst_Open(cgn->iParents) == SUCCESS) {
829 char *cpref = Var_Value(PREFIX, cgn, &p1);
831 while ((ln = Lst_Next(cgn->iParents)) != NULL) {
832 pgn = (GNode *)Lst_Datum(ln);
833 if (pgn->flags & REMAKE) {
834 Var_Set(IMPSRC, cname, pgn, 0);
835 if (cpref != NULL)
836 Var_Set(PREFIX, cpref, pgn, 0);
839 free(p1);
840 Lst_Close(cgn->iParents);
845 *-----------------------------------------------------------------------
846 * MakeAddAllSrc --
847 * Add a child's name to the ALLSRC and OODATE variables of the given
848 * node. Called from Make_DoAllVar via Lst_ForEach. A child is added only
849 * if it has not been given the .EXEC, .USE or .INVISIBLE attributes.
850 * .EXEC and .USE children are very rarely going to be files, so...
851 * If the child is a .JOIN node, its ALLSRC is propagated to the parent.
853 * A child is added to the OODATE variable if its modification time is
854 * later than that of its parent, as defined by Make, except if the
855 * parent is a .JOIN node. In that case, it is only added to the OODATE
856 * variable if it was actually made (since .JOIN nodes don't have
857 * modification times, the comparison is rather unfair...)..
859 * Results:
860 * Always returns 0
862 * Side Effects:
863 * The ALLSRC variable for the given node is extended.
864 *-----------------------------------------------------------------------
866 static int
867 MakeUnmark(void *cgnp, void *pgnp MAKE_ATTR_UNUSED)
869 GNode *cgn = (GNode *)cgnp;
871 cgn->type &= ~OP_MARK;
872 return (0);
876 * Input:
877 * cgnp The child to add
878 * pgnp The parent to whose ALLSRC variable it should
879 * be added
882 static int
883 MakeAddAllSrc(void *cgnp, void *pgnp)
885 GNode *cgn = (GNode *)cgnp;
886 GNode *pgn = (GNode *)pgnp;
888 if (cgn->type & OP_MARK)
889 return (0);
890 cgn->type |= OP_MARK;
892 if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) {
893 char *child, *allsrc;
894 char *p1 = NULL, *p2 = NULL;
896 if (cgn->type & OP_ARCHV)
897 child = Var_Value(MEMBER, cgn, &p1);
898 else
899 child = cgn->path ? cgn->path : cgn->name;
900 if (cgn->type & OP_JOIN) {
901 allsrc = Var_Value(ALLSRC, cgn, &p2);
902 } else {
903 allsrc = child;
905 if (allsrc != NULL)
906 Var_Append(ALLSRC, allsrc, pgn);
907 free(p2);
908 if (pgn->type & OP_JOIN) {
909 if (cgn->made == MADE) {
910 Var_Append(OODATE, child, pgn);
912 } else if ((pgn->mtime < cgn->mtime) ||
913 (cgn->mtime >= now && cgn->made == MADE))
916 * It goes in the OODATE variable if the parent is younger than the
917 * child or if the child has been modified more recently than
918 * the start of the make. This is to keep pmake from getting
919 * confused if something else updates the parent after the
920 * make starts (shouldn't happen, I know, but sometimes it
921 * does). In such a case, if we've updated the kid, the parent
922 * is likely to have a modification time later than that of
923 * the kid and anything that relies on the OODATE variable will
924 * be hosed.
926 * XXX: This will cause all made children to go in the OODATE
927 * variable, even if they're not touched, if RECHECK isn't defined,
928 * since cgn->mtime is set to now in Make_Update. According to
929 * some people, this is good...
931 Var_Append(OODATE, child, pgn);
933 free(p1);
935 return (0);
939 *-----------------------------------------------------------------------
940 * Make_DoAllVar --
941 * Set up the ALLSRC and OODATE variables. Sad to say, it must be
942 * done separately, rather than while traversing the graph. This is
943 * because Make defined OODATE to contain all sources whose modification
944 * times were later than that of the target, *not* those sources that
945 * were out-of-date. Since in both compatibility and native modes,
946 * the modification time of the parent isn't found until the child
947 * has been dealt with, we have to wait until now to fill in the
948 * variable. As for ALLSRC, the ordering is important and not
949 * guaranteed when in native mode, so it must be set here, too.
951 * Results:
952 * None
954 * Side Effects:
955 * The ALLSRC and OODATE variables of the given node is filled in.
956 * If the node is a .JOIN node, its TARGET variable will be set to
957 * match its ALLSRC variable.
958 *-----------------------------------------------------------------------
960 void
961 Make_DoAllVar(GNode *gn)
963 if (gn->flags & DONE_ALLSRC)
964 return;
966 Lst_ForEach(gn->children, MakeUnmark, gn);
967 Lst_ForEach(gn->children, MakeAddAllSrc, gn);
969 if (!Var_Exists (OODATE, gn)) {
970 Var_Set(OODATE, "", gn, 0);
972 if (!Var_Exists (ALLSRC, gn)) {
973 Var_Set(ALLSRC, "", gn, 0);
976 if (gn->type & OP_JOIN) {
977 char *p1;
978 Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn, 0);
979 free(p1);
981 gn->flags |= DONE_ALLSRC;
985 *-----------------------------------------------------------------------
986 * MakeStartJobs --
987 * Start as many jobs as possible.
989 * Results:
990 * If the query flag was given to pmake, no job will be started,
991 * but as soon as an out-of-date target is found, this function
992 * returns TRUE. At all other times, this function returns FALSE.
994 * Side Effects:
995 * Nodes are removed from the toBeMade queue and job table slots
996 * are filled.
998 *-----------------------------------------------------------------------
1001 static int
1002 MakeCheckOrder(void *v_bn, void *ignore MAKE_ATTR_UNUSED)
1004 GNode *bn = v_bn;
1006 if (bn->made >= MADE || !(bn->flags & REMAKE))
1007 return 0;
1008 if (DEBUG(MAKE))
1009 fprintf(debug_file, "MakeCheckOrder: Waiting for .ORDER node %s%s\n",
1010 bn->name, bn->cohort_num);
1011 return 1;
1014 static int
1015 MakeBuildChild(void *v_cn, void *toBeMade_next)
1017 GNode *cn = v_cn;
1019 if (DEBUG(MAKE))
1020 fprintf(debug_file, "MakeBuildChild: inspect %s%s, made %d, type %x\n",
1021 cn->name, cn->cohort_num, cn->made, cn->type);
1022 if (cn->made > DEFERRED)
1023 return 0;
1025 /* If this node is on the RHS of a .ORDER, check LHSs. */
1026 if (cn->order_pred && Lst_ForEach(cn->order_pred, MakeCheckOrder, 0)) {
1027 /* Can't build this (or anything else in this child list) yet */
1028 cn->made = DEFERRED;
1029 return 0; /* but keep looking */
1032 if (DEBUG(MAKE))
1033 fprintf(debug_file, "MakeBuildChild: schedule %s%s\n",
1034 cn->name, cn->cohort_num);
1036 cn->made = REQUESTED;
1037 if (toBeMade_next == NULL)
1038 Lst_AtEnd(toBeMade, cn);
1039 else
1040 Lst_InsertBefore(toBeMade, toBeMade_next, cn);
1042 if (cn->unmade_cohorts != 0)
1043 Lst_ForEach(cn->cohorts, MakeBuildChild, toBeMade_next);
1046 * If this node is a .WAIT node with unmade chlidren
1047 * then don't add the next sibling.
1049 return cn->type & OP_WAIT && cn->unmade > 0;
1052 /* When a .ORDER LHS node completes we do this on each RHS */
1053 static int
1054 MakeBuildParent(void *v_pn, void *toBeMade_next)
1056 GNode *pn = v_pn;
1058 if (pn->made != DEFERRED)
1059 return 0;
1061 if (MakeBuildChild(pn, toBeMade_next) == 0) {
1062 /* Mark so that when this node is built we reschedule its parents */
1063 pn->flags |= DONE_ORDER;
1066 return 0;
1069 static Boolean
1070 MakeStartJobs(void)
1072 GNode *gn;
1073 int have_token = 0;
1075 while (!Lst_IsEmpty (toBeMade)) {
1076 /* Get token now to avoid cycling job-list when we only have 1 token */
1077 if (!have_token && !Job_TokenWithdraw())
1078 break;
1079 have_token = 1;
1081 gn = (GNode *)Lst_DeQueue(toBeMade);
1082 if (DEBUG(MAKE))
1083 fprintf(debug_file, "Examining %s%s...\n",
1084 gn->name, gn->cohort_num);
1086 if (gn->made != REQUESTED) {
1087 if (DEBUG(MAKE))
1088 fprintf(debug_file, "state %d\n", gn->made);
1090 make_abort(gn, __LINE__);
1093 if (gn->checked == checked) {
1094 /* We've already looked at this node since a job finished... */
1095 if (DEBUG(MAKE))
1096 fprintf(debug_file, "already checked %s%s\n",
1097 gn->name, gn->cohort_num);
1098 gn->made = DEFERRED;
1099 continue;
1101 gn->checked = checked;
1103 if (gn->unmade != 0) {
1105 * We can't build this yet, add all unmade children to toBeMade,
1106 * just before the current first element.
1108 gn->made = DEFERRED;
1109 Lst_ForEach(gn->children, MakeBuildChild, Lst_First(toBeMade));
1110 /* and drop this node on the floor */
1111 if (DEBUG(MAKE))
1112 fprintf(debug_file, "dropped %s%s\n", gn->name, gn->cohort_num);
1113 continue;
1116 gn->made = BEINGMADE;
1117 if (Make_OODate(gn)) {
1118 if (DEBUG(MAKE)) {
1119 fprintf(debug_file, "out-of-date\n");
1121 if (queryFlag) {
1122 return (TRUE);
1124 Make_DoAllVar(gn);
1125 Job_Make(gn);
1126 have_token = 0;
1127 } else {
1128 if (DEBUG(MAKE)) {
1129 fprintf(debug_file, "up-to-date\n");
1131 gn->made = UPTODATE;
1132 if (gn->type & OP_JOIN) {
1134 * Even for an up-to-date .JOIN node, we need it to have its
1135 * context variables so references to it get the correct
1136 * value for .TARGET when building up the context variables
1137 * of its parent(s)...
1139 Make_DoAllVar(gn);
1141 Make_Update(gn);
1145 if (have_token)
1146 Job_TokenReturn();
1148 return (FALSE);
1152 *-----------------------------------------------------------------------
1153 * MakePrintStatus --
1154 * Print the status of a top-level node, viz. it being up-to-date
1155 * already or not created due to an error in a lower level.
1156 * Callback function for Make_Run via Lst_ForEach.
1158 * Input:
1159 * gnp Node to examine
1160 * cyclep True if gn->unmade being non-zero implies a
1161 * cycle in the graph, not an error in an
1162 * inferior.
1164 * Results:
1165 * Always returns 0.
1167 * Side Effects:
1168 * A message may be printed.
1170 *-----------------------------------------------------------------------
1172 static int
1173 MakePrintStatusOrder(void *ognp, void *gnp)
1175 GNode *ogn = ognp;
1176 GNode *gn = gnp;
1178 if (!(ogn->flags & REMAKE) || ogn->made > REQUESTED)
1179 /* not waiting for this one */
1180 return 0;
1182 printf(" `%s%s' has .ORDER dependency against %s%s "
1183 "(made %d, flags %x, type %x)\n",
1184 gn->name, gn->cohort_num,
1185 ogn->name, ogn->cohort_num, ogn->made, ogn->flags, ogn->type);
1186 if (DEBUG(MAKE) && debug_file != stdout)
1187 fprintf(debug_file, " `%s%s' has .ORDER dependency against %s%s "
1188 "(made %d, flags %x, type %x)\n",
1189 gn->name, gn->cohort_num,
1190 ogn->name, ogn->cohort_num, ogn->made, ogn->flags, ogn->type);
1191 return 0;
1194 static int
1195 MakePrintStatus(void *gnp, void *v_errors)
1197 GNode *gn = (GNode *)gnp;
1198 int *errors = v_errors;
1200 if (gn->flags & DONECYCLE)
1201 /* We've completely processed this node before, don't do it again. */
1202 return 0;
1204 if (gn->unmade == 0) {
1205 gn->flags |= DONECYCLE;
1206 switch (gn->made) {
1207 case UPTODATE:
1208 printf("`%s%s' is up to date.\n", gn->name, gn->cohort_num);
1209 break;
1210 case MADE:
1211 break;
1212 case UNMADE:
1213 case DEFERRED:
1214 case REQUESTED:
1215 case BEINGMADE:
1216 (*errors)++;
1217 printf("`%s%s' was not built (made %d, flags %x, type %x)!\n",
1218 gn->name, gn->cohort_num, gn->made, gn->flags, gn->type);
1219 if (DEBUG(MAKE) && debug_file != stdout)
1220 fprintf(debug_file,
1221 "`%s%s' was not built (made %d, flags %x, type %x)!\n",
1222 gn->name, gn->cohort_num, gn->made, gn->flags, gn->type);
1223 /* Most likely problem is actually caused by .ORDER */
1224 Lst_ForEach(gn->order_pred, MakePrintStatusOrder, gn);
1225 break;
1226 default:
1227 /* Errors - already counted */
1228 printf("`%s%s' not remade because of errors.\n",
1229 gn->name, gn->cohort_num);
1230 if (DEBUG(MAKE) && debug_file != stdout)
1231 fprintf(debug_file, "`%s%s' not remade because of errors.\n",
1232 gn->name, gn->cohort_num);
1233 break;
1235 return 0;
1238 if (DEBUG(MAKE))
1239 fprintf(debug_file, "MakePrintStatus: %s%s has %d unmade children\n",
1240 gn->name, gn->cohort_num, gn->unmade);
1242 * If printing cycles and came to one that has unmade children,
1243 * print out the cycle by recursing on its children.
1245 if (!(gn->flags & CYCLE)) {
1246 /* Fist time we've seen this node, check all children */
1247 gn->flags |= CYCLE;
1248 Lst_ForEach(gn->children, MakePrintStatus, errors);
1249 /* Mark that this node needn't be processed again */
1250 gn->flags |= DONECYCLE;
1251 return 0;
1254 /* Only output the error once per node */
1255 gn->flags |= DONECYCLE;
1256 Error("Graph cycles through `%s%s'", gn->name, gn->cohort_num);
1257 if ((*errors)++ > 100)
1258 /* Abandon the whole error report */
1259 return 1;
1261 /* Reporting for our children will give the rest of the loop */
1262 Lst_ForEach(gn->children, MakePrintStatus, errors);
1263 return 0;
1268 *-----------------------------------------------------------------------
1269 * Make_ExpandUse --
1270 * Expand .USE nodes and create a new targets list
1272 * Input:
1273 * targs the initial list of targets
1275 * Side Effects:
1276 *-----------------------------------------------------------------------
1278 void
1279 Make_ExpandUse(Lst targs)
1281 GNode *gn; /* a temporary pointer */
1282 Lst examine; /* List of targets to examine */
1284 examine = Lst_Duplicate(targs, NULL);
1287 * Make an initial downward pass over the graph, marking nodes to be made
1288 * as we go down. We call Suff_FindDeps to find where a node is and
1289 * to get some children for it if it has none and also has no commands.
1290 * If the node is a leaf, we stick it on the toBeMade queue to
1291 * be looked at in a minute, otherwise we add its children to our queue
1292 * and go on about our business.
1294 while (!Lst_IsEmpty (examine)) {
1295 gn = (GNode *)Lst_DeQueue(examine);
1297 if (gn->flags & REMAKE)
1298 /* We've looked at this one already */
1299 continue;
1300 gn->flags |= REMAKE;
1301 if (DEBUG(MAKE))
1302 fprintf(debug_file, "Make_ExpandUse: examine %s%s\n",
1303 gn->name, gn->cohort_num);
1305 if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts)) {
1306 /* Append all the 'cohorts' to the list of things to examine */
1307 Lst new;
1308 new = Lst_Duplicate(gn->cohorts, NULL);
1309 Lst_Concat(new, examine, LST_CONCLINK);
1310 examine = new;
1314 * Apply any .USE rules before looking for implicit dependencies
1315 * to make sure everything has commands that should...
1316 * Make sure that the TARGET is set, so that we can make
1317 * expansions.
1319 if (gn->type & OP_ARCHV) {
1320 char *eoa, *eon;
1321 eoa = strchr(gn->name, '(');
1322 eon = strchr(gn->name, ')');
1323 if (eoa == NULL || eon == NULL)
1324 continue;
1325 *eoa = '\0';
1326 *eon = '\0';
1327 Var_Set(MEMBER, eoa + 1, gn, 0);
1328 Var_Set(ARCHIVE, gn->name, gn, 0);
1329 *eoa = '(';
1330 *eon = ')';
1333 (void)Dir_MTime(gn, 0);
1334 Var_Set(TARGET, gn->path ? gn->path : gn->name, gn, 0);
1335 Lst_ForEach(gn->children, MakeUnmark, gn);
1336 Lst_ForEach(gn->children, MakeHandleUse, gn);
1338 if ((gn->type & OP_MADE) == 0)
1339 Suff_FindDeps(gn);
1340 else {
1341 /* Pretend we made all this node's children */
1342 Lst_ForEach(gn->children, MakeFindChild, gn);
1343 if (gn->unmade != 0)
1344 printf("Warning: %s%s still has %d unmade children\n",
1345 gn->name, gn->cohort_num, gn->unmade);
1348 if (gn->unmade != 0)
1349 Lst_ForEach(gn->children, MakeAddChild, examine);
1352 Lst_Destroy(examine, NULL);
1356 *-----------------------------------------------------------------------
1357 * Make_ProcessWait --
1358 * Convert .WAIT nodes into dependencies
1360 * Input:
1361 * targs the initial list of targets
1363 *-----------------------------------------------------------------------
1366 static int
1367 link_parent(void *cnp, void *pnp)
1369 GNode *cn = cnp;
1370 GNode *pn = pnp;
1372 Lst_AtEnd(pn->children, cn);
1373 Lst_AtEnd(cn->parents, pn);
1374 pn->unmade++;
1375 return 0;
1378 static int
1379 add_wait_dep(void *v_cn, void *v_wn)
1381 GNode *cn = v_cn;
1382 GNode *wn = v_wn;
1384 if (cn == wn)
1385 return 1;
1387 if (cn == NULL || wn == NULL) {
1388 printf("bad wait dep %p %p\n", cn, wn);
1389 exit(4);
1391 if (DEBUG(MAKE))
1392 fprintf(debug_file, ".WAIT: add dependency %s%s -> %s\n",
1393 cn->name, cn->cohort_num, wn->name);
1395 Lst_AtEnd(wn->children, cn);
1396 wn->unmade++;
1397 Lst_AtEnd(cn->parents, wn);
1398 return 0;
1401 static void
1402 Make_ProcessWait(Lst targs)
1404 GNode *pgn; /* 'parent' node we are examining */
1405 GNode *cgn; /* Each child in turn */
1406 LstNode owln; /* Previous .WAIT node */
1407 Lst examine; /* List of targets to examine */
1408 LstNode ln;
1411 * We need all the nodes to have a common parent in order for the
1412 * .WAIT and .ORDER scheduling to work.
1413 * Perhaps this should be done earlier...
1416 pgn = Targ_NewGN(".MAIN");
1417 pgn->flags = REMAKE;
1418 pgn->type = OP_PHONY | OP_DEPENDS;
1419 /* Get it displayed in the diag dumps */
1420 Lst_AtFront(Targ_List(), pgn);
1422 Lst_ForEach(targs, link_parent, pgn);
1424 /* Start building with the 'dummy' .MAIN' node */
1425 MakeBuildChild(pgn, NULL);
1427 examine = Lst_Init(FALSE);
1428 Lst_AtEnd(examine, pgn);
1430 while (!Lst_IsEmpty (examine)) {
1431 pgn = Lst_DeQueue(examine);
1433 /* We only want to process each child-list once */
1434 if (pgn->flags & DONE_WAIT)
1435 continue;
1436 pgn->flags |= DONE_WAIT;
1437 if (DEBUG(MAKE))
1438 fprintf(debug_file, "Make_ProcessWait: examine %s\n", pgn->name);
1440 if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (pgn->cohorts)) {
1441 /* Append all the 'cohorts' to the list of things to examine */
1442 Lst new;
1443 new = Lst_Duplicate(pgn->cohorts, NULL);
1444 Lst_Concat(new, examine, LST_CONCLINK);
1445 examine = new;
1448 owln = Lst_First(pgn->children);
1449 Lst_Open(pgn->children);
1450 for (; (ln = Lst_Next(pgn->children)) != NULL; ) {
1451 cgn = Lst_Datum(ln);
1452 if (cgn->type & OP_WAIT) {
1453 /* Make the .WAIT node depend on the previous children */
1454 Lst_ForEachFrom(pgn->children, owln, add_wait_dep, cgn);
1455 owln = ln;
1456 } else {
1457 Lst_AtEnd(examine, cgn);
1460 Lst_Close(pgn->children);
1463 Lst_Destroy(examine, NULL);
1467 *-----------------------------------------------------------------------
1468 * Make_Run --
1469 * Initialize the nodes to remake and the list of nodes which are
1470 * ready to be made by doing a breadth-first traversal of the graph
1471 * starting from the nodes in the given list. Once this traversal
1472 * is finished, all the 'leaves' of the graph are in the toBeMade
1473 * queue.
1474 * Using this queue and the Job module, work back up the graph,
1475 * calling on MakeStartJobs to keep the job table as full as
1476 * possible.
1478 * Input:
1479 * targs the initial list of targets
1481 * Results:
1482 * TRUE if work was done. FALSE otherwise.
1484 * Side Effects:
1485 * The make field of all nodes involved in the creation of the given
1486 * targets is set to 1. The toBeMade list is set to contain all the
1487 * 'leaves' of these subgraphs.
1488 *-----------------------------------------------------------------------
1490 Boolean
1491 Make_Run(Lst targs)
1493 int errors; /* Number of errors the Job module reports */
1495 /* Start trying to make the current targets... */
1496 toBeMade = Lst_Init(FALSE);
1498 Make_ExpandUse(targs);
1499 Make_ProcessWait(targs);
1501 if (DEBUG(MAKE)) {
1502 fprintf(debug_file, "#***# full graph\n");
1503 Targ_PrintGraph(1);
1506 if (queryFlag) {
1508 * We wouldn't do any work unless we could start some jobs in the
1509 * next loop... (we won't actually start any, of course, this is just
1510 * to see if any of the targets was out of date)
1512 return (MakeStartJobs());
1515 * Initialization. At the moment, no jobs are running and until some
1516 * get started, nothing will happen since the remaining upward
1517 * traversal of the graph is performed by the routines in job.c upon
1518 * the finishing of a job. So we fill the Job table as much as we can
1519 * before going into our loop.
1521 (void)MakeStartJobs();
1524 * Main Loop: The idea here is that the ending of jobs will take
1525 * care of the maintenance of data structures and the waiting for output
1526 * will cause us to be idle most of the time while our children run as
1527 * much as possible. Because the job table is kept as full as possible,
1528 * the only time when it will be empty is when all the jobs which need
1529 * running have been run, so that is the end condition of this loop.
1530 * Note that the Job module will exit if there were any errors unless the
1531 * keepgoing flag was given.
1533 while (!Lst_IsEmpty(toBeMade) || jobTokensRunning > 0) {
1534 Job_CatchOutput();
1535 (void)MakeStartJobs();
1538 errors = Job_Finish();
1541 * Print the final status of each target. E.g. if it wasn't made
1542 * because some inferior reported an error.
1544 if (DEBUG(MAKE))
1545 fprintf(debug_file, "done: errors %d\n", errors);
1546 if (errors == 0) {
1547 Lst_ForEach(targs, MakePrintStatus, &errors);
1548 if (DEBUG(MAKE)) {
1549 fprintf(debug_file, "done: errors %d\n", errors);
1550 if (errors)
1551 Targ_PrintGraph(4);
1554 return errors != 0;