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