1 /* $NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $ */ 2 3 /* 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 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. 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) 1988, 1989 by Adam de Boor 37 * Copyright (c) 1989 by Berkeley Softworks 38 * All rights reserved. 39 * 40 * This code is derived from software contributed to Berkeley by 41 * Adam de Boor. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. All advertising materials mentioning features or use of this software 52 * must display the following acknowledgement: 53 * This product includes software developed by the University of 54 * California, Berkeley and its contributors. 55 * 4. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 */ 71 72 #ifndef MAKE_NATIVE 73 static char rcsid[] = "$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $"; 74 #else 75 #include <sys/cdefs.h> 76 #ifndef lint 77 #if 0 78 static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94"; 79 #else 80 __RCSID("$NetBSD: compat.c,v 1.107 2017/07/20 19:29:54 sjg Exp $"); 81 #endif 82 #endif /* not lint */ 83 #endif 84 85 /*- 86 * compat.c -- 87 * The routines in this file implement the full-compatibility 88 * mode of PMake. Most of the special functionality of PMake 89 * is available in this mode. Things not supported: 90 * - different shells. 91 * - friendly variable substitution. 92 * 93 * Interface: 94 * Compat_Run Initialize things for this module and recreate 95 * thems as need creatin' 96 */ 97 98 #include <sys/types.h> 99 #include <sys/stat.h> 100 #include <sys/wait.h> 101 102 #include <ctype.h> 103 #include <errno.h> 104 #include <signal.h> 105 #include <stdio.h> 106 107 #include "make.h" 108 #include "hash.h" 109 #include "dir.h" 110 #include "job.h" 111 #include "metachar.h" 112 #include "pathnames.h" 113 114 115 static GNode *curTarg = NULL; 116 static GNode *ENDNode; 117 static void CompatInterrupt(int); 118 static pid_t compatChild; 119 static int compatSigno; 120 121 /* 122 * CompatDeleteTarget -- delete a failed, interrupted, or otherwise 123 * duffed target if not inhibited by .PRECIOUS. 124 */ 125 static void 126 CompatDeleteTarget(GNode *gn) 127 { 128 if ((gn != NULL) && !Targ_Precious (gn)) { 129 char *p1; 130 char *file = Var_Value(TARGET, gn, &p1); 131 132 if (!noExecute && eunlink(file) != -1) { 133 Error("*** %s removed", file); 134 } 135 136 free(p1); 137 } 138 } 139 140 /*- 141 *----------------------------------------------------------------------- 142 * CompatInterrupt -- 143 * Interrupt the creation of the current target and remove it if 144 * it ain't precious. 145 * 146 * Results: 147 * None. 148 * 149 * Side Effects: 150 * The target is removed and the process exits. If .INTERRUPT exists, 151 * its commands are run first WITH INTERRUPTS IGNORED.. 152 * 153 * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've 154 * left the logic alone for now. - dholland 20160826 155 * 156 *----------------------------------------------------------------------- 157 */ 158 static void 159 CompatInterrupt(int signo) 160 { 161 GNode *gn; 162 163 CompatDeleteTarget(curTarg); 164 165 if ((curTarg != NULL) && !Targ_Precious (curTarg)) { 166 /* 167 * Run .INTERRUPT only if hit with interrupt signal 168 */ 169 if (signo == SIGINT) { 170 gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE); 171 if (gn != NULL) { 172 Compat_Make(gn, gn); 173 } 174 } 175 } 176 if (signo == SIGQUIT) 177 _exit(signo); 178 /* 179 * If there is a child running, pass the signal on 180 * we will exist after it has exited. 181 */ 182 compatSigno = signo; 183 if (compatChild > 0) { 184 KILLPG(compatChild, signo); 185 } else { 186 bmake_signal(signo, SIG_DFL); 187 kill(myPid, signo); 188 } 189 } 190 191 /*- 192 *----------------------------------------------------------------------- 193 * CompatRunCommand -- 194 * Execute the next command for a target. If the command returns an 195 * error, the node's made field is set to ERROR and creation stops. 196 * 197 * Input: 198 * cmdp Command to execute 199 * gnp Node from which the command came 200 * 201 * Results: 202 * 0 if the command succeeded, 1 if an error occurred. 203 * 204 * Side Effects: 205 * The node's 'made' field may be set to ERROR. 206 * 207 *----------------------------------------------------------------------- 208 */ 209 int 210 CompatRunCommand(void *cmdp, void *gnp) 211 { 212 char *cmdStart; /* Start of expanded command */ 213 char *cp, *bp; 214 Boolean silent, /* Don't print command */ 215 doIt; /* Execute even if -n */ 216 volatile Boolean errCheck; /* Check errors */ 217 int reason; /* Reason for child's death */ 218 int status; /* Description of child's death */ 219 pid_t cpid; /* Child actually found */ 220 pid_t retstat; /* Result of wait */ 221 LstNode cmdNode; /* Node where current command is located */ 222 const char ** volatile av; /* Argument vector for thing to exec */ 223 char ** volatile mav;/* Copy of the argument vector for freeing */ 224 int argc; /* Number of arguments in av or 0 if not 225 * dynamically allocated */ 226 Boolean local; /* TRUE if command should be executed 227 * locally */ 228 Boolean useShell; /* TRUE if command should be executed 229 * using a shell */ 230 char * volatile cmd = (char *)cmdp; 231 GNode *gn = (GNode *)gnp; 232 233 silent = gn->type & OP_SILENT; 234 errCheck = !(gn->type & OP_IGNORE); 235 doIt = FALSE; 236 237 cmdNode = Lst_Member(gn->commands, cmd); 238 cmdStart = Var_Subst(NULL, cmd, gn, VARF_WANTRES); 239 240 /* 241 * brk_string will return an argv with a NULL in av[0], thus causing 242 * execvp to choke and die horribly. Besides, how can we execute a null 243 * command? In any case, we warn the user that the command expanded to 244 * nothing (is this the right thing to do?). 245 */ 246 247 if (*cmdStart == '\0') { 248 free(cmdStart); 249 return(0); 250 } 251 cmd = cmdStart; 252 Lst_Replace(cmdNode, cmdStart); 253 254 if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { 255 (void)Lst_AtEnd(ENDNode->commands, cmdStart); 256 return(0); 257 } 258 if (strcmp(cmdStart, "...") == 0) { 259 gn->type |= OP_SAVE_CMDS; 260 return(0); 261 } 262 263 while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) { 264 switch (*cmd) { 265 case '@': 266 silent = DEBUG(LOUD) ? FALSE : TRUE; 267 break; 268 case '-': 269 errCheck = FALSE; 270 break; 271 case '+': 272 doIt = TRUE; 273 if (!shellName) /* we came here from jobs */ 274 Shell_Init(); 275 break; 276 } 277 cmd++; 278 } 279 280 while (isspace((unsigned char)*cmd)) 281 cmd++; 282 283 /* 284 * If we did not end up with a command, just skip it. 285 */ 286 if (!*cmd) 287 return (0); 288 289 #if !defined(MAKE_NATIVE) 290 /* 291 * In a non-native build, the host environment might be weird enough 292 * that it's necessary to go through a shell to get the correct 293 * behaviour. Or perhaps the shell has been replaced with something 294 * that does extra logging, and that should not be bypassed. 295 */ 296 useShell = TRUE; 297 #else 298 /* 299 * Search for meta characters in the command. If there are no meta 300 * characters, there's no need to execute a shell to execute the 301 * command. 302 * 303 * Additionally variable assignments and empty commands 304 * go to the shell. Therefore treat '=' and ':' like shell 305 * meta characters as documented in make(1). 306 */ 307 308 useShell = needshell(cmd, FALSE); 309 #endif 310 311 /* 312 * Print the command before echoing if we're not supposed to be quiet for 313 * this one. We also print the command if -n given. 314 */ 315 if (!silent || NoExecute(gn)) { 316 printf("%s\n", cmd); 317 fflush(stdout); 318 } 319 320 /* 321 * If we're not supposed to execute any commands, this is as far as 322 * we go... 323 */ 324 if (!doIt && NoExecute(gn)) { 325 return (0); 326 } 327 if (DEBUG(JOB)) 328 fprintf(debug_file, "Execute: '%s'\n", cmd); 329 330 again: 331 if (useShell) { 332 /* 333 * We need to pass the command off to the shell, typically 334 * because the command contains a "meta" character. 335 */ 336 static const char *shargv[5]; 337 int shargc; 338 339 shargc = 0; 340 shargv[shargc++] = shellPath; 341 /* 342 * The following work for any of the builtin shell specs. 343 */ 344 if (errCheck && shellErrFlag) { 345 shargv[shargc++] = shellErrFlag; 346 } 347 if (DEBUG(SHELL)) 348 shargv[shargc++] = "-xc"; 349 else 350 shargv[shargc++] = "-c"; 351 shargv[shargc++] = cmd; 352 shargv[shargc++] = NULL; 353 av = shargv; 354 argc = 0; 355 bp = NULL; 356 mav = NULL; 357 } else { 358 /* 359 * No meta-characters, so no need to exec a shell. Break the command 360 * into words to form an argument vector we can execute. 361 */ 362 mav = brk_string(cmd, &argc, TRUE, &bp); 363 if (mav == NULL) { 364 useShell = 1; 365 goto again; 366 } 367 av = (void *)mav; 368 } 369 370 local = TRUE; 371 372 #ifdef USE_META 373 if (useMeta) { 374 meta_compat_start(); 375 } 376 #endif 377 378 /* 379 * Fork and execute the single command. If the fork fails, we abort. 380 */ 381 compatChild = cpid = vFork(); 382 if (cpid < 0) { 383 Fatal("Could not fork"); 384 } 385 if (cpid == 0) { 386 Var_ExportVars(); 387 #ifdef USE_META 388 if (useMeta) { 389 meta_compat_child(); 390 } 391 #endif 392 if (local) 393 (void)execvp(av[0], (char *const *)UNCONST(av)); 394 else 395 (void)execv(av[0], (char *const *)UNCONST(av)); 396 execError("exec", av[0]); 397 _exit(1); 398 } 399 400 free(mav); 401 free(bp); 402 403 Lst_Replace(cmdNode, NULL); 404 405 #ifdef USE_META 406 if (useMeta) { 407 meta_compat_parent(); 408 } 409 #endif 410 411 /* 412 * The child is off and running. Now all we can do is wait... 413 */ 414 while (1) { 415 416 while ((retstat = wait(&reason)) != cpid) { 417 if (retstat > 0) 418 JobReapChild(retstat, reason, FALSE); /* not ours? */ 419 if (retstat == -1 && errno != EINTR) { 420 break; 421 } 422 } 423 424 if (retstat > -1) { 425 if (WIFSTOPPED(reason)) { 426 status = WSTOPSIG(reason); /* stopped */ 427 } else if (WIFEXITED(reason)) { 428 status = WEXITSTATUS(reason); /* exited */ 429 #if defined(USE_META) && defined(USE_FILEMON_ONCE) 430 if (useMeta) { 431 meta_cmd_finish(NULL); 432 } 433 #endif 434 if (status != 0) { 435 if (DEBUG(ERROR)) { 436 fprintf(debug_file, "\n*** Failed target: %s\n*** Failed command: ", 437 gn->name); 438 for (cp = cmd; *cp; ) { 439 if (isspace((unsigned char)*cp)) { 440 fprintf(debug_file, " "); 441 while (isspace((unsigned char)*cp)) 442 cp++; 443 } else { 444 fprintf(debug_file, "%c", *cp); 445 cp++; 446 } 447 } 448 fprintf(debug_file, "\n"); 449 } 450 printf("*** Error code %d", status); 451 } 452 } else { 453 status = WTERMSIG(reason); /* signaled */ 454 printf("*** Signal %d", status); 455 } 456 457 458 if (!WIFEXITED(reason) || (status != 0)) { 459 if (errCheck) { 460 #ifdef USE_META 461 if (useMeta) { 462 meta_job_error(NULL, gn, 0, status); 463 } 464 #endif 465 gn->made = ERROR; 466 if (keepgoing) { 467 /* 468 * Abort the current target, but let others 469 * continue. 470 */ 471 printf(" (continuing)\n"); 472 } else { 473 printf("\n"); 474 } 475 if (deleteOnError) { 476 CompatDeleteTarget(gn); 477 } 478 } else { 479 /* 480 * Continue executing commands for this target. 481 * If we return 0, this will happen... 482 */ 483 printf(" (ignored)\n"); 484 status = 0; 485 } 486 } 487 break; 488 } else { 489 Fatal("error in wait: %d: %s", retstat, strerror(errno)); 490 /*NOTREACHED*/ 491 } 492 } 493 free(cmdStart); 494 compatChild = 0; 495 if (compatSigno) { 496 bmake_signal(compatSigno, SIG_DFL); 497 kill(myPid, compatSigno); 498 } 499 500 return (status); 501 } 502 503 /*- 504 *----------------------------------------------------------------------- 505 * Compat_Make -- 506 * Make a target. 507 * 508 * Input: 509 * gnp The node to make 510 * pgnp Parent to abort if necessary 511 * 512 * Results: 513 * 0 514 * 515 * Side Effects: 516 * If an error is detected and not being ignored, the process exits. 517 * 518 *----------------------------------------------------------------------- 519 */ 520 int 521 Compat_Make(void *gnp, void *pgnp) 522 { 523 GNode *gn = (GNode *)gnp; 524 GNode *pgn = (GNode *)pgnp; 525 526 if (!shellName) /* we came here from jobs */ 527 Shell_Init(); 528 if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) { 529 /* 530 * First mark ourselves to be made, then apply whatever transformations 531 * the suffix module thinks are necessary. Once that's done, we can 532 * descend and make all our children. If any of them has an error 533 * but the -k flag was given, our 'make' field will be set FALSE again. 534 * This is our signal to not attempt to do anything but abort our 535 * parent as well. 536 */ 537 gn->flags |= REMAKE; 538 gn->made = BEINGMADE; 539 if ((gn->type & OP_MADE) == 0) 540 Suff_FindDeps(gn); 541 Lst_ForEach(gn->children, Compat_Make, gn); 542 if ((gn->flags & REMAKE) == 0) { 543 gn->made = ABORTED; 544 pgn->flags &= ~REMAKE; 545 goto cohorts; 546 } 547 548 if (Lst_Member(gn->iParents, pgn) != NULL) { 549 char *p1; 550 Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); 551 free(p1); 552 } 553 554 /* 555 * All the children were made ok. Now cmgn->mtime contains the 556 * modification time of the newest child, we need to find out if we 557 * exist and when we were modified last. The criteria for datedness 558 * are defined by the Make_OODate function. 559 */ 560 if (DEBUG(MAKE)) { 561 fprintf(debug_file, "Examining %s...", gn->name); 562 } 563 if (! Make_OODate(gn)) { 564 gn->made = UPTODATE; 565 if (DEBUG(MAKE)) { 566 fprintf(debug_file, "up-to-date.\n"); 567 } 568 goto cohorts; 569 } else if (DEBUG(MAKE)) { 570 fprintf(debug_file, "out-of-date.\n"); 571 } 572 573 /* 574 * If the user is just seeing if something is out-of-date, exit now 575 * to tell him/her "yes". 576 */ 577 if (queryFlag) { 578 exit(1); 579 } 580 581 /* 582 * We need to be re-made. We also have to make sure we've got a $? 583 * variable. To be nice, we also define the $> variable using 584 * Make_DoAllVar(). 585 */ 586 Make_DoAllVar(gn); 587 588 /* 589 * Alter our type to tell if errors should be ignored or things 590 * should not be printed so CompatRunCommand knows what to do. 591 */ 592 if (Targ_Ignore(gn)) { 593 gn->type |= OP_IGNORE; 594 } 595 if (Targ_Silent(gn)) { 596 gn->type |= OP_SILENT; 597 } 598 599 if (Job_CheckCommands(gn, Fatal)) { 600 /* 601 * Our commands are ok, but we still have to worry about the -t 602 * flag... 603 */ 604 if (!touchFlag || (gn->type & OP_MAKE)) { 605 curTarg = gn; 606 #ifdef USE_META 607 if (useMeta && !NoExecute(gn)) { 608 meta_job_start(NULL, gn); 609 } 610 #endif 611 Lst_ForEach(gn->commands, CompatRunCommand, gn); 612 curTarg = NULL; 613 } else { 614 Job_Touch(gn, gn->type & OP_SILENT); 615 } 616 } else { 617 gn->made = ERROR; 618 } 619 #ifdef USE_META 620 if (useMeta && !NoExecute(gn)) { 621 if (meta_job_finish(NULL) != 0) 622 gn->made = ERROR; 623 } 624 #endif 625 626 if (gn->made != ERROR) { 627 /* 628 * If the node was made successfully, mark it so, update 629 * its modification time and timestamp all its parents. Note 630 * that for .ZEROTIME targets, the timestamping isn't done. 631 * This is to keep its state from affecting that of its parent. 632 */ 633 gn->made = MADE; 634 pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0; 635 if (!(gn->type & OP_EXEC)) { 636 pgn->flags |= CHILDMADE; 637 Make_TimeStamp(pgn, gn); 638 } 639 } else if (keepgoing) { 640 pgn->flags &= ~REMAKE; 641 } else { 642 PrintOnError(gn, "\nStop."); 643 exit(1); 644 } 645 } else if (gn->made == ERROR) { 646 /* 647 * Already had an error when making this beastie. Tell the parent 648 * to abort. 649 */ 650 pgn->flags &= ~REMAKE; 651 } else { 652 if (Lst_Member(gn->iParents, pgn) != NULL) { 653 char *p1; 654 Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0); 655 free(p1); 656 } 657 switch(gn->made) { 658 case BEINGMADE: 659 Error("Graph cycles through %s", gn->name); 660 gn->made = ERROR; 661 pgn->flags &= ~REMAKE; 662 break; 663 case MADE: 664 if ((gn->type & OP_EXEC) == 0) { 665 pgn->flags |= CHILDMADE; 666 Make_TimeStamp(pgn, gn); 667 } 668 break; 669 case UPTODATE: 670 if ((gn->type & OP_EXEC) == 0) { 671 Make_TimeStamp(pgn, gn); 672 } 673 break; 674 default: 675 break; 676 } 677 } 678 679 cohorts: 680 Lst_ForEach(gn->cohorts, Compat_Make, pgnp); 681 return (0); 682 } 683 684 /*- 685 *----------------------------------------------------------------------- 686 * Compat_Run -- 687 * Initialize this mode and start making. 688 * 689 * Input: 690 * targs List of target nodes to re-create 691 * 692 * Results: 693 * None. 694 * 695 * Side Effects: 696 * Guess what? 697 * 698 *----------------------------------------------------------------------- 699 */ 700 void 701 Compat_Run(Lst targs) 702 { 703 GNode *gn = NULL;/* Current root target */ 704 int errors; /* Number of targets not remade due to errors */ 705 706 if (!shellName) 707 Shell_Init(); 708 709 if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) { 710 bmake_signal(SIGINT, CompatInterrupt); 711 } 712 if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) { 713 bmake_signal(SIGTERM, CompatInterrupt); 714 } 715 if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) { 716 bmake_signal(SIGHUP, CompatInterrupt); 717 } 718 if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) { 719 bmake_signal(SIGQUIT, CompatInterrupt); 720 } 721 722 ENDNode = Targ_FindNode(".END", TARG_CREATE); 723 ENDNode->type = OP_SPECIAL; 724 /* 725 * If the user has defined a .BEGIN target, execute the commands attached 726 * to it. 727 */ 728 if (!queryFlag) { 729 gn = Targ_FindNode(".BEGIN", TARG_NOCREATE); 730 if (gn != NULL) { 731 Compat_Make(gn, gn); 732 if (gn->made == ERROR) { 733 PrintOnError(gn, "\nStop."); 734 exit(1); 735 } 736 } 737 } 738 739 /* 740 * Expand .USE nodes right now, because they can modify the structure 741 * of the tree. 742 */ 743 Make_ExpandUse(targs); 744 745 /* 746 * For each entry in the list of targets to create, call Compat_Make on 747 * it to create the thing. Compat_Make will leave the 'made' field of gn 748 * in one of several states: 749 * UPTODATE gn was already up-to-date 750 * MADE gn was recreated successfully 751 * ERROR An error occurred while gn was being created 752 * ABORTED gn was not remade because one of its inferiors 753 * could not be made due to errors. 754 */ 755 errors = 0; 756 while (!Lst_IsEmpty (targs)) { 757 gn = (GNode *)Lst_DeQueue(targs); 758 Compat_Make(gn, gn); 759 760 if (gn->made == UPTODATE) { 761 printf("`%s' is up to date.\n", gn->name); 762 } else if (gn->made == ABORTED) { 763 printf("`%s' not remade because of errors.\n", gn->name); 764 errors += 1; 765 } 766 } 767 768 /* 769 * If the user has defined a .END target, run its commands. 770 */ 771 if (errors == 0) { 772 Compat_Make(ENDNode, ENDNode); 773 if (gn->made == ERROR) { 774 PrintOnError(gn, "\nStop."); 775 exit(1); 776 } 777 } 778 } 779