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