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