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