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