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