make.c (137606) | make.c (138232) |
---|---|
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. --- 25 unchanged lines hidden (view full) --- 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 * @(#)make.c 8.1 (Berkeley) 6/6/93 39 */ 40 41#include <sys/cdefs.h> | 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. --- 25 unchanged lines hidden (view full) --- 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 * @(#)make.c 8.1 (Berkeley) 6/6/93 39 */ 40 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: head/usr.bin/make/make.c 137606 2004-11-12 08:58:07Z phk $"); | 42__FBSDID("$FreeBSD: head/usr.bin/make/make.c 138232 2004-11-30 17:46:29Z harti $"); |
43 44/*- 45 * make.c -- 46 * The functions which perform the examination of targets and 47 * their suitability for creation 48 * 49 * Interface: 50 * Make_Run Initialize things for the module and recreate --- 37 unchanged lines hidden (view full) --- 88 * TRUE, there's a cycle in the graph */ 89 90static int MakeAddChild(void *, void *); 91static int MakeAddAllSrc(void *, void *); 92static int MakeTimeStamp(void *, void *); 93static int MakeHandleUse(void *, void *); 94static Boolean MakeStartJobs(void); 95static int MakePrintStatus(void *, void *); | 43 44/*- 45 * make.c -- 46 * The functions which perform the examination of targets and 47 * their suitability for creation 48 * 49 * Interface: 50 * Make_Run Initialize things for the module and recreate --- 37 unchanged lines hidden (view full) --- 88 * TRUE, there's a cycle in the graph */ 89 90static int MakeAddChild(void *, void *); 91static int MakeAddAllSrc(void *, void *); 92static int MakeTimeStamp(void *, void *); 93static int MakeHandleUse(void *, void *); 94static Boolean MakeStartJobs(void); 95static int MakePrintStatus(void *, void *); |
96 |
|
96/*- 97 *----------------------------------------------------------------------- 98 * Make_TimeStamp -- 99 * Set the cmtime field of a parent node based on the mtime stamp in its 100 * child. Called from MakeOODate via Lst_ForEach. 101 * 102 * Results: 103 * Always returns 0. 104 * 105 * Side Effects: 106 * The cmtime of the parent node will be changed if the mtime 107 * field of the child is greater than it. 108 *----------------------------------------------------------------------- 109 */ 110int | 97/*- 98 *----------------------------------------------------------------------- 99 * Make_TimeStamp -- 100 * Set the cmtime field of a parent node based on the mtime stamp in its 101 * child. Called from MakeOODate via Lst_ForEach. 102 * 103 * Results: 104 * Always returns 0. 105 * 106 * Side Effects: 107 * The cmtime of the parent node will be changed if the mtime 108 * field of the child is greater than it. 109 *----------------------------------------------------------------------- 110 */ 111int |
111Make_TimeStamp (GNode *pgn, GNode *cgn) | 112Make_TimeStamp(GNode *pgn, GNode *cgn) |
112{ | 113{ |
114 |
|
113 if (cgn->mtime > pgn->cmtime) { 114 pgn->cmtime = cgn->mtime; 115 } 116 return (0); 117} 118 119static int | 115 if (cgn->mtime > pgn->cmtime) { 116 pgn->cmtime = cgn->mtime; 117 } 118 return (0); 119} 120 121static int |
120MakeTimeStamp (void *pgn, void *cgn) | 122MakeTimeStamp(void *pgn, void *cgn) |
121{ | 123{ |
122 return Make_TimeStamp((GNode *) pgn, (GNode *) cgn); | 124 125 return (Make_TimeStamp((GNode *)pgn, (GNode *)cgn)); |
123} | 126} |
124 | 127 |
125/*- 126 *----------------------------------------------------------------------- 127 * Make_OODate -- 128 * See if a given node is out of date with respect to its sources. 129 * Used by Make_Run when deciding which nodes to place on the 130 * toBeMade queue initially and by Make_Update to screen out USE and 131 * EXEC nodes. In the latter case, however, any other sort of node 132 * must be considered out-of-date since at least one of its children 133 * will have been recreated. 134 * 135 * Results: 136 * TRUE if the node is out of date. FALSE otherwise. 137 * 138 * Side Effects: 139 * The mtime field of the node and the cmtime field of its parents 140 * will/may be changed. 141 *----------------------------------------------------------------------- 142 */ 143Boolean | 128/*- 129 *----------------------------------------------------------------------- 130 * Make_OODate -- 131 * See if a given node is out of date with respect to its sources. 132 * Used by Make_Run when deciding which nodes to place on the 133 * toBeMade queue initially and by Make_Update to screen out USE and 134 * EXEC nodes. In the latter case, however, any other sort of node 135 * must be considered out-of-date since at least one of its children 136 * will have been recreated. 137 * 138 * Results: 139 * TRUE if the node is out of date. FALSE otherwise. 140 * 141 * Side Effects: 142 * The mtime field of the node and the cmtime field of its parents 143 * will/may be changed. 144 *----------------------------------------------------------------------- 145 */ 146Boolean |
144Make_OODate (GNode *gn) | 147Make_OODate(GNode *gn) |
145{ 146 Boolean oodate; 147 148 /* 149 * Certain types of targets needn't even be sought as their datedness 150 * doesn't depend on their modification time... 151 */ | 148{ 149 Boolean oodate; 150 151 /* 152 * Certain types of targets needn't even be sought as their datedness 153 * doesn't depend on their modification time... 154 */ |
152 if ((gn->type & (OP_JOIN|OP_USE|OP_EXEC)) == 0) { 153 (void) Dir_MTime (gn); | 155 if ((gn->type & (OP_JOIN | OP_USE | OP_EXEC)) == 0) { 156 Dir_MTime(gn); |
154 if (gn->mtime != 0) { 155 DEBUGF(MAKE, ("modified %s...", Targ_FmtTime(gn->mtime))); 156 } else { 157 DEBUGF(MAKE, ("non-existent...")); 158 } 159 } 160 161 /* --- 19 unchanged lines hidden (view full) --- 181 oodate = FALSE; 182 } else if (gn->type & OP_LIB) { 183 DEBUGF(MAKE, ("library...")); 184 185 /* 186 * always out of date if no children and :: target 187 */ 188 | 157 if (gn->mtime != 0) { 158 DEBUGF(MAKE, ("modified %s...", Targ_FmtTime(gn->mtime))); 159 } else { 160 DEBUGF(MAKE, ("non-existent...")); 161 } 162 } 163 164 /* --- 19 unchanged lines hidden (view full) --- 184 oodate = FALSE; 185 } else if (gn->type & OP_LIB) { 186 DEBUGF(MAKE, ("library...")); 187 188 /* 189 * always out of date if no children and :: target 190 */ 191 |
189 oodate = Arch_LibOODate (gn) || | 192 oodate = Arch_LibOODate(gn) || |
190 ((gn->cmtime == 0) && (gn->type & OP_DOUBLEDEP)); 191 } else if (gn->type & OP_JOIN) { 192 /* 193 * A target with the .JOIN attribute is only considered 194 * out-of-date if any of its children was out-of-date. 195 */ 196 DEBUGF(MAKE, (".JOIN node...")); 197 oodate = gn->childMade; --- 35 unchanged lines hidden (view full) --- 233 /* 234 * If the target isn't out-of-date, the parents need to know its 235 * modification time. Note that targets that appear to be out-of-date 236 * but aren't, because they have no commands and aren't of type OP_NOP, 237 * have their mtime stay below their children's mtime to keep parents from 238 * thinking they're out-of-date. 239 */ 240 if (!oodate) { | 193 ((gn->cmtime == 0) && (gn->type & OP_DOUBLEDEP)); 194 } else if (gn->type & OP_JOIN) { 195 /* 196 * A target with the .JOIN attribute is only considered 197 * out-of-date if any of its children was out-of-date. 198 */ 199 DEBUGF(MAKE, (".JOIN node...")); 200 oodate = gn->childMade; --- 35 unchanged lines hidden (view full) --- 236 /* 237 * If the target isn't out-of-date, the parents need to know its 238 * modification time. Note that targets that appear to be out-of-date 239 * but aren't, because they have no commands and aren't of type OP_NOP, 240 * have their mtime stay below their children's mtime to keep parents from 241 * thinking they're out-of-date. 242 */ 243 if (!oodate) { |
241 Lst_ForEach (gn->parents, MakeTimeStamp, (void *)gn); | 244 Lst_ForEach(gn->parents, MakeTimeStamp, (void *)gn); |
242 } 243 244 return (oodate); 245} | 245 } 246 247 return (oodate); 248} |
246 | 249 |
247/*- 248 *----------------------------------------------------------------------- 249 * MakeAddChild -- 250 * Function used by Make_Run to add a child to the list l. 251 * It will only add the child if its make field is FALSE. 252 * 253 * Results: 254 * Always returns 0 255 * 256 * Side Effects: 257 * The given list is extended 258 *----------------------------------------------------------------------- 259 */ 260static int | 250/*- 251 *----------------------------------------------------------------------- 252 * MakeAddChild -- 253 * Function used by Make_Run to add a child to the list l. 254 * It will only add the child if its make field is FALSE. 255 * 256 * Results: 257 * Always returns 0 258 * 259 * Side Effects: 260 * The given list is extended 261 *----------------------------------------------------------------------- 262 */ 263static int |
261MakeAddChild (void *gnp, void *lp) | 264MakeAddChild(void *gnp, void *lp) |
262{ | 265{ |
263 GNode *gn = (GNode *) gnp; 264 Lst l = (Lst) lp; | 266 GNode *gn = (GNode *)gnp; 267 Lst l = (Lst)lp; |
265 266 if (!gn->make && !(gn->type & OP_USE)) { | 268 269 if (!gn->make && !(gn->type & OP_USE)) { |
267 (void)Lst_EnQueue (l, (void *)gn); | 270 Lst_EnQueue(l, (void *)gn); |
268 } 269 return (0); 270} | 271 } 272 return (0); 273} |
271 | 274 |
272/*- 273 *----------------------------------------------------------------------- 274 * Make_HandleUse -- 275 * Function called by Make_Run and SuffApplyTransform on the downward 276 * pass to handle .USE and transformation nodes. A callback function 277 * for Lst_ForEach, it implements the .USE and transformation 278 * functionality by copying the node's commands, type flags 279 * and children to the parent node. Should be called before the --- 8 unchanged lines hidden (view full) --- 288 * 289 * Side Effects: 290 * Children and commands may be added to the parent and the parent's 291 * type may be changed. 292 * 293 *----------------------------------------------------------------------- 294 */ 295int | 275/*- 276 *----------------------------------------------------------------------- 277 * Make_HandleUse -- 278 * Function called by Make_Run and SuffApplyTransform on the downward 279 * pass to handle .USE and transformation nodes. A callback function 280 * for Lst_ForEach, it implements the .USE and transformation 281 * functionality by copying the node's commands, type flags 282 * and children to the parent node. Should be called before the --- 8 unchanged lines hidden (view full) --- 291 * 292 * Side Effects: 293 * Children and commands may be added to the parent and the parent's 294 * type may be changed. 295 * 296 *----------------------------------------------------------------------- 297 */ 298int |
296Make_HandleUse (GNode *cgn, GNode *pgn) | 299Make_HandleUse(GNode *cgn, GNode *pgn) |
297{ 298 GNode *gn; /* A child of the .USE node */ 299 LstNode ln; /* An element in the children list */ 300 301 if (cgn->type & (OP_USE|OP_TRANSFORM)) { 302 if ((cgn->type & OP_USE) || Lst_IsEmpty(pgn->commands)) { 303 /* 304 * .USE or transformation and target has no commands -- append 305 * the child's commands to the parent. 306 */ | 300{ 301 GNode *gn; /* A child of the .USE node */ 302 LstNode ln; /* An element in the children list */ 303 304 if (cgn->type & (OP_USE|OP_TRANSFORM)) { 305 if ((cgn->type & OP_USE) || Lst_IsEmpty(pgn->commands)) { 306 /* 307 * .USE or transformation and target has no commands -- append 308 * the child's commands to the parent. 309 */ |
307 (void) Lst_Concat (pgn->commands, cgn->commands, LST_CONCNEW); | 310 Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW); |
308 } 309 | 311 } 312 |
310 if (Lst_Open (cgn->children) == SUCCESS) { 311 while ((ln = Lst_Next (cgn->children)) != NULL) { 312 gn = (GNode *)Lst_Datum (ln); | 313 if (Lst_Open(cgn->children) == SUCCESS) { 314 while ((ln = Lst_Next(cgn->children)) != NULL) { 315 gn = (GNode *)Lst_Datum(ln); |
313 | 316 |
314 if (Lst_Member (pgn->children, gn) == NULL) { 315 (void) Lst_AtEnd (pgn->children, gn); 316 (void) Lst_AtEnd (gn->parents, pgn); | 317 if (Lst_Member(pgn->children, gn) == NULL) { 318 Lst_AtEnd(pgn->children, gn); 319 Lst_AtEnd(gn->parents, pgn); |
317 pgn->unmade += 1; 318 } 319 } | 320 pgn->unmade += 1; 321 } 322 } |
320 Lst_Close (cgn->children); | 323 Lst_Close(cgn->children); |
321 } 322 | 324 } 325 |
323 pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_TRANSFORM); | 326 pgn->type |= cgn->type & ~(OP_OPMASK | OP_USE | OP_TRANSFORM); |
324 325 /* 326 * This child node is now "made", so we decrement the count of 327 * unmade children in the parent... We also remove the child 328 * from the parent's list to accurately reflect the number of decent 329 * children the parent has. This is used by Make_Run to decide 330 * whether to queue the parent or examine its children... 331 */ 332 if (cgn->type & OP_USE) { 333 pgn->unmade--; 334 } 335 } 336 return (0); 337} | 327 328 /* 329 * This child node is now "made", so we decrement the count of 330 * unmade children in the parent... We also remove the child 331 * from the parent's list to accurately reflect the number of decent 332 * children the parent has. This is used by Make_Run to decide 333 * whether to queue the parent or examine its children... 334 */ 335 if (cgn->type & OP_USE) { 336 pgn->unmade--; 337 } 338 } 339 return (0); 340} |
341 |
|
338static int | 342static int |
339MakeHandleUse (void *pgn, void *cgn) | 343MakeHandleUse(void *pgn, void *cgn) |
340{ | 344{ |
341 return Make_HandleUse((GNode *) pgn, (GNode *) cgn); | 345 346 return (Make_HandleUse((GNode *)pgn, (GNode *)cgn)); |
342} | 347} |
343 | 348 |
344/*- 345 *----------------------------------------------------------------------- 346 * Make_Update -- 347 * Perform update on the parents of a node. Used by JobFinish once 348 * a node has been dealt with and by MakeStartJobs if it finds an 349 * up-to-date node. 350 * 351 * Results: --- 10 unchanged lines hidden (view full) --- 362 * altered if the child's mtime is big enough. 363 * 364 * Finally, if the child is the implied source for the parent, the 365 * parent's IMPSRC variable is set appropriately. 366 * 367 *----------------------------------------------------------------------- 368 */ 369void | 349/*- 350 *----------------------------------------------------------------------- 351 * Make_Update -- 352 * Perform update on the parents of a node. Used by JobFinish once 353 * a node has been dealt with and by MakeStartJobs if it finds an 354 * up-to-date node. 355 * 356 * Results: --- 10 unchanged lines hidden (view full) --- 367 * altered if the child's mtime is big enough. 368 * 369 * Finally, if the child is the implied source for the parent, the 370 * parent's IMPSRC variable is set appropriately. 371 * 372 *----------------------------------------------------------------------- 373 */ 374void |
370Make_Update (GNode *cgn) | 375Make_Update(GNode *cgn) |
371{ 372 GNode *pgn; /* the parent node */ 373 char *cname; /* the child's name */ 374 LstNode ln; /* Element in parents and iParents lists */ 375 char *p1; 376 | 376{ 377 GNode *pgn; /* the parent node */ 378 char *cname; /* the child's name */ 379 LstNode ln; /* Element in parents and iParents lists */ 380 char *p1; 381 |
377 cname = Var_Value (TARGET, cgn, &p1); | 382 cname = Var_Value(TARGET, cgn, &p1); |
378 free(p1); 379 380 /* 381 * If the child was actually made, see what its modification time is 382 * now -- some rules won't actually update the file. If the file still 383 * doesn't exist, make its mtime now. 384 */ 385 if (cgn->made != UPTODATE) { --- 51 unchanged lines hidden (view full) --- 437 */ 438 if (noExecute || (cgn->type & OP_SAVE_CMDS) || Dir_MTime(cgn) == 0) { 439 cgn->mtime = now; 440 } 441 DEBUGF(MAKE, ("update time: %s\n", Targ_FmtTime(cgn->mtime))); 442#endif 443 } 444 | 383 free(p1); 384 385 /* 386 * If the child was actually made, see what its modification time is 387 * now -- some rules won't actually update the file. If the file still 388 * doesn't exist, make its mtime now. 389 */ 390 if (cgn->made != UPTODATE) { --- 51 unchanged lines hidden (view full) --- 442 */ 443 if (noExecute || (cgn->type & OP_SAVE_CMDS) || Dir_MTime(cgn) == 0) { 444 cgn->mtime = now; 445 } 446 DEBUGF(MAKE, ("update time: %s\n", Targ_FmtTime(cgn->mtime))); 447#endif 448 } 449 |
445 if (Lst_Open (cgn->parents) == SUCCESS) { 446 while ((ln = Lst_Next (cgn->parents)) != NULL) { 447 pgn = (GNode *)Lst_Datum (ln); | 450 if (Lst_Open(cgn->parents) == SUCCESS) { 451 while ((ln = Lst_Next(cgn->parents)) != NULL) { 452 pgn = (GNode *)Lst_Datum(ln); |
448 if (pgn->make) { 449 pgn->unmade -= 1; 450 | 453 if (pgn->make) { 454 pgn->unmade -= 1; 455 |
451 if ( ! (cgn->type & (OP_EXEC|OP_USE))) { | 456 if (!(cgn->type & (OP_EXEC | OP_USE))) { |
452 if (cgn->made == MADE) { 453 pgn->childMade = TRUE; 454 if (pgn->cmtime < cgn->mtime) { 455 pgn->cmtime = cgn->mtime; 456 } 457 } else { | 457 if (cgn->made == MADE) { 458 pgn->childMade = TRUE; 459 if (pgn->cmtime < cgn->mtime) { 460 pgn->cmtime = cgn->mtime; 461 } 462 } else { |
458 (void)Make_TimeStamp (pgn, cgn); | 463 Make_TimeStamp(pgn, cgn); |
459 } 460 } 461 if (pgn->unmade == 0) { 462 /* 463 * Queue the node up -- any unmade predecessors will 464 * be dealt with in MakeStartJobs. 465 */ | 464 } 465 } 466 if (pgn->unmade == 0) { 467 /* 468 * Queue the node up -- any unmade predecessors will 469 * be dealt with in MakeStartJobs. 470 */ |
466 (void)Lst_EnQueue (toBeMade, (void *)pgn); | 471 Lst_EnQueue(toBeMade, (void *)pgn); |
467 } else if (pgn->unmade < 0) { | 472 } else if (pgn->unmade < 0) { |
468 Error ("Graph cycles through %s", pgn->name); | 473 Error("Graph cycles through %s", pgn->name); |
469 } 470 } 471 } | 474 } 475 } 476 } |
472 Lst_Close (cgn->parents); | 477 Lst_Close(cgn->parents); |
473 } 474 /* 475 * Deal with successor nodes. If any is marked for making and has an unmade 476 * count of 0, has not been made and isn't in the examination queue, 477 * it means we need to place it in the queue as it restrained itself 478 * before. 479 */ 480 for (ln = Lst_First(cgn->successors); ln != NULL; ln = Lst_Succ(ln)) { 481 GNode *succ = (GNode *)Lst_Datum(ln); 482 483 if (succ->make && succ->unmade == 0 && succ->made == UNMADE && 484 Lst_Member(toBeMade, (void *)succ) == NULL) 485 { | 478 } 479 /* 480 * Deal with successor nodes. If any is marked for making and has an unmade 481 * count of 0, has not been made and isn't in the examination queue, 482 * it means we need to place it in the queue as it restrained itself 483 * before. 484 */ 485 for (ln = Lst_First(cgn->successors); ln != NULL; ln = Lst_Succ(ln)) { 486 GNode *succ = (GNode *)Lst_Datum(ln); 487 488 if (succ->make && succ->unmade == 0 && succ->made == UNMADE && 489 Lst_Member(toBeMade, (void *)succ) == NULL) 490 { |
486 (void)Lst_EnQueue(toBeMade, (void *)succ); | 491 Lst_EnQueue(toBeMade, (void *)succ); |
487 } 488 } 489 490 /* 491 * Set the .PREFIX and .IMPSRC variables for all the implied parents 492 * of this node. 493 */ | 492 } 493 } 494 495 /* 496 * Set the .PREFIX and .IMPSRC variables for all the implied parents 497 * of this node. 498 */ |
494 if (Lst_Open (cgn->iParents) == SUCCESS) { | 499 if (Lst_Open(cgn->iParents) == SUCCESS) { |
495 char *ptr; 496 char *cpref = Var_Value(PREFIX, cgn, &ptr); 497 | 500 char *ptr; 501 char *cpref = Var_Value(PREFIX, cgn, &ptr); 502 |
498 while ((ln = Lst_Next (cgn->iParents)) != NULL) { | 503 while ((ln = Lst_Next(cgn->iParents)) != NULL) { |
499 pgn = (GNode *)Lst_Datum (ln); 500 if (pgn->make) { | 504 pgn = (GNode *)Lst_Datum (ln); 505 if (pgn->make) { |
501 Var_Set (IMPSRC, cname, pgn); 502 Var_Set (PREFIX, cpref, pgn); | 506 Var_Set(IMPSRC, cname, pgn); 507 Var_Set(PREFIX, cpref, pgn); |
503 } 504 } 505 free(ptr); | 508 } 509 } 510 free(ptr); |
506 Lst_Close (cgn->iParents); | 511 Lst_Close(cgn->iParents); |
507 } 508} | 512 } 513} |
509 | 514 |
510/*- 511 *----------------------------------------------------------------------- 512 * MakeAddAllSrc -- 513 * Add a child's name to the ALLSRC and OODATE variables of the given 514 * node. Called from Make_DoAllVar via Lst_ForEach. A child is added only 515 * if it has not been given the .EXEC, .USE or .INVISIBLE attributes. 516 * .EXEC and .USE children are very rarely going to be files, so... 517 * A child is added to the OODATE variable if its modification time is --- 5 unchanged lines hidden (view full) --- 523 * Results: 524 * Always returns 0 525 * 526 * Side Effects: 527 * The ALLSRC variable for the given node is extended. 528 *----------------------------------------------------------------------- 529 */ 530static int | 515/*- 516 *----------------------------------------------------------------------- 517 * MakeAddAllSrc -- 518 * Add a child's name to the ALLSRC and OODATE variables of the given 519 * node. Called from Make_DoAllVar via Lst_ForEach. A child is added only 520 * if it has not been given the .EXEC, .USE or .INVISIBLE attributes. 521 * .EXEC and .USE children are very rarely going to be files, so... 522 * A child is added to the OODATE variable if its modification time is --- 5 unchanged lines hidden (view full) --- 528 * Results: 529 * Always returns 0 530 * 531 * Side Effects: 532 * The ALLSRC variable for the given node is extended. 533 *----------------------------------------------------------------------- 534 */ 535static int |
531MakeAddAllSrc (void *cgnp, void *pgnp) | 536MakeAddAllSrc(void *cgnp, void *pgnp) |
532{ 533 GNode *cgn = (GNode *) cgnp; 534 GNode *pgn = (GNode *) pgnp; | 537{ 538 GNode *cgn = (GNode *) cgnp; 539 GNode *pgn = (GNode *) pgnp; |
535 if ((cgn->type & (OP_EXEC|OP_USE|OP_INVISIBLE)) == 0) { | 540 541 if ((cgn->type & (OP_EXEC | OP_USE | OP_INVISIBLE)) == 0) { |
536 char *child; 537 char *p1 = NULL; 538 539 if (OP_NOP(cgn->type)) { 540 /* 541 * this node is only source; use the specific pathname for it 542 */ 543 child = cgn->path ? cgn->path : cgn->name; 544 } 545 else 546 child = Var_Value(TARGET, cgn, &p1); | 542 char *child; 543 char *p1 = NULL; 544 545 if (OP_NOP(cgn->type)) { 546 /* 547 * this node is only source; use the specific pathname for it 548 */ 549 child = cgn->path ? cgn->path : cgn->name; 550 } 551 else 552 child = Var_Value(TARGET, cgn, &p1); |
547 Var_Append (ALLSRC, child, pgn); | 553 Var_Append(ALLSRC, child, pgn); |
548 if (pgn->type & OP_JOIN) { 549 if (cgn->made == MADE) { 550 Var_Append(OODATE, child, pgn); 551 } 552 } else if ((pgn->mtime < cgn->mtime) || 553 (cgn->mtime >= now && cgn->made == MADE)) 554 { 555 /* --- 13 unchanged lines hidden (view full) --- 569 * some people, this is good... 570 */ 571 Var_Append(OODATE, child, pgn); 572 } 573 free(p1); 574 } 575 return (0); 576} | 554 if (pgn->type & OP_JOIN) { 555 if (cgn->made == MADE) { 556 Var_Append(OODATE, child, pgn); 557 } 558 } else if ((pgn->mtime < cgn->mtime) || 559 (cgn->mtime >= now && cgn->made == MADE)) 560 { 561 /* --- 13 unchanged lines hidden (view full) --- 575 * some people, this is good... 576 */ 577 Var_Append(OODATE, child, pgn); 578 } 579 free(p1); 580 } 581 return (0); 582} |
577 | 583 |
578/*- 579 *----------------------------------------------------------------------- 580 * Make_DoAllVar -- 581 * Set up the ALLSRC and OODATE variables. Sad to say, it must be 582 * done separately, rather than while traversing the graph. This is 583 * because Make defined OODATE to contain all sources whose modification 584 * times were later than that of the target, *not* those sources that 585 * were out-of-date. Since in both compatibility and native modes, --- 7 unchanged lines hidden (view full) --- 593 * 594 * Side Effects: 595 * The ALLSRC and OODATE variables of the given node is filled in. 596 * If the node is a .JOIN node, its TARGET variable will be set to 597 * match its ALLSRC variable. 598 *----------------------------------------------------------------------- 599 */ 600void | 584/*- 585 *----------------------------------------------------------------------- 586 * Make_DoAllVar -- 587 * Set up the ALLSRC and OODATE variables. Sad to say, it must be 588 * done separately, rather than while traversing the graph. This is 589 * because Make defined OODATE to contain all sources whose modification 590 * times were later than that of the target, *not* those sources that 591 * were out-of-date. Since in both compatibility and native modes, --- 7 unchanged lines hidden (view full) --- 599 * 600 * Side Effects: 601 * The ALLSRC and OODATE variables of the given node is filled in. 602 * If the node is a .JOIN node, its TARGET variable will be set to 603 * match its ALLSRC variable. 604 *----------------------------------------------------------------------- 605 */ 606void |
601Make_DoAllVar (GNode *gn) | 607Make_DoAllVar(GNode *gn) |
602{ | 608{ |
603 Lst_ForEach (gn->children, MakeAddAllSrc, (void *) gn); | |
604 | 609 |
610 Lst_ForEach(gn->children, MakeAddAllSrc, (void *)gn); 611 |
|
605 if (!Var_Exists (OODATE, gn)) { | 612 if (!Var_Exists (OODATE, gn)) { |
606 Var_Set (OODATE, "", gn); | 613 Var_Set(OODATE, "", gn); |
607 } 608 if (!Var_Exists (ALLSRC, gn)) { | 614 } 615 if (!Var_Exists (ALLSRC, gn)) { |
609 Var_Set (ALLSRC, "", gn); | 616 Var_Set(ALLSRC, "", gn); |
610 } 611 612 if (gn->type & OP_JOIN) { 613 char *p1; | 617 } 618 619 if (gn->type & OP_JOIN) { 620 char *p1; |
614 Var_Set (TARGET, Var_Value (ALLSRC, gn, &p1), gn); | 621 622 Var_Set(TARGET, Var_Value(ALLSRC, gn, &p1), gn); |
615 free(p1); 616 } 617} | 623 free(p1); 624 } 625} |
618 | 626 |
619/*- 620 *----------------------------------------------------------------------- 621 * MakeStartJobs -- 622 * Start as many jobs as possible. 623 * 624 * Results: 625 * If the query flag was given to pmake, no job will be started, 626 * but as soon as an out-of-date target is found, this function 627 * returns TRUE. At all other times, this function returns FALSE. 628 * 629 * Side Effects: 630 * Nodes are removed from the toBeMade queue and job table slots 631 * are filled. 632 * 633 *----------------------------------------------------------------------- 634 */ 635static Boolean | 627/*- 628 *----------------------------------------------------------------------- 629 * MakeStartJobs -- 630 * Start as many jobs as possible. 631 * 632 * Results: 633 * If the query flag was given to pmake, no job will be started, 634 * but as soon as an out-of-date target is found, this function 635 * returns TRUE. At all other times, this function returns FALSE. 636 * 637 * Side Effects: 638 * Nodes are removed from the toBeMade queue and job table slots 639 * are filled. 640 * 641 *----------------------------------------------------------------------- 642 */ 643static Boolean |
636MakeStartJobs (void) | 644MakeStartJobs(void) |
637{ 638 GNode *gn; 639 640 while (!Lst_IsEmpty (toBeMade) && !Job_Full()) { | 645{ 646 GNode *gn; 647 648 while (!Lst_IsEmpty (toBeMade) && !Job_Full()) { |
641 gn = (GNode *) Lst_DeQueue (toBeMade); | 649 gn = (GNode *)Lst_DeQueue(toBeMade); |
642 DEBUGF(MAKE, ("Examining %s...", gn->name)); 643 /* 644 * Make sure any and all predecessors that are going to be made, 645 * have been. 646 */ 647 if (!Lst_IsEmpty(gn->preds)) { 648 LstNode ln; 649 --- 12 unchanged lines hidden (view full) --- 662 * make but as yet unmade and will place the node on the queue. 663 */ 664 if (ln != NULL) { 665 continue; 666 } 667 } 668 669 numNodes--; | 650 DEBUGF(MAKE, ("Examining %s...", gn->name)); 651 /* 652 * Make sure any and all predecessors that are going to be made, 653 * have been. 654 */ 655 if (!Lst_IsEmpty(gn->preds)) { 656 LstNode ln; 657 --- 12 unchanged lines hidden (view full) --- 670 * make but as yet unmade and will place the node on the queue. 671 */ 672 if (ln != NULL) { 673 continue; 674 } 675 } 676 677 numNodes--; |
670 if (Make_OODate (gn)) { | 678 if (Make_OODate(gn)) { |
671 DEBUGF(MAKE, ("out-of-date\n")); 672 if (queryFlag) { 673 return (TRUE); 674 } | 679 DEBUGF(MAKE, ("out-of-date\n")); 680 if (queryFlag) { 681 return (TRUE); 682 } |
675 Make_DoAllVar (gn); 676 Job_Make (gn); | 683 Make_DoAllVar(gn); 684 Job_Make(gn); |
677 } else { 678 DEBUGF(MAKE, ("up-to-date\n")); 679 gn->made = UPTODATE; 680 if (gn->type & OP_JOIN) { 681 /* 682 * Even for an up-to-date .JOIN node, we need it to have its 683 * context variables so references to it get the correct 684 * value for .TARGET when building up the context variables 685 * of its parent(s)... 686 */ | 685 } else { 686 DEBUGF(MAKE, ("up-to-date\n")); 687 gn->made = UPTODATE; 688 if (gn->type & OP_JOIN) { 689 /* 690 * Even for an up-to-date .JOIN node, we need it to have its 691 * context variables so references to it get the correct 692 * value for .TARGET when building up the context variables 693 * of its parent(s)... 694 */ |
687 Make_DoAllVar (gn); | 695 Make_DoAllVar(gn); |
688 } 689 | 696 } 697 |
690 Make_Update (gn); | 698 Make_Update(gn); |
691 } 692 } 693 return (FALSE); 694} | 699 } 700 } 701 return (FALSE); 702} |
695 | 703 |
696/*- 697 *----------------------------------------------------------------------- 698 * MakePrintStatus -- 699 * Print the status of a top-level node, viz. it being up-to-date 700 * already or not created due to an error in a lower level. 701 * Callback function for Make_Run via Lst_ForEach. If gn->unmade is 702 * nonzero and that is meant to imply a cycle in the graph, then 703 * cycle is TRUE. --- 4 unchanged lines hidden (view full) --- 708 * Side Effects: 709 * A message may be printed. 710 * 711 *----------------------------------------------------------------------- 712 */ 713static int 714MakePrintStatus(void *gnp, void *cyclep) 715{ | 704/*- 705 *----------------------------------------------------------------------- 706 * MakePrintStatus -- 707 * Print the status of a top-level node, viz. it being up-to-date 708 * already or not created due to an error in a lower level. 709 * Callback function for Make_Run via Lst_ForEach. If gn->unmade is 710 * nonzero and that is meant to imply a cycle in the graph, then 711 * cycle is TRUE. --- 4 unchanged lines hidden (view full) --- 716 * Side Effects: 717 * A message may be printed. 718 * 719 *----------------------------------------------------------------------- 720 */ 721static int 722MakePrintStatus(void *gnp, void *cyclep) 723{ |
716 GNode *gn = (GNode *) gnp; 717 Boolean cycle = *(Boolean *) cyclep; | 724 GNode *gn = (GNode *)gnp; 725 Boolean cycle = *(Boolean *)cyclep; 726 |
718 if (gn->made == UPTODATE) { | 727 if (gn->made == UPTODATE) { |
719 printf ("`%s' is up to date.\n", gn->name); | 728 printf("`%s' is up to date.\n", gn->name); |
720 } else if (gn->unmade != 0) { 721 if (cycle) { 722 Boolean t = TRUE; 723 /* 724 * If printing cycles and came to one that has unmade children, 725 * print out the cycle by recursing on its children. Note a 726 * cycle like: 727 * a : b 728 * b : c 729 * c : b 730 * will cause this to erroneously complain about a being in 731 * the cycle, but this is a good approximation. 732 */ 733 if (gn->made == CYCLE) { 734 Error("Graph cycles through `%s'", gn->name); 735 gn->made = ENDCYCLE; | 729 } else if (gn->unmade != 0) { 730 if (cycle) { 731 Boolean t = TRUE; 732 /* 733 * If printing cycles and came to one that has unmade children, 734 * print out the cycle by recursing on its children. Note a 735 * cycle like: 736 * a : b 737 * b : c 738 * c : b 739 * will cause this to erroneously complain about a being in 740 * the cycle, but this is a good approximation. 741 */ 742 if (gn->made == CYCLE) { 743 Error("Graph cycles through `%s'", gn->name); 744 gn->made = ENDCYCLE; |
736 Lst_ForEach(gn->children, MakePrintStatus, (void *) &t); | 745 Lst_ForEach(gn->children, MakePrintStatus, (void *)&t); |
737 gn->made = UNMADE; 738 } else if (gn->made != ENDCYCLE) { 739 gn->made = CYCLE; | 746 gn->made = UNMADE; 747 } else if (gn->made != ENDCYCLE) { 748 gn->made = CYCLE; |
740 Lst_ForEach(gn->children, MakePrintStatus, (void *) &t); | 749 Lst_ForEach(gn->children, MakePrintStatus, (void *)&t); |
741 } 742 } else { | 750 } 751 } else { |
743 printf ("`%s' not remade because of errors.\n", gn->name); | 752 printf("`%s' not remade because of errors.\n", gn->name); |
744 } 745 } 746 return (0); 747} | 753 } 754 } 755 return (0); 756} |
748 | 757 |
749/*- 750 *----------------------------------------------------------------------- 751 * Make_Run -- 752 * Initialize the nodes to remake and the list of nodes which are 753 * ready to be made by doing a breadth-first traversal of the graph 754 * starting from the nodes in the given list. Once this traversal 755 * is finished, all the 'leaves' of the graph are in the toBeMade 756 * queue. --- 6 unchanged lines hidden (view full) --- 763 * 764 * Side Effects: 765 * The make field of all nodes involved in the creation of the given 766 * targets is set to 1. The toBeMade list is set to contain all the 767 * 'leaves' of these subgraphs. 768 *----------------------------------------------------------------------- 769 */ 770Boolean | 758/*- 759 *----------------------------------------------------------------------- 760 * Make_Run -- 761 * Initialize the nodes to remake and the list of nodes which are 762 * ready to be made by doing a breadth-first traversal of the graph 763 * starting from the nodes in the given list. Once this traversal 764 * is finished, all the 'leaves' of the graph are in the toBeMade 765 * queue. --- 6 unchanged lines hidden (view full) --- 772 * 773 * Side Effects: 774 * The make field of all nodes involved in the creation of the given 775 * targets is set to 1. The toBeMade list is set to contain all the 776 * 'leaves' of these subgraphs. 777 *----------------------------------------------------------------------- 778 */ 779Boolean |
771Make_Run (Lst targs) | 780Make_Run(Lst targs) |
772{ 773 GNode *gn; /* a temporary pointer */ 774 Lst examine; /* List of targets to examine */ 775 int errors; /* Number of errors the Job module reports */ 776 | 781{ 782 GNode *gn; /* a temporary pointer */ 783 Lst examine; /* List of targets to examine */ 784 int errors; /* Number of errors the Job module reports */ 785 |
777 toBeMade = Lst_Init (FALSE); | 786 toBeMade = Lst_Init(FALSE); |
778 779 examine = Lst_Duplicate(targs, NOCOPY); 780 numNodes = 0; 781 782 /* 783 * Make an initial downward pass over the graph, marking nodes to be made 784 * as we go down. We call Suff_FindDeps to find where a node is and 785 * to get some children for it if it has none and also has no commands. 786 * If the node is a leaf, we stick it on the toBeMade queue to 787 * be looked at in a minute, otherwise we add its children to our queue 788 * and go on about our business. 789 */ | 787 788 examine = Lst_Duplicate(targs, NOCOPY); 789 numNodes = 0; 790 791 /* 792 * Make an initial downward pass over the graph, marking nodes to be made 793 * as we go down. We call Suff_FindDeps to find where a node is and 794 * to get some children for it if it has none and also has no commands. 795 * If the node is a leaf, we stick it on the toBeMade queue to 796 * be looked at in a minute, otherwise we add its children to our queue 797 * and go on about our business. 798 */ |
790 while (!Lst_IsEmpty (examine)) { 791 gn = (GNode *) Lst_DeQueue (examine); | 799 while (!Lst_IsEmpty(examine)) { 800 gn = (GNode *)Lst_DeQueue(examine); |
792 793 if (!gn->make) { 794 gn->make = TRUE; 795 numNodes++; 796 797 /* 798 * Apply any .USE rules before looking for implicit dependencies 799 * to make sure everything has commands that should... 800 */ | 801 802 if (!gn->make) { 803 gn->make = TRUE; 804 numNodes++; 805 806 /* 807 * Apply any .USE rules before looking for implicit dependencies 808 * to make sure everything has commands that should... 809 */ |
801 Lst_ForEach (gn->children, MakeHandleUse, (void *)gn); 802 Suff_FindDeps (gn); | 810 Lst_ForEach(gn->children, MakeHandleUse, (void *)gn); 811 Suff_FindDeps(gn); |
803 804 if (gn->unmade != 0) { | 812 813 if (gn->unmade != 0) { |
805 Lst_ForEach (gn->children, MakeAddChild, (void *)examine); | 814 Lst_ForEach(gn->children, MakeAddChild, (void *)examine); |
806 } else { | 815 } else { |
807 (void)Lst_EnQueue (toBeMade, (void *)gn); | 816 Lst_EnQueue(toBeMade, (void *)gn); |
808 } 809 } 810 } 811 | 817 } 818 } 819 } 820 |
812 Lst_Destroy (examine, NOFREE); | 821 Lst_Destroy(examine, NOFREE); |
813 814 if (queryFlag) { 815 /* 816 * We wouldn't do any work unless we could start some jobs in the 817 * next loop... (we won't actually start any, of course, this is just 818 * to see if any of the targets was out of date) 819 */ 820 return (MakeStartJobs()); 821 } else { 822 /* 823 * Initialization. At the moment, no jobs are running and until some 824 * get started, nothing will happen since the remaining upward 825 * traversal of the graph is performed by the routines in job.c upon 826 * the finishing of a job. So we fill the Job table as much as we can 827 * before going into our loop. 828 */ | 822 823 if (queryFlag) { 824 /* 825 * We wouldn't do any work unless we could start some jobs in the 826 * next loop... (we won't actually start any, of course, this is just 827 * to see if any of the targets was out of date) 828 */ 829 return (MakeStartJobs()); 830 } else { 831 /* 832 * Initialization. At the moment, no jobs are running and until some 833 * get started, nothing will happen since the remaining upward 834 * traversal of the graph is performed by the routines in job.c upon 835 * the finishing of a job. So we fill the Job table as much as we can 836 * before going into our loop. 837 */ |
829 (void) MakeStartJobs(); | 838 MakeStartJobs(); |
830 } 831 832 /* 833 * Main Loop: The idea here is that the ending of jobs will take 834 * care of the maintenance of data structures and the waiting for output 835 * will cause us to be idle most of the time while our children run as 836 * much as possible. Because the job table is kept as full as possible, 837 * the only time when it will be empty is when all the jobs which need 838 * running have been run, so that is the end condition of this loop. 839 * Note that the Job module will exit if there were any errors unless the 840 * keepgoing flag was given. 841 */ 842 while (!Job_Empty ()) { | 839 } 840 841 /* 842 * Main Loop: The idea here is that the ending of jobs will take 843 * care of the maintenance of data structures and the waiting for output 844 * will cause us to be idle most of the time while our children run as 845 * much as possible. Because the job table is kept as full as possible, 846 * the only time when it will be empty is when all the jobs which need 847 * running have been run, so that is the end condition of this loop. 848 * Note that the Job module will exit if there were any errors unless the 849 * keepgoing flag was given. 850 */ 851 while (!Job_Empty ()) { |
843 Job_CatchOutput (!Lst_IsEmpty (toBeMade)); 844 Job_CatchChildren (!usePipes); 845 (void)MakeStartJobs(); | 852 Job_CatchOutput(!Lst_IsEmpty (toBeMade)); 853 Job_CatchChildren(!usePipes); 854 MakeStartJobs(); |
846 } 847 848 errors = Job_Finish(); 849 850 /* 851 * Print the final status of each target. E.g. if it wasn't made 852 * because some inferior reported an error. 853 */ 854 errors = ((errors == 0) && (numNodes != 0)); | 855 } 856 857 errors = Job_Finish(); 858 859 /* 860 * Print the final status of each target. E.g. if it wasn't made 861 * because some inferior reported an error. 862 */ 863 errors = ((errors == 0) && (numNodes != 0)); |
855 Lst_ForEach(targs, MakePrintStatus, (void *) &errors); | 864 Lst_ForEach(targs, MakePrintStatus, (void *)&errors); |
856 857 return (TRUE); 858} | 865 866 return (TRUE); 867} |