Home | History | Annotate | Line # | Download | only in make
compat.c revision 1.104
      1 /*	$NetBSD: compat.c,v 1.104 2016/02/18 18:29:14 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.104 2016/02/18 18:29:14 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.104 2016/02/18 18:29:14 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 
    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, VARF_WANTRES);
    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 
    376     free(mav);
    377     free(bp);
    378 
    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 	    free(p1);
    519 	}
    520 
    521 	/*
    522 	 * All the children were made ok. Now cmgn->mtime contains the
    523 	 * modification time of the newest child, we need to find out if we
    524 	 * exist and when we were modified last. The criteria for datedness
    525 	 * are defined by the Make_OODate function.
    526 	 */
    527 	if (DEBUG(MAKE)) {
    528 	    fprintf(debug_file, "Examining %s...", gn->name);
    529 	}
    530 	if (! Make_OODate(gn)) {
    531 	    gn->made = UPTODATE;
    532 	    if (DEBUG(MAKE)) {
    533 		fprintf(debug_file, "up-to-date.\n");
    534 	    }
    535 	    goto cohorts;
    536 	} else if (DEBUG(MAKE)) {
    537 	    fprintf(debug_file, "out-of-date.\n");
    538 	}
    539 
    540 	/*
    541 	 * If the user is just seeing if something is out-of-date, exit now
    542 	 * to tell him/her "yes".
    543 	 */
    544 	if (queryFlag) {
    545 	    exit(1);
    546 	}
    547 
    548 	/*
    549 	 * We need to be re-made. We also have to make sure we've got a $?
    550 	 * variable. To be nice, we also define the $> variable using
    551 	 * Make_DoAllVar().
    552 	 */
    553 	Make_DoAllVar(gn);
    554 
    555 	/*
    556 	 * Alter our type to tell if errors should be ignored or things
    557 	 * should not be printed so CompatRunCommand knows what to do.
    558 	 */
    559 	if (Targ_Ignore(gn)) {
    560 	    gn->type |= OP_IGNORE;
    561 	}
    562 	if (Targ_Silent(gn)) {
    563 	    gn->type |= OP_SILENT;
    564 	}
    565 
    566 	if (Job_CheckCommands(gn, Fatal)) {
    567 	    /*
    568 	     * Our commands are ok, but we still have to worry about the -t
    569 	     * flag...
    570 	     */
    571 	    if (!touchFlag || (gn->type & OP_MAKE)) {
    572 		curTarg = gn;
    573 #ifdef USE_META
    574 		if (useMeta && !NoExecute(gn)) {
    575 		    meta_job_start(NULL, gn);
    576 		}
    577 #endif
    578 		Lst_ForEach(gn->commands, CompatRunCommand, gn);
    579 		curTarg = NULL;
    580 	    } else {
    581 		Job_Touch(gn, gn->type & OP_SILENT);
    582 	    }
    583 	} else {
    584 	    gn->made = ERROR;
    585 	}
    586 #ifdef USE_META
    587 	if (useMeta && !NoExecute(gn)) {
    588 	    meta_job_finish(NULL);
    589 	}
    590 #endif
    591 
    592 	if (gn->made != ERROR) {
    593 	    /*
    594 	     * If the node was made successfully, mark it so, update
    595 	     * its modification time and timestamp all its parents. Note
    596 	     * that for .ZEROTIME targets, the timestamping isn't done.
    597 	     * This is to keep its state from affecting that of its parent.
    598 	     */
    599 	    gn->made = MADE;
    600 	    pgn->flags |= Make_Recheck(gn) == 0 ? FORCE : 0;
    601 	    if (!(gn->type & OP_EXEC)) {
    602 		pgn->flags |= CHILDMADE;
    603 		Make_TimeStamp(pgn, gn);
    604 	    }
    605 	} else if (keepgoing) {
    606 	    pgn->flags &= ~REMAKE;
    607 	} else {
    608 	    PrintOnError(gn, "\n\nStop.");
    609 	    exit(1);
    610 	}
    611     } else if (gn->made == ERROR) {
    612 	/*
    613 	 * Already had an error when making this beastie. Tell the parent
    614 	 * to abort.
    615 	 */
    616 	pgn->flags &= ~REMAKE;
    617     } else {
    618 	if (Lst_Member(gn->iParents, pgn) != NULL) {
    619 	    char *p1;
    620 	    Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
    621 	    free(p1);
    622 	}
    623 	switch(gn->made) {
    624 	    case BEINGMADE:
    625 		Error("Graph cycles through %s", gn->name);
    626 		gn->made = ERROR;
    627 		pgn->flags &= ~REMAKE;
    628 		break;
    629 	    case MADE:
    630 		if ((gn->type & OP_EXEC) == 0) {
    631 		    pgn->flags |= CHILDMADE;
    632 		    Make_TimeStamp(pgn, gn);
    633 		}
    634 		break;
    635 	    case UPTODATE:
    636 		if ((gn->type & OP_EXEC) == 0) {
    637 		    Make_TimeStamp(pgn, gn);
    638 		}
    639 		break;
    640 	    default:
    641 		break;
    642 	}
    643     }
    644 
    645 cohorts:
    646     Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
    647     return (0);
    648 }
    649 
    650 /*-
    652  *-----------------------------------------------------------------------
    653  * Compat_Run --
    654  *	Initialize this mode and start making.
    655  *
    656  * Input:
    657  *	targs		List of target nodes to re-create
    658  *
    659  * Results:
    660  *	None.
    661  *
    662  * Side Effects:
    663  *	Guess what?
    664  *
    665  *-----------------------------------------------------------------------
    666  */
    667 void
    668 Compat_Run(Lst targs)
    669 {
    670     GNode   	  *gn = NULL;/* Current root target */
    671     int	    	  errors;   /* Number of targets not remade due to errors */
    672 
    673     if (!shellName)
    674 	Shell_Init();
    675 
    676     if (bmake_signal(SIGINT, SIG_IGN) != SIG_IGN) {
    677 	bmake_signal(SIGINT, CompatInterrupt);
    678     }
    679     if (bmake_signal(SIGTERM, SIG_IGN) != SIG_IGN) {
    680 	bmake_signal(SIGTERM, CompatInterrupt);
    681     }
    682     if (bmake_signal(SIGHUP, SIG_IGN) != SIG_IGN) {
    683 	bmake_signal(SIGHUP, CompatInterrupt);
    684     }
    685     if (bmake_signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
    686 	bmake_signal(SIGQUIT, CompatInterrupt);
    687     }
    688 
    689     ENDNode = Targ_FindNode(".END", TARG_CREATE);
    690     ENDNode->type = OP_SPECIAL;
    691     /*
    692      * If the user has defined a .BEGIN target, execute the commands attached
    693      * to it.
    694      */
    695     if (!queryFlag) {
    696 	gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    697 	if (gn != NULL) {
    698 	    Compat_Make(gn, gn);
    699             if (gn->made == ERROR) {
    700                 PrintOnError(gn, "\n\nStop.");
    701                 exit(1);
    702             }
    703 	}
    704     }
    705 
    706     /*
    707      * Expand .USE nodes right now, because they can modify the structure
    708      * of the tree.
    709      */
    710     Make_ExpandUse(targs);
    711 
    712     /*
    713      * For each entry in the list of targets to create, call Compat_Make on
    714      * it to create the thing. Compat_Make will leave the 'made' field of gn
    715      * in one of several states:
    716      *	    UPTODATE	    gn was already up-to-date
    717      *	    MADE  	    gn was recreated successfully
    718      *	    ERROR 	    An error occurred while gn was being created
    719      *	    ABORTED	    gn was not remade because one of its inferiors
    720      *	    	  	    could not be made due to errors.
    721      */
    722     errors = 0;
    723     while (!Lst_IsEmpty (targs)) {
    724 	gn = (GNode *)Lst_DeQueue(targs);
    725 	Compat_Make(gn, gn);
    726 
    727 	if (gn->made == UPTODATE) {
    728 	    printf("`%s' is up to date.\n", gn->name);
    729 	} else if (gn->made == ABORTED) {
    730 	    printf("`%s' not remade because of errors.\n", gn->name);
    731 	    errors += 1;
    732 	}
    733     }
    734 
    735     /*
    736      * If the user has defined a .END target, run its commands.
    737      */
    738     if (errors == 0) {
    739 	Compat_Make(ENDNode, ENDNode);
    740 	if (gn->made == ERROR) {
    741 	    PrintOnError(gn, "\n\nStop.");
    742 	    exit(1);
    743 	}
    744     }
    745 }
    746