compat.c revision 1.244 1 /* $NetBSD: compat.c,v 1.244 2023/01/17 21:35:19 christos 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 /*
73 * This file implements the full-compatibility mode of make, which makes the
74 * targets without parallelism and without a custom shell.
75 *
76 * Interface:
77 * Compat_MakeAll Initialize this module and make the given targets.
78 */
79
80 #include <sys/types.h>
81 #include <sys/stat.h>
82 #include <sys/wait.h>
83
84 #include <errno.h>
85 #include <signal.h>
86
87 #include "make.h"
88 #include "dir.h"
89 #include "job.h"
90 #include "metachar.h"
91 #include "pathnames.h"
92
93 /* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */
94 MAKE_RCSID("$NetBSD: compat.c,v 1.244 2023/01/17 21:35:19 christos Exp $");
95
96 static GNode *curTarg = NULL;
97 static pid_t compatChild;
98 static int compatSigno;
99
100 /*
101 * Delete the file of a failed, interrupted, or otherwise duffed target,
102 * unless inhibited by .PRECIOUS.
103 */
104 static void
105 CompatDeleteTarget(GNode *gn)
106 {
107 if (gn != NULL && !GNode_IsPrecious(gn)) {
108 const char *file = GNode_VarTarget(gn);
109
110 if (!opts.noExecute && unlink_file(file) == 0) {
111 Error("*** %s removed", file);
112 }
113 }
114 }
115
116 /*
117 * Interrupt the creation of the current target and remove it if it ain't
118 * precious. Then exit.
119 *
120 * If .INTERRUPT exists, its commands are run first WITH INTERRUPTS IGNORED.
121 *
122 * XXX: is .PRECIOUS supposed to inhibit .INTERRUPT? I doubt it, but I've
123 * left the logic alone for now. - dholland 20160826
124 */
125 static void
126 CompatInterrupt(int signo)
127 {
128 CompatDeleteTarget(curTarg);
129
130 if (curTarg != NULL && !GNode_IsPrecious(curTarg)) {
131 /*
132 * Run .INTERRUPT only if hit with interrupt signal
133 */
134 if (signo == SIGINT) {
135 GNode *gn = Targ_FindNode(".INTERRUPT");
136 if (gn != NULL) {
137 Compat_Make(gn, gn);
138 }
139 }
140 }
141
142 if (signo == SIGQUIT)
143 _exit(signo);
144
145 /*
146 * If there is a child running, pass the signal on.
147 * We will exist after it has exited.
148 */
149 compatSigno = signo;
150 if (compatChild > 0) {
151 KILLPG(compatChild, signo);
152 } else {
153 bmake_signal(signo, SIG_DFL);
154 kill(myPid, signo);
155 }
156 }
157
158 static void
159 DebugFailedTarget(const char *cmd, const GNode *gn)
160 {
161 const char *p = cmd;
162 debug_printf("\n*** Failed target: %s\n*** Failed command: ",
163 gn->name);
164
165 /*
166 * Replace runs of whitespace with a single space, to reduce the
167 * amount of whitespace for multi-line command lines.
168 */
169 while (*p != '\0') {
170 if (ch_isspace(*p)) {
171 debug_printf(" ");
172 cpp_skip_whitespace(&p);
173 } else {
174 debug_printf("%c", *p);
175 p++;
176 }
177 }
178 debug_printf("\n");
179 }
180
181 static bool
182 UseShell(const char *cmd MAKE_ATTR_UNUSED)
183 {
184 #if !defined(MAKE_NATIVE)
185 /*
186 * In a non-native build, the host environment might be weird enough
187 * that it's necessary to go through a shell to get the correct
188 * behaviour. Or perhaps the shell has been replaced with something
189 * that does extra logging, and that should not be bypassed.
190 */
191 return true;
192 #else
193 /*
194 * Search for meta characters in the command. If there are no meta
195 * characters, there's no need to execute a shell to execute the
196 * command.
197 *
198 * Additionally variable assignments and empty commands
199 * go to the shell. Therefore treat '=' and ':' like shell
200 * meta characters as documented in make(1).
201 */
202
203 return needshell(cmd);
204 #endif
205 }
206
207 /*
208 * Execute the next command for a target. If the command returns an error,
209 * the node's made field is set to ERROR and creation stops.
210 *
211 * Input:
212 * cmdp Command to execute
213 * gn Node from which the command came
214 * ln List node that contains the command
215 *
216 * Results:
217 * true if the command succeeded.
218 */
219 bool
220 Compat_RunCommand(const char *cmdp, GNode *gn, StringListNode *ln)
221 {
222 char *cmdStart; /* Start of expanded command */
223 char *bp;
224 bool silent; /* Don't print command */
225 bool doIt; /* Execute even if -n */
226 volatile bool errCheck; /* Check errors */
227 int reason; /* Reason for child's death */
228 int status; /* Description of child's death */
229 pid_t cpid; /* Child actually found */
230 pid_t retstat; /* Result of wait */
231 const char **volatile av; /* Argument vector for thing to exec */
232 char **volatile mav; /* Copy of the argument vector for freeing */
233 bool useShell; /* True if command should be executed using a
234 * shell */
235 const char *volatile cmd = cmdp;
236
237 silent = (gn->type & OP_SILENT) != OP_NONE;
238 errCheck = !(gn->type & OP_IGNORE);
239 doIt = false;
240
241 (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart);
242 /* TODO: handle errors */
243
244 if (cmdStart[0] == '\0') {
245 free(cmdStart);
246 return true;
247 }
248 cmd = cmdStart;
249 LstNode_Set(ln, cmdStart);
250
251 if (gn->type & OP_SAVE_CMDS) {
252 GNode *endNode = Targ_GetEndNode();
253 if (gn != endNode) {
254 /*
255 * Append the expanded command, to prevent the
256 * local variables from being interpreted in the
257 * scope of the .END node.
258 *
259 * A probably unintended side effect of this is that
260 * the expanded command will be expanded again in the
261 * .END node. Therefore, a literal '$' in these
262 * commands must be written as '$$$$' instead of the
263 * usual '$$'.
264 */
265 Lst_Append(&endNode->commands, cmdStart);
266 return true;
267 }
268 }
269 if (strcmp(cmdStart, "...") == 0) {
270 gn->type |= OP_SAVE_CMDS;
271 return true;
272 }
273
274 for (;;) {
275 if (*cmd == '@')
276 silent = !DEBUG(LOUD);
277 else if (*cmd == '-')
278 errCheck = false;
279 else if (*cmd == '+') {
280 doIt = true;
281 if (shellName == NULL) /* we came here from jobs */
282 Shell_Init();
283 } else if (!ch_isspace(*cmd))
284 /* Ignore whitespace for compatibility with gnu make */
285 break;
286 cmd++;
287 }
288
289 while (ch_isspace(*cmd))
290 cmd++;
291
292 /*
293 * If we did not end up with a command, just skip it.
294 */
295 if (cmd[0] == '\0')
296 return true;
297
298 useShell = UseShell(cmd);
299 /*
300 * Print the command before echoing if we're not supposed to be quiet
301 * for this one. We also print the command if -n given.
302 */
303 if (!silent || !GNode_ShouldExecute(gn)) {
304 printf("%s\n", cmd);
305 fflush(stdout);
306 }
307
308 /*
309 * If we're not supposed to execute any commands, this is as far as
310 * we go...
311 */
312 if (!doIt && !GNode_ShouldExecute(gn))
313 return true;
314
315 DEBUG1(JOB, "Execute: '%s'\n", cmd);
316
317 if (useShell) {
318 /*
319 * We need to pass the command off to the shell, typically
320 * because the command contains a "meta" character.
321 */
322 static const char *shargv[5];
323
324 /* The following work for any of the builtin shell specs. */
325 int shargc = 0;
326 shargv[shargc++] = shellPath;
327 if (errCheck && shellErrFlag != NULL)
328 shargv[shargc++] = shellErrFlag;
329 shargv[shargc++] = DEBUG(SHELL) ? "-xc" : "-c";
330 shargv[shargc++] = cmd;
331 shargv[shargc] = NULL;
332 av = shargv;
333 bp = NULL;
334 mav = NULL;
335 } else {
336 /*
337 * No meta-characters, so no need to exec a shell. Break the
338 * command into words to form an argument vector we can
339 * execute.
340 */
341 Words words = Str_Words(cmd, false);
342 mav = words.words;
343 bp = words.freeIt;
344 av = (void *)mav;
345 }
346
347 #ifdef USE_META
348 if (useMeta)
349 meta_compat_start();
350 #endif
351
352 Var_ReexportVars();
353
354 compatChild = cpid = vfork();
355 if (cpid < 0)
356 Fatal("Could not fork");
357
358 if (cpid == 0) {
359 #ifdef USE_META
360 if (useMeta)
361 meta_compat_child();
362 #endif
363 (void)execvp(av[0], (char *const *)UNCONST(av));
364 execDie("exec", av[0]);
365 }
366
367 free(mav);
368 free(bp);
369
370 /* XXX: Memory management looks suspicious here. */
371 /* XXX: Setting a list item to NULL is unexpected. */
372 LstNode_SetNull(ln);
373
374 #ifdef USE_META
375 if (useMeta)
376 meta_compat_parent(cpid);
377 #endif
378
379 /*
380 * The child is off and running. Now all we can do is wait...
381 */
382 while ((retstat = wait(&reason)) != cpid) {
383 if (retstat > 0)
384 JobReapChild(retstat, reason, false); /* not ours? */
385 if (retstat == -1 && errno != EINTR) {
386 break;
387 }
388 }
389
390 if (retstat < 0)
391 Fatal("error in wait: %d: %s", retstat, strerror(errno));
392
393 if (WIFSTOPPED(reason)) {
394 status = WSTOPSIG(reason); /* stopped */
395 } else if (WIFEXITED(reason)) {
396 status = WEXITSTATUS(reason); /* exited */
397 #if defined(USE_META) && defined(USE_FILEMON_ONCE)
398 if (useMeta)
399 meta_cmd_finish(NULL);
400 #endif
401 if (status != 0) {
402 if (DEBUG(ERROR))
403 DebugFailedTarget(cmd, gn);
404 printf("*** Error code %d", status);
405 }
406 } else {
407 status = WTERMSIG(reason); /* signaled */
408 printf("*** Signal %d", status);
409 }
410
411
412 if (!WIFEXITED(reason) || status != 0) {
413 if (errCheck) {
414 #ifdef USE_META
415 if (useMeta)
416 meta_job_error(NULL, gn, false, status);
417 #endif
418 gn->made = ERROR;
419 if (opts.keepgoing) {
420 /*
421 * Abort the current target,
422 * but let others continue.
423 */
424 printf(" (continuing)\n");
425 } else {
426 printf("\n");
427 }
428 if (deleteOnError)
429 CompatDeleteTarget(gn);
430 } else {
431 /*
432 * Continue executing commands for this target.
433 * If we return 0, this will happen...
434 */
435 printf(" (ignored)\n");
436 status = 0;
437 }
438 }
439
440 free(cmdStart);
441 compatChild = 0;
442 if (compatSigno != 0) {
443 bmake_signal(compatSigno, SIG_DFL);
444 kill(myPid, compatSigno);
445 }
446
447 return status == 0;
448 }
449
450 static void
451 RunCommands(GNode *gn)
452 {
453 StringListNode *ln;
454
455 for (ln = gn->commands.first; ln != NULL; ln = ln->next) {
456 const char *cmd = ln->datum;
457 if (!Compat_RunCommand(cmd, gn, ln))
458 break;
459 }
460 }
461
462 static void
463 MakeInRandomOrder(GNode **gnodes, GNode **end, GNode *pgn)
464 {
465 GNode **it;
466 size_t r;
467
468 for (r = (size_t)(end - gnodes); r >= 2; r--) {
469 /* Biased, but irrelevant in practice. */
470 size_t i = (size_t)random() % r;
471 GNode *t = gnodes[r - 1];
472 gnodes[r - 1] = gnodes[i];
473 gnodes[i] = t;
474 }
475
476 for (it = gnodes; it != end; it++)
477 Compat_Make(*it, pgn);
478 }
479
480 static void
481 MakeWaitGroupsInRandomOrder(GNodeList *gnodes, GNode *pgn)
482 {
483 Vector vec;
484 GNodeListNode *ln;
485 GNode **nodes;
486 size_t i, n, start;
487
488 Vector_Init(&vec, sizeof(GNode *));
489 for (ln = gnodes->first; ln != NULL; ln = ln->next)
490 *(GNode **)Vector_Push(&vec) = ln->datum;
491 nodes = vec.items;
492 n = vec.len;
493
494 start = 0;
495 for (i = 0; i < n; i++) {
496 if (nodes[i]->type & OP_WAIT) {
497 MakeInRandomOrder(nodes + start, nodes + i, pgn);
498 Compat_Make(nodes[i], pgn);
499 start = i + 1;
500 }
501 }
502 MakeInRandomOrder(nodes + start, nodes + i, pgn);
503
504 Vector_Done(&vec);
505 }
506
507 static void
508 MakeNodes(GNodeList *gnodes, GNode *pgn)
509 {
510 GNodeListNode *ln;
511
512 if (Lst_IsEmpty(gnodes))
513 return;
514 if (opts.randomizeTargets) {
515 MakeWaitGroupsInRandomOrder(gnodes, pgn);
516 return;
517 }
518
519 for (ln = gnodes->first; ln != NULL; ln = ln->next) {
520 GNode *cgn = ln->datum;
521 Compat_Make(cgn, pgn);
522 }
523 }
524
525 static bool
526 MakeUnmade(GNode *gn, GNode *pgn)
527 {
528
529 assert(gn->made == UNMADE);
530
531 /*
532 * First mark ourselves to be made, then apply whatever transformations
533 * the suffix module thinks are necessary. Once that's done, we can
534 * descend and make all our children. If any of them has an error
535 * but the -k flag was given, our 'make' field will be set to false
536 * again. This is our signal to not attempt to do anything but abort
537 * our parent as well.
538 */
539 gn->flags.remake = true;
540 gn->made = BEINGMADE;
541
542 if (!(gn->type & OP_MADE))
543 Suff_FindDeps(gn);
544
545 MakeNodes(&gn->children, gn);
546
547 if (!gn->flags.remake) {
548 gn->made = ABORTED;
549 pgn->flags.remake = false;
550 return false;
551 }
552
553 if (Lst_FindDatum(&gn->implicitParents, pgn) != NULL)
554 Var_Set(pgn, IMPSRC, GNode_VarTarget(gn));
555
556 /*
557 * All the children were made ok. Now youngestChild->mtime contains the
558 * modification time of the newest child, we need to find out if we
559 * exist and when we were modified last. The criteria for datedness
560 * are defined by GNode_IsOODate.
561 */
562 DEBUG1(MAKE, "Examining %s...", gn->name);
563 if (!GNode_IsOODate(gn)) {
564 gn->made = UPTODATE;
565 DEBUG0(MAKE, "up-to-date.\n");
566 return false;
567 }
568
569 /*
570 * If the user is just seeing if something is out-of-date, exit now
571 * to tell him/her "yes".
572 */
573 DEBUG0(MAKE, "out-of-date.\n");
574 if (opts.query && gn != Targ_GetEndNode())
575 exit(1);
576
577 /*
578 * We need to be re-made.
579 * Ensure that $? (.OODATE) and $> (.ALLSRC) are both set.
580 */
581 GNode_SetLocalVars(gn);
582
583 /*
584 * Alter our type to tell if errors should be ignored or things
585 * should not be printed so Compat_RunCommand knows what to do.
586 */
587 if (opts.ignoreErrors)
588 gn->type |= OP_IGNORE;
589 if (opts.silent)
590 gn->type |= OP_SILENT;
591
592 if (Job_CheckCommands(gn, Fatal)) {
593 /*
594 * Our commands are ok, but we still have to worry about
595 * the -t flag.
596 */
597 if (!opts.touch || (gn->type & OP_MAKE)) {
598 curTarg = gn;
599 #ifdef USE_META
600 if (useMeta && GNode_ShouldExecute(gn))
601 meta_job_start(NULL, gn);
602 #endif
603 RunCommands(gn);
604 curTarg = NULL;
605 } else {
606 Job_Touch(gn, (gn->type & OP_SILENT) != OP_NONE);
607 }
608 } else {
609 gn->made = ERROR;
610 }
611 #ifdef USE_META
612 if (useMeta && GNode_ShouldExecute(gn)) {
613 if (meta_job_finish(NULL) != 0)
614 gn->made = ERROR;
615 }
616 #endif
617
618 if (gn->made != ERROR) {
619 /*
620 * If the node was made successfully, mark it so, update
621 * its modification time and timestamp all its parents.
622 * This is to keep its state from affecting that of its parent.
623 */
624 gn->made = MADE;
625 if (Make_Recheck(gn) == 0)
626 pgn->flags.force = true;
627 if (!(gn->type & OP_EXEC)) {
628 pgn->flags.childMade = true;
629 GNode_UpdateYoungestChild(pgn, gn);
630 }
631 } else if (opts.keepgoing) {
632 pgn->flags.remake = false;
633 } else {
634 PrintOnError(gn, "\nStop.\n");
635 exit(1);
636 }
637 return true;
638 }
639
640 static void
641 MakeOther(GNode *gn, GNode *pgn)
642 {
643
644 if (Lst_FindDatum(&gn->implicitParents, pgn) != NULL) {
645 const char *target = GNode_VarTarget(gn);
646 Var_Set(pgn, IMPSRC, target != NULL ? target : "");
647 }
648
649 switch (gn->made) {
650 case BEINGMADE:
651 Error("Graph cycles through %s", gn->name);
652 gn->made = ERROR;
653 pgn->flags.remake = false;
654 break;
655 case MADE:
656 if (!(gn->type & OP_EXEC)) {
657 pgn->flags.childMade = true;
658 GNode_UpdateYoungestChild(pgn, gn);
659 }
660 break;
661 case UPTODATE:
662 if (!(gn->type & OP_EXEC))
663 GNode_UpdateYoungestChild(pgn, gn);
664 break;
665 default:
666 break;
667 }
668 }
669
670 /*
671 * Make a target.
672 *
673 * If an error is detected and not being ignored, the process exits.
674 *
675 * Input:
676 * gn The node to make
677 * pgn Parent to abort if necessary
678 *
679 * Output:
680 * gn->made
681 * UPTODATE gn was already up-to-date.
682 * MADE gn was recreated successfully.
683 * ERROR An error occurred while gn was being created,
684 * either due to missing commands or in -k mode.
685 * ABORTED gn was not remade because one of its
686 * dependencies could not be made due to errors.
687 */
688 void
689 Compat_Make(GNode *gn, GNode *pgn)
690 {
691 if (shellName == NULL) /* we came here from jobs */
692 Shell_Init();
693
694 if (gn->made == UNMADE && (gn == pgn || !(pgn->type & OP_MADE))) {
695 if (!MakeUnmade(gn, pgn))
696 goto cohorts;
697
698 /* XXX: Replace with GNode_IsError(gn) */
699 } else if (gn->made == ERROR) {
700 /*
701 * Already had an error when making this.
702 * Tell the parent to abort.
703 */
704 pgn->flags.remake = false;
705 } else {
706 MakeOther(gn, pgn);
707 }
708
709 cohorts:
710 MakeNodes(&gn->cohorts, pgn);
711 }
712
713 static void
714 MakeBeginNode(void)
715 {
716 GNode *gn = Targ_FindNode(".BEGIN");
717 if (gn == NULL)
718 return;
719
720 Compat_Make(gn, gn);
721 if (GNode_IsError(gn)) {
722 PrintOnError(gn, "\nStop.\n");
723 exit(1);
724 }
725 }
726
727 static void
728 InitSignals(void)
729 {
730 if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN)
731 bmake_signal(SIGINT, CompatInterrupt);
732 if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN)
733 bmake_signal(SIGTERM, CompatInterrupt);
734 if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN)
735 bmake_signal(SIGHUP, CompatInterrupt);
736 if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN)
737 bmake_signal(SIGQUIT, CompatInterrupt);
738 }
739
740 void
741 Compat_MakeAll(GNodeList *targs)
742 {
743 GNode *errorNode = NULL;
744
745 if (shellName == NULL)
746 Shell_Init();
747
748 InitSignals();
749
750 /*
751 * Create the .END node now, to keep the (debug) output of the
752 * counter.mk test the same as before 2020-09-23. This
753 * implementation detail probably doesn't matter though.
754 */
755 (void)Targ_GetEndNode();
756
757 if (!opts.query)
758 MakeBeginNode();
759
760 /*
761 * Expand .USE nodes right now, because they can modify the structure
762 * of the tree.
763 */
764 Make_ExpandUse(targs);
765
766 while (!Lst_IsEmpty(targs)) {
767 GNode *gn = Lst_Dequeue(targs);
768 Compat_Make(gn, gn);
769
770 if (gn->made == UPTODATE) {
771 printf("`%s' is up to date.\n", gn->name);
772 } else if (gn->made == ABORTED) {
773 printf("`%s' not remade because of errors.\n",
774 gn->name);
775 }
776 if (GNode_IsError(gn) && errorNode == NULL)
777 errorNode = gn;
778 }
779
780 /* If the user has defined a .END target, run its commands. */
781 if (errorNode == NULL) {
782 GNode *endNode = Targ_GetEndNode();
783 Compat_Make(endNode, endNode);
784 if (GNode_IsError(endNode))
785 errorNode = endNode;
786 }
787
788 if (errorNode != NULL) {
789 if (DEBUG(GRAPH2))
790 Targ_PrintGraph(2);
791 else if (DEBUG(GRAPH3))
792 Targ_PrintGraph(3);
793 PrintOnError(errorNode, "\nStop.\n");
794 exit(1);
795 }
796 }
797