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