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