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