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