1 /* $NetBSD: make.c,v 1.186 2020/11/01 17:47:26 rillig Exp $ */ 2 3 /* 4 * Copyright (c) 1988, 1989, 1990, 1993 5 * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * Copyright (c) 1989 by Berkeley Softworks 37 * All rights reserved. 38 * 39 * This code is derived from software contributed to Berkeley by 40 * Adam de Boor. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by the University of 53 * California, Berkeley and its contributors. 54 * 4. Neither the name of the University nor the names of its contributors 55 * may be used to endorse or promote products derived from this software 56 * without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 */ 70 71 /*- 72 * make.c -- 73 * The functions which perform the examination of targets and 74 * their suitability for creation 75 * 76 * Interface: 77 * Make_Run Initialize things for the module and recreate 78 * whatever needs recreating. Returns TRUE if 79 * work was (or would have been) done and FALSE 80 * otherwise. 81 * 82 * Make_Update Update all parents of a given child. Performs 83 * various bookkeeping chores like the updating 84 * of the youngestChild field of the parent, filling 85 * of the IMPSRC context variable, etc. It will 86 * place the parent on the toBeMade queue if it 87 * should be. 88 * 89 * Make_TimeStamp Function to set the parent's youngestChild field 90 * based on a child's modification time. 91 * 92 * Make_DoAllVar Set up the various local variables for a 93 * target, including the .ALLSRC variable, making 94 * sure that any variable that needs to exist 95 * at the very least has the empty value. 96 * 97 * Make_OODate Determine if a target is out-of-date. 98 * 99 * Make_HandleUse See if a child is a .USE node for a parent 100 * and perform the .USE actions if so. 101 * 102 * Make_ExpandUse Expand .USE nodes 103 */ 104 105 #include "make.h" 106 #include "dir.h" 107 #include "job.h" 108 109 /* "@(#)make.c 8.1 (Berkeley) 6/6/93" */ 110 MAKE_RCSID("$NetBSD: make.c,v 1.186 2020/11/01 17:47:26 rillig Exp $"); 111 112 /* Sequence # to detect recursion. */ 113 static unsigned int checked = 1; 114 115 /* The current fringe of the graph. 116 * These are nodes which await examination by MakeOODate. 117 * It is added to by Make_Update and subtracted from by MakeStartJobs */ 118 static GNodeList *toBeMade; 119 120 static int MakeCheckOrder(void *, void *); 121 static int MakeBuildParent(void *, void *); 122 123 void 124 debug_printf(const char *fmt, ...) 125 { 126 va_list args; 127 128 va_start(args, fmt); 129 vfprintf(opts.debug_file, fmt, args); 130 va_end(args); 131 } 132 133 MAKE_ATTR_DEAD static void 134 make_abort(GNode *gn, int line) 135 { 136 debug_printf("make_abort from line %d\n", line); 137 Targ_PrintNode(gn, 2); 138 Targ_PrintNodes(toBeMade, 2); 139 Targ_PrintGraph(3); 140 abort(); 141 } 142 143 ENUM_VALUE_RTTI_8(GNodeMade, 144 UNMADE, DEFERRED, REQUESTED, BEINGMADE, 145 MADE, UPTODATE, ERROR, ABORTED); 146 147 ENUM_FLAGS_RTTI_31(GNodeType, 148 OP_DEPENDS, OP_FORCE, OP_DOUBLEDEP, 149 /* OP_OPMASK is omitted since it combines other flags */ 150 OP_OPTIONAL, OP_USE, OP_EXEC, OP_IGNORE, 151 OP_PRECIOUS, OP_SILENT, OP_MAKE, OP_JOIN, 152 OP_MADE, OP_SPECIAL, OP_USEBEFORE, OP_INVISIBLE, 153 OP_NOTMAIN, OP_PHONY, OP_NOPATH, OP_WAIT, 154 OP_NOMETA, OP_META, OP_NOMETA_CMP, OP_SUBMAKE, 155 OP_TRANSFORM, OP_MEMBER, OP_LIB, OP_ARCHV, 156 OP_HAS_COMMANDS, OP_SAVE_CMDS, OP_DEPS_FOUND, OP_MARK); 157 158 ENUM_FLAGS_RTTI_10(GNodeFlags, 159 REMAKE, CHILDMADE, FORCE, DONE_WAIT, 160 DONE_ORDER, FROM_DEPEND, DONE_ALLSRC, CYCLE, 161 DONECYCLE, INTERNAL); 162 163 void 164 GNode_FprintDetails(FILE *f, const char *prefix, const GNode *gn, 165 const char *suffix) 166 { 167 char type_buf[GNodeType_ToStringSize]; 168 char flags_buf[GNodeFlags_ToStringSize]; 169 170 fprintf(f, "%smade %s, type %s, flags %s%s", 171 prefix, 172 Enum_ValueToString(gn->made, GNodeMade_ToStringSpecs), 173 Enum_FlagsToString(type_buf, sizeof type_buf, 174 gn->type, GNodeType_ToStringSpecs), 175 Enum_FlagsToString(flags_buf, sizeof flags_buf, 176 gn->flags, GNodeFlags_ToStringSpecs), 177 suffix); 178 } 179 180 Boolean 181 GNode_ShouldExecute(GNode *gn) 182 { 183 return !((gn->type & OP_MAKE) ? opts.noRecursiveExecute : opts.noExecute); 184 } 185 186 /* Update the youngest child of the node, according to the given child. */ 187 void 188 Make_TimeStamp(GNode *pgn, GNode *cgn) 189 { 190 if (pgn->youngestChild == NULL || cgn->mtime > pgn->youngestChild->mtime) { 191 pgn->youngestChild = cgn; 192 } 193 } 194 195 /* See if the node is out of date with respect to its sources. 196 * 197 * Used by Make_Run when deciding which nodes to place on the 198 * toBeMade queue initially and by Make_Update to screen out .USE and 199 * .EXEC nodes. In the latter case, however, any other sort of node 200 * must be considered out-of-date since at least one of its children 201 * will have been recreated. 202 * 203 * The mtime field of the node and the youngestChild field of its parents 204 * may be changed. 205 */ 206 Boolean 207 Make_OODate(GNode *gn) 208 { 209 Boolean oodate; 210 211 /* 212 * Certain types of targets needn't even be sought as their datedness 213 * doesn't depend on their modification time... 214 */ 215 if ((gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC)) == 0) { 216 (void)Dir_MTime(gn, 1); 217 if (DEBUG(MAKE)) { 218 if (gn->mtime != 0) { 219 debug_printf("modified %s...", Targ_FmtTime(gn->mtime)); 220 } else { 221 debug_printf("non-existent..."); 222 } 223 } 224 } 225 226 /* 227 * A target is remade in one of the following circumstances: 228 * its modification time is smaller than that of its youngest child and 229 * it would actually be run (has commands or is not GNode_IsTarget) 230 * it's the object of a force operator 231 * it has no children, was on the lhs of an operator and doesn't exist 232 * already. 233 * 234 * Libraries are only considered out-of-date if the archive module says 235 * they are. 236 * 237 * These weird rules are brought to you by Backward-Compatibility and 238 * the strange people who wrote 'Make'. 239 */ 240 if (gn->type & (OP_USE|OP_USEBEFORE)) { 241 /* 242 * If the node is a USE node it is *never* out of date 243 * no matter *what*. 244 */ 245 DEBUG0(MAKE, ".USE node..."); 246 oodate = FALSE; 247 } else if ((gn->type & OP_LIB) && 248 ((gn->mtime==0) || Arch_IsLib(gn))) { 249 DEBUG0(MAKE, "library..."); 250 251 /* 252 * always out of date if no children and :: target 253 * or non-existent. 254 */ 255 oodate = (gn->mtime == 0 || Arch_LibOODate(gn) || 256 (gn->youngestChild == NULL && (gn->type & OP_DOUBLEDEP))); 257 } else if (gn->type & OP_JOIN) { 258 /* 259 * A target with the .JOIN attribute is only considered 260 * out-of-date if any of its children was out-of-date. 261 */ 262 DEBUG0(MAKE, ".JOIN node..."); 263 DEBUG1(MAKE, "source %smade...", gn->flags & CHILDMADE ? "" : "not "); 264 oodate = (gn->flags & CHILDMADE) ? TRUE : FALSE; 265 } else if (gn->type & (OP_FORCE|OP_EXEC|OP_PHONY)) { 266 /* 267 * A node which is the object of the force (!) operator or which has 268 * the .EXEC attribute is always considered out-of-date. 269 */ 270 if (DEBUG(MAKE)) { 271 if (gn->type & OP_FORCE) { 272 debug_printf("! operator..."); 273 } else if (gn->type & OP_PHONY) { 274 debug_printf(".PHONY node..."); 275 } else { 276 debug_printf(".EXEC node..."); 277 } 278 } 279 oodate = TRUE; 280 } else if ((gn->youngestChild != NULL && 281 gn->mtime < gn->youngestChild->mtime) || 282 (gn->youngestChild == NULL && 283 ((gn->mtime == 0 && !(gn->type & OP_OPTIONAL)) 284 || gn->type & OP_DOUBLEDEP))) 285 { 286 /* 287 * A node whose modification time is less than that of its 288 * youngest child or that has no children (youngestChild == NULL) and 289 * either doesn't exist (mtime == 0) and it isn't optional 290 * or was the object of a * :: operator is out-of-date. 291 * Why? Because that's the way Make does it. 292 */ 293 if (DEBUG(MAKE)) { 294 if (gn->youngestChild != NULL && 295 gn->mtime < gn->youngestChild->mtime) { 296 debug_printf("modified before source %s...", 297 GNode_Path(gn->youngestChild)); 298 } else if (gn->mtime == 0) { 299 debug_printf("non-existent and no sources..."); 300 } else { 301 debug_printf(":: operator and no sources..."); 302 } 303 } 304 oodate = TRUE; 305 } else { 306 /* 307 * When a non-existing child with no sources 308 * (such as a typically used FORCE source) has been made and 309 * the target of the child (usually a directory) has the same 310 * timestamp as the timestamp just given to the non-existing child 311 * after it was considered made. 312 */ 313 if (DEBUG(MAKE)) { 314 if (gn->flags & FORCE) 315 debug_printf("non existing child..."); 316 } 317 oodate = (gn->flags & FORCE) ? TRUE : FALSE; 318 } 319 320 #ifdef USE_META 321 if (useMeta) { 322 oodate = meta_oodate(gn, oodate); 323 } 324 #endif 325 326 /* 327 * If the target isn't out-of-date, the parents need to know its 328 * modification time. Note that targets that appear to be out-of-date 329 * but aren't, because they have no commands and are GNode_IsTarget, 330 * have their mtime stay below their children's mtime to keep parents from 331 * thinking they're out-of-date. 332 */ 333 if (!oodate) { 334 GNodeListNode *ln; 335 for (ln = gn->parents->first; ln != NULL; ln = ln->next) 336 Make_TimeStamp(ln->datum, gn); 337 } 338 339 return oodate; 340 } 341 342 /* Add the node to the list if it needs to be examined. */ 343 static int 344 MakeAddChild(void *gnp, void *lp) 345 { 346 GNode *gn = gnp; 347 GNodeList *l = lp; 348 349 if ((gn->flags & REMAKE) == 0 && !(gn->type & (OP_USE|OP_USEBEFORE))) { 350 DEBUG2(MAKE, "MakeAddChild: need to examine %s%s\n", 351 gn->name, gn->cohort_num); 352 Lst_Enqueue(l, gn); 353 } 354 return 0; 355 } 356 357 /* Find the pathname of a child that was already made. 358 * 359 * The path and mtime of the node and the youngestChild of the parent are 360 * updated; the unmade children count of the parent is decremented. 361 * 362 * Input: 363 * gnp the node to find 364 */ 365 static int 366 MakeFindChild(void *gnp, void *pgnp) 367 { 368 GNode *gn = gnp; 369 GNode *pgn = pgnp; 370 371 (void)Dir_MTime(gn, 0); 372 Make_TimeStamp(pgn, gn); 373 pgn->unmade--; 374 375 return 0; 376 } 377 378 /* Called by Make_Run and SuffApplyTransform on the downward pass to handle 379 * .USE and transformation nodes, by copying the child node's commands, type 380 * flags and children to the parent node. 381 * 382 * A .USE node is much like an explicit transformation rule, except its 383 * commands are always added to the target node, even if the target already 384 * has commands. 385 * 386 * Input: 387 * cgn The source node, which is either a .USE/.USEBEFORE 388 * node or a transformation node (OP_TRANSFORM). 389 * pgn The target node 390 */ 391 void 392 Make_HandleUse(GNode *cgn, GNode *pgn) 393 { 394 GNodeListNode *ln; /* An element in the children list */ 395 396 #ifdef DEBUG_SRC 397 if ((cgn->type & (OP_USE|OP_USEBEFORE|OP_TRANSFORM)) == 0) { 398 debug_printf("Make_HandleUse: called for plain node %s\n", cgn->name); 399 return; 400 } 401 #endif 402 403 if ((cgn->type & (OP_USE|OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) { 404 if (cgn->type & OP_USEBEFORE) { 405 /* .USEBEFORE */ 406 Lst_PrependAll(pgn->commands, cgn->commands); 407 } else { 408 /* .USE, or target has no commands */ 409 Lst_AppendAll(pgn->commands, cgn->commands); 410 } 411 } 412 413 for (ln = cgn->children->first; ln != NULL; ln = ln->next) { 414 GNode *gn = ln->datum; 415 416 /* 417 * Expand variables in the .USE node's name 418 * and save the unexpanded form. 419 * We don't need to do this for commands. 420 * They get expanded properly when we execute. 421 */ 422 if (gn->uname == NULL) { 423 gn->uname = gn->name; 424 } else { 425 free(gn->name); 426 } 427 (void)Var_Subst(gn->uname, pgn, VARE_WANTRES, &gn->name); 428 /* TODO: handle errors */ 429 if (gn->uname && strcmp(gn->name, gn->uname) != 0) { 430 /* See if we have a target for this node. */ 431 GNode *tgn = Targ_FindNode(gn->name); 432 if (tgn != NULL) 433 gn = tgn; 434 } 435 436 Lst_Append(pgn->children, gn); 437 Lst_Append(gn->parents, pgn); 438 pgn->unmade++; 439 } 440 441 pgn->type |= cgn->type & ~(OP_OPMASK|OP_USE|OP_USEBEFORE|OP_TRANSFORM); 442 } 443 444 /* Used by Make_Run on the downward pass to handle .USE nodes. Should be 445 * called before the children are enqueued to be looked at by MakeAddChild. 446 * 447 * For a .USE child, the commands, type flags and children are copied to the 448 * parent node, and since the relation to the .USE node is then no longer 449 * needed, that relation is removed. 450 * 451 * Input: 452 * cgn the child, which may be a .USE node 453 * pgn the current parent 454 */ 455 static void 456 MakeHandleUse(GNode *cgn, GNode *pgn, GNodeListNode *ln) 457 { 458 Boolean unmarked; 459 460 unmarked = ((cgn->type & OP_MARK) == 0); 461 cgn->type |= OP_MARK; 462 463 if ((cgn->type & (OP_USE|OP_USEBEFORE)) == 0) 464 return; 465 466 if (unmarked) 467 Make_HandleUse(cgn, pgn); 468 469 /* 470 * This child node is now "made", so we decrement the count of 471 * unmade children in the parent... We also remove the child 472 * from the parent's list to accurately reflect the number of decent 473 * children the parent has. This is used by Make_Run to decide 474 * whether to queue the parent or examine its children... 475 */ 476 Lst_Remove(pgn->children, ln); 477 pgn->unmade--; 478 } 479 480 static void 481 HandleUseNodes(GNode *gn) 482 { 483 GNodeListNode *ln, *nln; 484 for (ln = gn->children->first; ln != NULL; ln = nln) { 485 nln = ln->next; 486 MakeHandleUse(ln->datum, gn, ln); 487 } 488 } 489 490 491 /* Check the modification time of a gnode, and update it if necessary. 492 * Return 0 if the gnode does not exist, or its filesystem time if it does. */ 493 time_t 494 Make_Recheck(GNode *gn) 495 { 496 time_t mtime = Dir_MTime(gn, 1); 497 498 #ifndef RECHECK 499 /* 500 * We can't re-stat the thing, but we can at least take care of rules 501 * where a target depends on a source that actually creates the 502 * target, but only if it has changed, e.g. 503 * 504 * parse.h : parse.o 505 * 506 * parse.o : parse.y 507 * yacc -d parse.y 508 * cc -c y.tab.c 509 * mv y.tab.o parse.o 510 * cmp -s y.tab.h parse.h || mv y.tab.h parse.h 511 * 512 * In this case, if the definitions produced by yacc haven't changed 513 * from before, parse.h won't have been updated and gn->mtime will 514 * reflect the current modification time for parse.h. This is 515 * something of a kludge, I admit, but it's a useful one.. 516 * XXX: People like to use a rule like 517 * 518 * FRC: 519 * 520 * To force things that depend on FRC to be made, so we have to 521 * check for gn->children being empty as well... 522 */ 523 if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) { 524 gn->mtime = now; 525 } 526 #else 527 /* 528 * This is what Make does and it's actually a good thing, as it 529 * allows rules like 530 * 531 * cmp -s y.tab.h parse.h || cp y.tab.h parse.h 532 * 533 * to function as intended. Unfortunately, thanks to the stateless 534 * nature of NFS (by which I mean the loose coupling of two clients 535 * using the same file from a common server), there are times 536 * when the modification time of a file created on a remote 537 * machine will not be modified before the local stat() implied by 538 * the Dir_MTime occurs, thus leading us to believe that the file 539 * is unchanged, wreaking havoc with files that depend on this one. 540 * 541 * I have decided it is better to make too much than to make too 542 * little, so this stuff is commented out unless you're sure it's ok. 543 * -- ardeb 1/12/88 544 */ 545 /* 546 * Christos, 4/9/92: If we are saving commands pretend that 547 * the target is made now. Otherwise archives with ... rules 548 * don't work! 549 */ 550 if (!GNode_ShouldExecute(gn) || (gn->type & OP_SAVE_CMDS) || 551 (mtime == 0 && !(gn->type & OP_WAIT))) { 552 DEBUG2(MAKE, " recheck(%s): update time from %s to now\n", 553 gn->name, Targ_FmtTime(gn->mtime)); 554 gn->mtime = now; 555 } 556 else { 557 DEBUG2(MAKE, " recheck(%s): current update time: %s\n", 558 gn->name, Targ_FmtTime(gn->mtime)); 559 } 560 #endif 561 return mtime; 562 } 563 564 /* 565 * Set the .PREFIX and .IMPSRC variables for all the implied parents 566 * of this node. 567 */ 568 static void 569 UpdateImplicitParentsVars(GNode *cgn, const char *cname) 570 { 571 GNodeListNode *ln; 572 const char *cpref = GNode_VarPrefix(cgn); 573 574 for (ln = cgn->implicitParents->first; ln != NULL; ln = ln->next) { 575 GNode *pgn = ln->datum; 576 if (pgn->flags & REMAKE) { 577 Var_Set(IMPSRC, cname, pgn); 578 if (cpref != NULL) 579 Var_Set(PREFIX, cpref, pgn); 580 } 581 } 582 } 583 584 /* Perform update on the parents of a node. Used by JobFinish once 585 * a node has been dealt with and by MakeStartJobs if it finds an 586 * up-to-date node. 587 * 588 * The unmade field of pgn is decremented and pgn may be placed on 589 * the toBeMade queue if this field becomes 0. 590 * 591 * If the child was made, the parent's flag CHILDMADE field will be 592 * set true. 593 * 594 * If the child is not up-to-date and still does not exist, 595 * set the FORCE flag on the parents. 596 * 597 * If the child wasn't made, the youngestChild field of the parent will be 598 * altered if the child's mtime is big enough. 599 * 600 * Finally, if the child is the implied source for the parent, the 601 * parent's IMPSRC variable is set appropriately. 602 */ 603 void 604 Make_Update(GNode *cgn) 605 { 606 const char *cname; /* the child's name */ 607 time_t mtime = -1; 608 GNodeList *parents; 609 GNodeListNode *ln; 610 GNode *centurion; 611 612 /* It is save to re-examine any nodes again */ 613 checked++; 614 615 cname = GNode_VarTarget(cgn); 616 617 DEBUG2(MAKE, "Make_Update: %s%s\n", cgn->name, cgn->cohort_num); 618 619 /* 620 * If the child was actually made, see what its modification time is 621 * now -- some rules won't actually update the file. If the file still 622 * doesn't exist, make its mtime now. 623 */ 624 if (cgn->made != UPTODATE) { 625 mtime = Make_Recheck(cgn); 626 } 627 628 /* 629 * If this is a `::' node, we must consult its first instance 630 * which is where all parents are linked. 631 */ 632 if ((centurion = cgn->centurion) != NULL) { 633 if (!Lst_IsEmpty(cgn->parents)) 634 Punt("%s%s: cohort has parents", cgn->name, cgn->cohort_num); 635 centurion->unmade_cohorts--; 636 if (centurion->unmade_cohorts < 0) 637 Error("Graph cycles through centurion %s", centurion->name); 638 } else { 639 centurion = cgn; 640 } 641 parents = centurion->parents; 642 643 /* If this was a .ORDER node, schedule the RHS */ 644 Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, toBeMade->first); 645 646 /* Now mark all the parents as having one less unmade child */ 647 for (ln = parents->first; ln != NULL; ln = ln->next) { 648 GNode *pgn = ln->datum; 649 650 if (DEBUG(MAKE)) 651 debug_printf("inspect parent %s%s: flags %x, " 652 "type %x, made %d, unmade %d ", 653 pgn->name, pgn->cohort_num, pgn->flags, 654 pgn->type, pgn->made, pgn->unmade - 1); 655 656 if (!(pgn->flags & REMAKE)) { 657 /* This parent isn't needed */ 658 DEBUG0(MAKE, "- not needed\n"); 659 continue; 660 } 661 if (mtime == 0 && !(cgn->type & OP_WAIT)) 662 pgn->flags |= FORCE; 663 664 /* 665 * If the parent has the .MADE attribute, its timestamp got 666 * updated to that of its newest child, and its unmade 667 * child count got set to zero in Make_ExpandUse(). 668 * However other things might cause us to build one of its 669 * children - and so we mustn't do any processing here when 670 * the child build finishes. 671 */ 672 if (pgn->type & OP_MADE) { 673 DEBUG0(MAKE, "- .MADE\n"); 674 continue; 675 } 676 677 if ( ! (cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE))) { 678 if (cgn->made == MADE) 679 pgn->flags |= CHILDMADE; 680 (void)Make_TimeStamp(pgn, cgn); 681 } 682 683 /* 684 * A parent must wait for the completion of all instances 685 * of a `::' dependency. 686 */ 687 if (centurion->unmade_cohorts != 0 || centurion->made < MADE) { 688 DEBUG2(MAKE, "- centurion made %d, %d unmade cohorts\n", 689 centurion->made, centurion->unmade_cohorts); 690 continue; 691 } 692 693 /* One more child of this parent is now made */ 694 pgn->unmade--; 695 if (pgn->unmade < 0) { 696 if (DEBUG(MAKE)) { 697 debug_printf("Graph cycles through %s%s\n", 698 pgn->name, pgn->cohort_num); 699 Targ_PrintGraph(2); 700 } 701 Error("Graph cycles through %s%s", pgn->name, pgn->cohort_num); 702 } 703 704 /* We must always rescan the parents of .WAIT and .ORDER nodes. */ 705 if (pgn->unmade != 0 && !(centurion->type & OP_WAIT) 706 && !(centurion->flags & DONE_ORDER)) { 707 DEBUG0(MAKE, "- unmade children\n"); 708 continue; 709 } 710 if (pgn->made != DEFERRED) { 711 /* 712 * Either this parent is on a different branch of the tree, 713 * or it on the RHS of a .WAIT directive 714 * or it is already on the toBeMade list. 715 */ 716 DEBUG0(MAKE, "- not deferred\n"); 717 continue; 718 } 719 assert(pgn->order_pred != NULL); 720 if (Lst_ForEachUntil(pgn->order_pred, MakeCheckOrder, 0)) { 721 /* A .ORDER rule stops us building this */ 722 continue; 723 } 724 if (DEBUG(MAKE)) { 725 debug_printf("- %s%s made, schedule %s%s (made %d)\n", 726 cgn->name, cgn->cohort_num, 727 pgn->name, pgn->cohort_num, pgn->made); 728 Targ_PrintNode(pgn, 2); 729 } 730 /* Ok, we can schedule the parent again */ 731 pgn->made = REQUESTED; 732 Lst_Enqueue(toBeMade, pgn); 733 } 734 735 UpdateImplicitParentsVars(cgn, cname); 736 } 737 738 static void 739 UnmarkChildren(GNode *gn) 740 { 741 GNodeListNode *ln; 742 743 for (ln = gn->children->first; ln != NULL; ln = ln->next) { 744 GNode *child = ln->datum; 745 child->type &= ~OP_MARK; 746 } 747 } 748 749 /* Add a child's name to the ALLSRC and OODATE variables of the given 750 * node, but only if it has not been given the .EXEC, .USE or .INVISIBLE 751 * attributes. .EXEC and .USE children are very rarely going to be files, 752 * so... 753 * 754 * If the child is a .JOIN node, its ALLSRC is propagated to the parent. 755 * 756 * A child is added to the OODATE variable if its modification time is 757 * later than that of its parent, as defined by Make, except if the 758 * parent is a .JOIN node. In that case, it is only added to the OODATE 759 * variable if it was actually made (since .JOIN nodes don't have 760 * modification times, the comparison is rather unfair...).. 761 * 762 * Input: 763 * cgn The child to add 764 * pgn The parent to whose ALLSRC variable it should 765 * be added 766 */ 767 static void 768 MakeAddAllSrc(GNode *cgn, GNode *pgn) 769 { 770 if (cgn->type & OP_MARK) 771 return; 772 cgn->type |= OP_MARK; 773 774 if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) { 775 const char *child, *allsrc; 776 777 if (cgn->type & OP_ARCHV) 778 child = GNode_VarMember(cgn); 779 else 780 child = GNode_Path(cgn); 781 if (cgn->type & OP_JOIN) { 782 allsrc = GNode_VarAllsrc(cgn); 783 } else { 784 allsrc = child; 785 } 786 if (allsrc != NULL) 787 Var_Append(ALLSRC, allsrc, pgn); 788 if (pgn->type & OP_JOIN) { 789 if (cgn->made == MADE) { 790 Var_Append(OODATE, child, pgn); 791 } 792 } else if ((pgn->mtime < cgn->mtime) || 793 (cgn->mtime >= now && cgn->made == MADE)) 794 { 795 /* 796 * It goes in the OODATE variable if the parent is younger than the 797 * child or if the child has been modified more recently than 798 * the start of the make. This is to keep pmake from getting 799 * confused if something else updates the parent after the 800 * make starts (shouldn't happen, I know, but sometimes it 801 * does). In such a case, if we've updated the kid, the parent 802 * is likely to have a modification time later than that of 803 * the kid and anything that relies on the OODATE variable will 804 * be hosed. 805 * 806 * XXX: This will cause all made children to go in the OODATE 807 * variable, even if they're not touched, if RECHECK isn't defined, 808 * since cgn->mtime is set to now in Make_Update. According to 809 * some people, this is good... 810 */ 811 Var_Append(OODATE, child, pgn); 812 } 813 } 814 } 815 816 /* Set up the ALLSRC and OODATE variables. Sad to say, it must be 817 * done separately, rather than while traversing the graph. This is 818 * because Make defined OODATE to contain all sources whose modification 819 * times were later than that of the target, *not* those sources that 820 * were out-of-date. Since in both compatibility and native modes, 821 * the modification time of the parent isn't found until the child 822 * has been dealt with, we have to wait until now to fill in the 823 * variable. As for ALLSRC, the ordering is important and not 824 * guaranteed when in native mode, so it must be set here, too. 825 * 826 * If the node is a .JOIN node, its TARGET variable will be set to 827 * match its ALLSRC variable. 828 */ 829 void 830 Make_DoAllVar(GNode *gn) 831 { 832 GNodeListNode *ln; 833 834 if (gn->flags & DONE_ALLSRC) 835 return; 836 837 UnmarkChildren(gn); 838 for (ln = gn->children->first; ln != NULL; ln = ln->next) 839 MakeAddAllSrc(ln->datum, gn); 840 841 if (!Var_Exists(OODATE, gn)) { 842 Var_Set(OODATE, "", gn); 843 } 844 if (!Var_Exists(ALLSRC, gn)) { 845 Var_Set(ALLSRC, "", gn); 846 } 847 848 if (gn->type & OP_JOIN) 849 Var_Set(TARGET, GNode_VarAllsrc(gn), gn); 850 gn->flags |= DONE_ALLSRC; 851 } 852 853 static int 854 MakeCheckOrder(void *v_bn, void *ignore MAKE_ATTR_UNUSED) 855 { 856 GNode *bn = v_bn; 857 858 if (bn->made >= MADE || !(bn->flags & REMAKE)) 859 return 0; 860 861 DEBUG2(MAKE, "MakeCheckOrder: Waiting for .ORDER node %s%s\n", 862 bn->name, bn->cohort_num); 863 return 1; 864 } 865 866 static int 867 MakeBuildChild(void *v_cn, void *toBeMade_next) 868 { 869 GNode *cn = v_cn; 870 871 DEBUG4(MAKE, "MakeBuildChild: inspect %s%s, made %d, type %x\n", 872 cn->name, cn->cohort_num, cn->made, cn->type); 873 if (cn->made > DEFERRED) 874 return 0; 875 876 /* If this node is on the RHS of a .ORDER, check LHSs. */ 877 assert(cn->order_pred); 878 if (Lst_ForEachUntil(cn->order_pred, MakeCheckOrder, 0)) { 879 /* Can't build this (or anything else in this child list) yet */ 880 cn->made = DEFERRED; 881 return 0; /* but keep looking */ 882 } 883 884 DEBUG2(MAKE, "MakeBuildChild: schedule %s%s\n", cn->name, cn->cohort_num); 885 886 cn->made = REQUESTED; 887 if (toBeMade_next == NULL) 888 Lst_Append(toBeMade, cn); 889 else 890 Lst_InsertBefore(toBeMade, toBeMade_next, cn); 891 892 if (cn->unmade_cohorts != 0) 893 Lst_ForEachUntil(cn->cohorts, MakeBuildChild, toBeMade_next); 894 895 /* 896 * If this node is a .WAIT node with unmade children 897 * then don't add the next sibling. 898 */ 899 return cn->type & OP_WAIT && cn->unmade > 0; 900 } 901 902 /* When a .ORDER LHS node completes we do this on each RHS */ 903 static int 904 MakeBuildParent(void *v_pn, void *toBeMade_next) 905 { 906 GNode *pn = v_pn; 907 908 if (pn->made != DEFERRED) 909 return 0; 910 911 if (MakeBuildChild(pn, toBeMade_next) == 0) { 912 /* Mark so that when this node is built we reschedule its parents */ 913 pn->flags |= DONE_ORDER; 914 } 915 916 return 0; 917 } 918 919 /* Start as many jobs as possible, taking them from the toBeMade queue. 920 * 921 * If the query flag was given to pmake, no job will be started, 922 * but as soon as an out-of-date target is found, this function 923 * returns TRUE. At all other times, this function returns FALSE. 924 */ 925 static Boolean 926 MakeStartJobs(void) 927 { 928 GNode *gn; 929 int have_token = 0; 930 931 while (!Lst_IsEmpty(toBeMade)) { 932 /* Get token now to avoid cycling job-list when we only have 1 token */ 933 if (!have_token && !Job_TokenWithdraw()) 934 break; 935 have_token = 1; 936 937 gn = Lst_Dequeue(toBeMade); 938 DEBUG2(MAKE, "Examining %s%s...\n", gn->name, gn->cohort_num); 939 940 if (gn->made != REQUESTED) { 941 DEBUG1(MAKE, "state %d\n", gn->made); 942 943 make_abort(gn, __LINE__); 944 } 945 946 if (gn->checked_seqno == checked) { 947 /* We've already looked at this node since a job finished... */ 948 DEBUG2(MAKE, "already checked %s%s\n", gn->name, gn->cohort_num); 949 gn->made = DEFERRED; 950 continue; 951 } 952 gn->checked_seqno = checked; 953 954 if (gn->unmade != 0) { 955 /* 956 * We can't build this yet, add all unmade children to toBeMade, 957 * just before the current first element. 958 */ 959 gn->made = DEFERRED; 960 Lst_ForEachUntil(gn->children, MakeBuildChild, toBeMade->first); 961 /* and drop this node on the floor */ 962 DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num); 963 continue; 964 } 965 966 gn->made = BEINGMADE; 967 if (Make_OODate(gn)) { 968 DEBUG0(MAKE, "out-of-date\n"); 969 if (opts.queryFlag) { 970 return TRUE; 971 } 972 Make_DoAllVar(gn); 973 Job_Make(gn); 974 have_token = 0; 975 } else { 976 DEBUG0(MAKE, "up-to-date\n"); 977 gn->made = UPTODATE; 978 if (gn->type & OP_JOIN) { 979 /* 980 * Even for an up-to-date .JOIN node, we need it to have its 981 * context variables so references to it get the correct 982 * value for .TARGET when building up the context variables 983 * of its parent(s)... 984 */ 985 Make_DoAllVar(gn); 986 } 987 Make_Update(gn); 988 } 989 } 990 991 if (have_token) 992 Job_TokenReturn(); 993 994 return FALSE; 995 } 996 997 static void 998 MakePrintStatusOrderNode(GNode *ogn, GNode *gn) 999 { 1000 if (!(ogn->flags & REMAKE) || ogn->made > REQUESTED) 1001 /* not waiting for this one */ 1002 return; 1003 1004 printf(" `%s%s' has .ORDER dependency against %s%s ", 1005 gn->name, gn->cohort_num, ogn->name, ogn->cohort_num); 1006 GNode_FprintDetails(stdout, "(", ogn, ")\n"); 1007 1008 if (DEBUG(MAKE) && opts.debug_file != stdout) { 1009 debug_printf(" `%s%s' has .ORDER dependency against %s%s ", 1010 gn->name, gn->cohort_num, ogn->name, ogn->cohort_num); 1011 GNode_FprintDetails(opts.debug_file, "(", ogn, ")\n"); 1012 } 1013 } 1014 1015 static void 1016 MakePrintStatusOrder(GNode *gn) 1017 { 1018 GNodeListNode *ln; 1019 for (ln = gn->order_pred->first; ln != NULL; ln = ln->next) 1020 MakePrintStatusOrderNode(ln->datum, gn); 1021 } 1022 1023 static void MakePrintStatusList(GNodeList *, int *); 1024 1025 /* Print the status of a top-level node, viz. it being up-to-date already 1026 * or not created due to an error in a lower level. 1027 * Callback function for Make_Run via Lst_ForEachUntil. 1028 */ 1029 static Boolean 1030 MakePrintStatus(GNode *gn, int *errors) 1031 { 1032 if (gn->flags & DONECYCLE) 1033 /* We've completely processed this node before, don't do it again. */ 1034 return FALSE; 1035 1036 if (gn->unmade == 0) { 1037 gn->flags |= DONECYCLE; 1038 switch (gn->made) { 1039 case UPTODATE: 1040 printf("`%s%s' is up to date.\n", gn->name, gn->cohort_num); 1041 break; 1042 case MADE: 1043 break; 1044 case UNMADE: 1045 case DEFERRED: 1046 case REQUESTED: 1047 case BEINGMADE: 1048 (*errors)++; 1049 printf("`%s%s' was not built", gn->name, gn->cohort_num); 1050 GNode_FprintDetails(stdout, " (", gn, ")!\n"); 1051 if (DEBUG(MAKE) && opts.debug_file != stdout) { 1052 debug_printf("`%s%s' was not built", gn->name, gn->cohort_num); 1053 GNode_FprintDetails(opts.debug_file, " (", gn, ")!\n"); 1054 } 1055 /* Most likely problem is actually caused by .ORDER */ 1056 MakePrintStatusOrder(gn); 1057 break; 1058 default: 1059 /* Errors - already counted */ 1060 printf("`%s%s' not remade because of errors.\n", 1061 gn->name, gn->cohort_num); 1062 if (DEBUG(MAKE) && opts.debug_file != stdout) 1063 debug_printf("`%s%s' not remade because of errors.\n", 1064 gn->name, gn->cohort_num); 1065 break; 1066 } 1067 return FALSE; 1068 } 1069 1070 DEBUG3(MAKE, "MakePrintStatus: %s%s has %d unmade children\n", 1071 gn->name, gn->cohort_num, gn->unmade); 1072 /* 1073 * If printing cycles and came to one that has unmade children, 1074 * print out the cycle by recursing on its children. 1075 */ 1076 if (!(gn->flags & CYCLE)) { 1077 /* Fist time we've seen this node, check all children */ 1078 gn->flags |= CYCLE; 1079 MakePrintStatusList(gn->children, errors); 1080 /* Mark that this node needn't be processed again */ 1081 gn->flags |= DONECYCLE; 1082 return FALSE; 1083 } 1084 1085 /* Only output the error once per node */ 1086 gn->flags |= DONECYCLE; 1087 Error("Graph cycles through `%s%s'", gn->name, gn->cohort_num); 1088 if ((*errors)++ > 100) 1089 /* Abandon the whole error report */ 1090 return TRUE; 1091 1092 /* Reporting for our children will give the rest of the loop */ 1093 MakePrintStatusList(gn->children, errors); 1094 return FALSE; 1095 } 1096 1097 static void 1098 MakePrintStatusList(GNodeList *gnodes, int *errors) 1099 { 1100 GNodeListNode *ln; 1101 for (ln = gnodes->first; ln != NULL; ln = ln->next) 1102 if (MakePrintStatus(ln->datum, errors)) 1103 break; 1104 } 1105 1106 /* Expand .USE nodes and create a new targets list. 1107 * 1108 * Input: 1109 * targs the initial list of targets 1110 */ 1111 void 1112 Make_ExpandUse(GNodeList *targs) 1113 { 1114 GNodeList *examine; /* List of targets to examine */ 1115 1116 { 1117 /* XXX: Why is it necessary to copy the list? There shouldn't be 1118 * any modifications to the list, at least the function name 1119 * ExpandUse doesn't suggest that. */ 1120 GNodeListNode *ln; 1121 examine = Lst_New(); 1122 for (ln = targs->first; ln != NULL; ln = ln->next) 1123 Lst_Append(examine, ln->datum); 1124 } 1125 1126 /* 1127 * Make an initial downward pass over the graph, marking nodes to be made 1128 * as we go down. We call Suff_FindDeps to find where a node is and 1129 * to get some children for it if it has none and also has no commands. 1130 * If the node is a leaf, we stick it on the toBeMade queue to 1131 * be looked at in a minute, otherwise we add its children to our queue 1132 * and go on about our business. 1133 */ 1134 while (!Lst_IsEmpty(examine)) { 1135 GNode *gn = Lst_Dequeue(examine); 1136 1137 if (gn->flags & REMAKE) 1138 /* We've looked at this one already */ 1139 continue; 1140 gn->flags |= REMAKE; 1141 DEBUG2(MAKE, "Make_ExpandUse: examine %s%s\n", 1142 gn->name, gn->cohort_num); 1143 1144 if (gn->type & OP_DOUBLEDEP) 1145 Lst_PrependAll(examine, gn->cohorts); 1146 1147 /* 1148 * Apply any .USE rules before looking for implicit dependencies 1149 * to make sure everything has commands that should... 1150 * Make sure that the TARGET is set, so that we can make 1151 * expansions. 1152 */ 1153 if (gn->type & OP_ARCHV) { 1154 char *eoa, *eon; 1155 eoa = strchr(gn->name, '('); 1156 eon = strchr(gn->name, ')'); 1157 if (eoa == NULL || eon == NULL) 1158 continue; 1159 *eoa = '\0'; 1160 *eon = '\0'; 1161 Var_Set(MEMBER, eoa + 1, gn); 1162 Var_Set(ARCHIVE, gn->name, gn); 1163 *eoa = '('; 1164 *eon = ')'; 1165 } 1166 1167 (void)Dir_MTime(gn, 0); 1168 Var_Set(TARGET, GNode_Path(gn), gn); 1169 UnmarkChildren(gn); 1170 HandleUseNodes(gn); 1171 1172 if ((gn->type & OP_MADE) == 0) 1173 Suff_FindDeps(gn); 1174 else { 1175 /* Pretend we made all this node's children */ 1176 Lst_ForEachUntil(gn->children, MakeFindChild, gn); 1177 if (gn->unmade != 0) 1178 printf("Warning: %s%s still has %d unmade children\n", 1179 gn->name, gn->cohort_num, gn->unmade); 1180 } 1181 1182 if (gn->unmade != 0) 1183 Lst_ForEachUntil(gn->children, MakeAddChild, examine); 1184 } 1185 1186 Lst_Free(examine); 1187 } 1188 1189 /* Make the .WAIT node depend on the previous children */ 1190 static void 1191 add_wait_dependency(GNodeListNode *owln, GNode *wn) 1192 { 1193 GNodeListNode *cln; 1194 GNode *cn; 1195 1196 for (cln = owln; (cn = cln->datum) != wn; cln = cln->next) { 1197 DEBUG3(MAKE, ".WAIT: add dependency %s%s -> %s\n", 1198 cn->name, cn->cohort_num, wn->name); 1199 1200 /* XXX: This pattern should be factored out, it repeats often */ 1201 Lst_Append(wn->children, cn); 1202 wn->unmade++; 1203 Lst_Append(cn->parents, wn); 1204 } 1205 } 1206 1207 /* Convert .WAIT nodes into dependencies. */ 1208 static void 1209 Make_ProcessWait(GNodeList *targs) 1210 { 1211 GNode *pgn; /* 'parent' node we are examining */ 1212 GNodeListNode *owln; /* Previous .WAIT node */ 1213 GNodeList *examine; /* List of targets to examine */ 1214 1215 /* 1216 * We need all the nodes to have a common parent in order for the 1217 * .WAIT and .ORDER scheduling to work. 1218 * Perhaps this should be done earlier... 1219 */ 1220 1221 pgn = Targ_NewGN(".MAIN"); 1222 pgn->flags = REMAKE; 1223 pgn->type = OP_PHONY | OP_DEPENDS; 1224 /* Get it displayed in the diag dumps */ 1225 Lst_Prepend(Targ_List(), pgn); 1226 1227 { 1228 GNodeListNode *ln; 1229 for (ln = targs->first; ln != NULL; ln = ln->next) { 1230 GNode *cgn = ln->datum; 1231 1232 Lst_Append(pgn->children, cgn); 1233 Lst_Append(cgn->parents, pgn); 1234 pgn->unmade++; 1235 } 1236 } 1237 1238 /* Start building with the 'dummy' .MAIN' node */ 1239 MakeBuildChild(pgn, NULL); 1240 1241 examine = Lst_New(); 1242 Lst_Append(examine, pgn); 1243 1244 while (!Lst_IsEmpty(examine)) { 1245 GNodeListNode *ln; 1246 1247 pgn = Lst_Dequeue(examine); 1248 1249 /* We only want to process each child-list once */ 1250 if (pgn->flags & DONE_WAIT) 1251 continue; 1252 pgn->flags |= DONE_WAIT; 1253 DEBUG1(MAKE, "Make_ProcessWait: examine %s\n", pgn->name); 1254 1255 if (pgn->type & OP_DOUBLEDEP) 1256 Lst_PrependAll(examine, pgn->cohorts); 1257 1258 owln = pgn->children->first; 1259 for (ln = pgn->children->first; ln != NULL; ln = ln->next) { 1260 GNode *cgn = ln->datum; 1261 if (cgn->type & OP_WAIT) { 1262 add_wait_dependency(owln, cgn); 1263 owln = ln; 1264 } else { 1265 Lst_Append(examine, cgn); 1266 } 1267 } 1268 } 1269 1270 Lst_Free(examine); 1271 } 1272 1273 /*- 1274 *----------------------------------------------------------------------- 1275 * Make_Run -- 1276 * Initialize the nodes to remake and the list of nodes which are 1277 * ready to be made by doing a breadth-first traversal of the graph 1278 * starting from the nodes in the given list. Once this traversal 1279 * is finished, all the 'leaves' of the graph are in the toBeMade 1280 * queue. 1281 * Using this queue and the Job module, work back up the graph, 1282 * calling on MakeStartJobs to keep the job table as full as 1283 * possible. 1284 * 1285 * Input: 1286 * targs the initial list of targets 1287 * 1288 * Results: 1289 * TRUE if work was done. FALSE otherwise. 1290 * 1291 * Side Effects: 1292 * The make field of all nodes involved in the creation of the given 1293 * targets is set to 1. The toBeMade list is set to contain all the 1294 * 'leaves' of these subgraphs. 1295 *----------------------------------------------------------------------- 1296 */ 1297 Boolean 1298 Make_Run(GNodeList *targs) 1299 { 1300 int errors; /* Number of errors the Job module reports */ 1301 1302 /* Start trying to make the current targets... */ 1303 toBeMade = Lst_New(); 1304 1305 Make_ExpandUse(targs); 1306 Make_ProcessWait(targs); 1307 1308 if (DEBUG(MAKE)) { 1309 debug_printf("#***# full graph\n"); 1310 Targ_PrintGraph(1); 1311 } 1312 1313 if (opts.queryFlag) { 1314 /* 1315 * We wouldn't do any work unless we could start some jobs in the 1316 * next loop... (we won't actually start any, of course, this is just 1317 * to see if any of the targets was out of date) 1318 */ 1319 return MakeStartJobs(); 1320 } 1321 /* 1322 * Initialization. At the moment, no jobs are running and until some 1323 * get started, nothing will happen since the remaining upward 1324 * traversal of the graph is performed by the routines in job.c upon 1325 * the finishing of a job. So we fill the Job table as much as we can 1326 * before going into our loop. 1327 */ 1328 (void)MakeStartJobs(); 1329 1330 /* 1331 * Main Loop: The idea here is that the ending of jobs will take 1332 * care of the maintenance of data structures and the waiting for output 1333 * will cause us to be idle most of the time while our children run as 1334 * much as possible. Because the job table is kept as full as possible, 1335 * the only time when it will be empty is when all the jobs which need 1336 * running have been run, so that is the end condition of this loop. 1337 * Note that the Job module will exit if there were any errors unless the 1338 * keepgoing flag was given. 1339 */ 1340 while (!Lst_IsEmpty(toBeMade) || jobTokensRunning > 0) { 1341 Job_CatchOutput(); 1342 (void)MakeStartJobs(); 1343 } 1344 1345 errors = Job_Finish(); 1346 1347 /* 1348 * Print the final status of each target. E.g. if it wasn't made 1349 * because some inferior reported an error. 1350 */ 1351 DEBUG1(MAKE, "done: errors %d\n", errors); 1352 if (errors == 0) { 1353 MakePrintStatusList(targs, &errors); 1354 if (DEBUG(MAKE)) { 1355 debug_printf("done: errors %d\n", errors); 1356 if (errors) 1357 Targ_PrintGraph(4); 1358 } 1359 } 1360 return errors != 0; 1361 } 1362