xref: /csrg-svn/usr.bin/make/compat.c (revision 60304)
140394Sbostic /*
240394Sbostic  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
340394Sbostic  * Copyright (c) 1988, 1989 by Adam de Boor
440394Sbostic  * Copyright (c) 1989 by Berkeley Softworks
540394Sbostic  * All rights reserved.
640394Sbostic  *
740394Sbostic  * This code is derived from software contributed to Berkeley by
840394Sbostic  * Adam de Boor.
940394Sbostic  *
1042746Sbostic  * %sccs.include.redist.c%
1140394Sbostic  */
1240394Sbostic 
1340394Sbostic #ifndef lint
14*60304Sbostic static char sccsid[] = "@(#)compat.c	5.12 (Berkeley) 05/24/93";
1540394Sbostic #endif /* not lint */
1640394Sbostic 
1740393Sbostic /*-
1840393Sbostic  * compat.c --
1940393Sbostic  *	The routines in this file implement the full-compatibility
2040393Sbostic  *	mode of PMake. Most of the special functionality of PMake
2140393Sbostic  *	is available in this mode. Things not supported:
2240393Sbostic  *	    - different shells.
2340393Sbostic  *	    - friendly variable substitution.
2440393Sbostic  *
2540393Sbostic  * Interface:
2640393Sbostic  *	Compat_Run	    Initialize things for this module and recreate
2740393Sbostic  *	    	  	    thems as need creatin'
2840393Sbostic  */
2940393Sbostic 
3040393Sbostic #include    <sys/types.h>
31*60304Sbostic #include    <sys/stat.h>
3240393Sbostic #include    <sys/wait.h>
3360302Sbostic 
3440393Sbostic #include    <ctype.h>
3560302Sbostic #include    <errno.h>
3660302Sbostic #include    <signal.h>
3760302Sbostic #include    <stdio.h>
3860302Sbostic 
3940393Sbostic #include    "make.h"
4060285Sbostic #include    "hash.h"
4160285Sbostic #include    "dir.h"
4260285Sbostic #include    "job.h"
4340393Sbostic extern int errno;
4440393Sbostic 
4540393Sbostic /*
4640393Sbostic  * The following array is used to make a fast determination of which
4740393Sbostic  * characters are interpreted specially by the shell.  If a command
4840393Sbostic  * contains any of these characters, it is executed by the shell, not
4940393Sbostic  * directly by us.
5040393Sbostic  */
5140393Sbostic 
5240393Sbostic static char 	    meta[256];
5340393Sbostic 
5440393Sbostic static GNode	    *curTarg = NILGNODE;
5540393Sbostic static GNode	    *ENDNode;
5660285Sbostic static void CompatInterrupt __P((int));
5760285Sbostic static int CompatRunCommand __P((char *, GNode *));
5860285Sbostic static int CompatMake __P((GNode *, GNode *));
5940393Sbostic 
6040393Sbostic /*-
6140393Sbostic  *-----------------------------------------------------------------------
6240393Sbostic  * CompatInterrupt --
6340393Sbostic  *	Interrupt the creation of the current target and remove it if
6440393Sbostic  *	it ain't precious.
6540393Sbostic  *
6640393Sbostic  * Results:
6740393Sbostic  *	None.
6840393Sbostic  *
6940393Sbostic  * Side Effects:
7040393Sbostic  *	The target is removed and the process exits. If .INTERRUPT exists,
7140393Sbostic  *	its commands are run first WITH INTERRUPTS IGNORED..
7240393Sbostic  *
7340393Sbostic  *-----------------------------------------------------------------------
7440393Sbostic  */
7546837Sbostic static void
7640393Sbostic CompatInterrupt (signo)
7740393Sbostic     int	    signo;
7840393Sbostic {
79*60304Sbostic     struct stat sb;
8040393Sbostic     GNode   *gn;
8140393Sbostic 
8240393Sbostic     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
8340393Sbostic 	char 	  *file = Var_Value (TARGET, curTarg);
8440393Sbostic 
85*60304Sbostic 	if (!stat(file, &sb) && S_ISREG(sb.st_mode) &&
86*60304Sbostic 	    unlink (file) == SUCCESS) {
8740393Sbostic 	    printf ("*** %s removed\n", file);
8840393Sbostic 	}
8940393Sbostic 
9040393Sbostic 	/*
9140393Sbostic 	 * Run .INTERRUPT only if hit with interrupt signal
9240393Sbostic 	 */
9340393Sbostic 	if (signo == SIGINT) {
9440393Sbostic 	    gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
9540393Sbostic 	    if (gn != NILGNODE) {
9640393Sbostic 		Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
9740393Sbostic 	    }
9840393Sbostic 	}
9940393Sbostic     }
10040393Sbostic     exit (0);
10140393Sbostic }
10240393Sbostic 
10340393Sbostic /*-
10440393Sbostic  *-----------------------------------------------------------------------
10540393Sbostic  * CompatRunCommand --
10640393Sbostic  *	Execute the next command for a target. If the command returns an
10740393Sbostic  *	error, the node's made field is set to ERROR and creation stops.
10840393Sbostic  *
10940393Sbostic  * Results:
11040393Sbostic  *	0 if the command succeeded, 1 if an error occurred.
11140393Sbostic  *
11240393Sbostic  * Side Effects:
11340393Sbostic  *	The node's 'made' field may be set to ERROR.
11440393Sbostic  *
11540393Sbostic  *-----------------------------------------------------------------------
11640393Sbostic  */
11740393Sbostic static int
11840393Sbostic CompatRunCommand (cmd, gn)
11940393Sbostic     char    	  *cmd;	    	/* Command to execute */
12040393Sbostic     GNode   	  *gn;    	/* Node from which the command came */
12140393Sbostic {
12240393Sbostic     char    	  *cmdStart;	/* Start of expanded command */
12340393Sbostic     register char *cp;
12440393Sbostic     Boolean 	  silent,   	/* Don't print command */
12540393Sbostic 		  errCheck; 	/* Check errors */
12640393Sbostic     union wait 	  reason;   	/* Reason for child's death */
12740393Sbostic     int	    	  status;   	/* Description of child's death */
12840393Sbostic     int	    	  cpid;	    	/* Child actually found */
12940393Sbostic     ReturnStatus  stat;	    	/* Status of fork */
13040393Sbostic     LstNode 	  cmdNode;  	/* Node where current command is located */
13140393Sbostic     char    	  **av;	    	/* Argument vector for thing to exec */
13240393Sbostic     int	    	  argc;	    	/* Number of arguments in av or 0 if not
13340393Sbostic 				 * dynamically allocated */
13440393Sbostic     Boolean 	  local;    	/* TRUE if command should be executed
13540393Sbostic 				 * locally */
13640393Sbostic 
13740393Sbostic     silent = gn->type & OP_SILENT;
13840393Sbostic     errCheck = !(gn->type & OP_IGNORE);
13940393Sbostic 
14040393Sbostic     cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
14160285Sbostic     cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
14240393Sbostic 
14340393Sbostic     /*
14440527Sbostic      * brk_string will return an argv with a NULL in av[1], thus causing
14540393Sbostic      * execvp to choke and die horribly. Besides, how can we execute a null
14640393Sbostic      * command? In any case, we warn the user that the command expanded to
14740393Sbostic      * nothing (is this the right thing to do?).
14840393Sbostic      */
14940393Sbostic 
15040393Sbostic     if (*cmdStart == '\0') {
15140539Sbostic 	Error("%s expands to empty string", cmd);
15240393Sbostic 	return(0);
15340393Sbostic     } else {
15440393Sbostic 	cmd = cmdStart;
15540393Sbostic     }
15640393Sbostic     Lst_Replace (cmdNode, (ClientData)cmdStart);
15740393Sbostic 
15840393Sbostic     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
15940393Sbostic 	(void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
16040393Sbostic 	return(0);
16140393Sbostic     } else if (strcmp(cmdStart, "...") == 0) {
16240393Sbostic 	gn->type |= OP_SAVE_CMDS;
16340393Sbostic 	return(0);
16440393Sbostic     }
16540393Sbostic 
16640393Sbostic     while ((*cmd == '@') || (*cmd == '-')) {
16740393Sbostic 	if (*cmd == '@') {
16840393Sbostic 	    silent = TRUE;
16940393Sbostic 	} else {
17040393Sbostic 	    errCheck = FALSE;
17140393Sbostic 	}
17240393Sbostic 	cmd++;
17340393Sbostic     }
17440393Sbostic 
17540393Sbostic     /*
17640393Sbostic      * Search for meta characters in the command. If there are no meta
17740393Sbostic      * characters, there's no need to execute a shell to execute the
17840393Sbostic      * command.
17940393Sbostic      */
18060285Sbostic     for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
18140393Sbostic 	continue;
18240393Sbostic     }
18340393Sbostic 
18440393Sbostic     /*
18540393Sbostic      * Print the command before echoing if we're not supposed to be quiet for
18640393Sbostic      * this one. We also print the command if -n given.
18740393Sbostic      */
18840393Sbostic     if (!silent || noExecute) {
18940393Sbostic 	printf ("%s\n", cmd);
19040393Sbostic 	fflush(stdout);
19140393Sbostic     }
19240393Sbostic 
19340393Sbostic     /*
19440393Sbostic      * If we're not supposed to execute any commands, this is as far as
19540393Sbostic      * we go...
19640393Sbostic      */
19740393Sbostic     if (noExecute) {
19840393Sbostic 	return (0);
19940393Sbostic     }
20040393Sbostic 
20140393Sbostic     if (*cp != '\0') {
20240393Sbostic 	/*
20340393Sbostic 	 * If *cp isn't the null character, we hit a "meta" character and
20440393Sbostic 	 * need to pass the command off to the shell. We give the shell the
20540393Sbostic 	 * -e flag as well as -c if it's supposed to exit when it hits an
20640393Sbostic 	 * error.
20740393Sbostic 	 */
20840393Sbostic 	static char	*shargv[4] = { "/bin/sh" };
20940393Sbostic 
21040393Sbostic 	shargv[1] = (errCheck ? "-ec" : "-c");
21140393Sbostic 	shargv[2] = cmd;
21240393Sbostic 	shargv[3] = (char *)NULL;
21340393Sbostic 	av = shargv;
21440393Sbostic 	argc = 0;
21540393Sbostic     } else {
21640393Sbostic 	/*
21740393Sbostic 	 * No meta-characters, so no need to exec a shell. Break the command
21840393Sbostic 	 * into words to form an argument vector we can execute.
21940527Sbostic 	 * brk_string sticks our name in av[0], so we have to
22040393Sbostic 	 * skip over it...
22140393Sbostic 	 */
22240527Sbostic 	av = brk_string(cmd, &argc);
22340393Sbostic 	av += 1;
22440393Sbostic     }
22540393Sbostic 
22640438Sbostic     local = TRUE;
22740393Sbostic 
22840393Sbostic     /*
22940393Sbostic      * Fork and execute the single command. If the fork fails, we abort.
23040393Sbostic      */
23140393Sbostic     cpid = vfork();
23240393Sbostic     if (cpid < 0) {
23340393Sbostic 	Fatal("Could not fork");
23440393Sbostic     }
23540393Sbostic     if (cpid == 0) {
23640393Sbostic 	if (local) {
23740393Sbostic 	    execvp(av[0], av);
23860285Sbostic 	    (void) write (2, av[0], strlen (av[0]));
23960285Sbostic 	    (void) write (2, ": not found\n", sizeof(": not found"));
24040393Sbostic 	} else {
24140438Sbostic 	    (void)execv(av[0], av);
24240393Sbostic 	}
24340393Sbostic 	exit(1);
24440393Sbostic     }
24540393Sbostic 
24640393Sbostic     /*
24740393Sbostic      * The child is off and running. Now all we can do is wait...
24840393Sbostic      */
24940393Sbostic     while (1) {
25040393Sbostic 	int 	  id;
25140393Sbostic 
25240393Sbostic 	if (!local) {
25340438Sbostic 	    id = 0;
25440393Sbostic 	}
25540393Sbostic 
25646837Sbostic 	while ((stat = wait((int *)&reason)) != cpid) {
25740393Sbostic 	    if (stat == -1 && errno != EINTR) {
25840393Sbostic 		break;
25940393Sbostic 	    }
26040393Sbostic 	}
26140393Sbostic 
26240393Sbostic 	if (stat > -1) {
26340393Sbostic 	    if (WIFSTOPPED(reason)) {
26440393Sbostic 		status = reason.w_stopval;		/* stopped */
26540393Sbostic 	    } else if (WIFEXITED(reason)) {
26640393Sbostic 		status = reason.w_retcode;		/* exited */
26740393Sbostic 		if (status != 0) {
26840393Sbostic 		    printf ("*** Error code %d", status);
26940393Sbostic 		}
27040393Sbostic 	    } else {
27140393Sbostic 		status = reason.w_termsig;		/* signaled */
27240393Sbostic 		printf ("*** Signal %d", status);
27340393Sbostic 	    }
27440393Sbostic 
27540393Sbostic 
27640393Sbostic 	    if (!WIFEXITED(reason) || (status != 0)) {
27740393Sbostic 		if (errCheck) {
27840393Sbostic 		    gn->made = ERROR;
27940393Sbostic 		    if (keepgoing) {
28040393Sbostic 			/*
28140393Sbostic 			 * Abort the current target, but let others
28240393Sbostic 			 * continue.
28340393Sbostic 			 */
28440393Sbostic 			printf (" (continuing)\n");
28540393Sbostic 		    }
28640393Sbostic 		} else {
28740393Sbostic 		    /*
28840393Sbostic 		     * Continue executing commands for this target.
28940393Sbostic 		     * If we return 0, this will happen...
29040393Sbostic 		     */
29140393Sbostic 		    printf (" (ignored)\n");
29240393Sbostic 		    status = 0;
29340393Sbostic 		}
29440393Sbostic 	    }
29540393Sbostic 	    break;
29640393Sbostic 	} else {
29740393Sbostic 	    Fatal ("error in wait: %d", stat);
29840393Sbostic 	    /*NOTREACHED*/
29940393Sbostic 	}
30040393Sbostic     }
30140393Sbostic 
30240393Sbostic     return (status);
30340393Sbostic }
30440393Sbostic 
30540393Sbostic /*-
30640393Sbostic  *-----------------------------------------------------------------------
30740393Sbostic  * CompatMake --
30840393Sbostic  *	Make a target.
30940393Sbostic  *
31040393Sbostic  * Results:
31140393Sbostic  *	0
31240393Sbostic  *
31340393Sbostic  * Side Effects:
31440393Sbostic  *	If an error is detected and not being ignored, the process exits.
31540393Sbostic  *
31640393Sbostic  *-----------------------------------------------------------------------
31740393Sbostic  */
31840393Sbostic static int
31940393Sbostic CompatMake (gn, pgn)
32040393Sbostic     GNode   	  *gn;	    /* The node to make */
32140393Sbostic     GNode   	  *pgn;	    /* Parent to abort if necessary */
32240393Sbostic {
32340393Sbostic     if (gn->type & OP_USE) {
32440393Sbostic 	Make_HandleUse(gn, pgn);
32540393Sbostic     } else if (gn->made == UNMADE) {
32640393Sbostic 	/*
32740393Sbostic 	 * First mark ourselves to be made, then apply whatever transformations
32840393Sbostic 	 * the suffix module thinks are necessary. Once that's done, we can
32940393Sbostic 	 * descend and make all our children. If any of them has an error
33040393Sbostic 	 * but the -k flag was given, our 'make' field will be set FALSE again.
33140393Sbostic 	 * This is our signal to not attempt to do anything but abort our
33240393Sbostic 	 * parent as well.
33340393Sbostic 	 */
33440393Sbostic 	gn->make = TRUE;
33540393Sbostic 	gn->made = BEINGMADE;
33640393Sbostic 	Suff_FindDeps (gn);
33740393Sbostic 	Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
33840393Sbostic 	if (!gn->make) {
33940393Sbostic 	    gn->made = ABORTED;
34040393Sbostic 	    pgn->make = FALSE;
34140393Sbostic 	    return (0);
34240393Sbostic 	}
34340393Sbostic 
34440393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
34540393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
34640393Sbostic 	}
34740393Sbostic 
34840393Sbostic 	/*
34940393Sbostic 	 * All the children were made ok. Now cmtime contains the modification
35040393Sbostic 	 * time of the newest child, we need to find out if we exist and when
35140393Sbostic 	 * we were modified last. The criteria for datedness are defined by the
35240393Sbostic 	 * Make_OODate function.
35340393Sbostic 	 */
35440393Sbostic 	if (DEBUG(MAKE)) {
35540393Sbostic 	    printf("Examining %s...", gn->name);
35640393Sbostic 	}
35740393Sbostic 	if (! Make_OODate(gn)) {
35840393Sbostic 	    gn->made = UPTODATE;
35940393Sbostic 	    if (DEBUG(MAKE)) {
36040393Sbostic 		printf("up-to-date.\n");
36140393Sbostic 	    }
36240393Sbostic 	    return (0);
36340393Sbostic 	} else if (DEBUG(MAKE)) {
36440393Sbostic 	    printf("out-of-date.\n");
36540393Sbostic 	}
36640393Sbostic 
36740393Sbostic 	/*
36840393Sbostic 	 * If the user is just seeing if something is out-of-date, exit now
36940393Sbostic 	 * to tell him/her "yes".
37040393Sbostic 	 */
37140393Sbostic 	if (queryFlag) {
37240393Sbostic 	    exit (-1);
37340393Sbostic 	}
37440393Sbostic 
37540393Sbostic 	/*
37640393Sbostic 	 * We need to be re-made. We also have to make sure we've got a $?
37740393Sbostic 	 * variable. To be nice, we also define the $> variable using
37840393Sbostic 	 * Make_DoAllVar().
37940393Sbostic 	 */
38040393Sbostic 	Make_DoAllVar(gn);
38140393Sbostic 
38240393Sbostic 	/*
38340393Sbostic 	 * Alter our type to tell if errors should be ignored or things
38440393Sbostic 	 * should not be printed so CompatRunCommand knows what to do.
38540393Sbostic 	 */
38640393Sbostic 	if (Targ_Ignore (gn)) {
38740393Sbostic 	    gn->type |= OP_IGNORE;
38840393Sbostic 	}
38940393Sbostic 	if (Targ_Silent (gn)) {
39040393Sbostic 	    gn->type |= OP_SILENT;
39140393Sbostic 	}
39240393Sbostic 
39340393Sbostic 	if (Job_CheckCommands (gn, Fatal)) {
39440393Sbostic 	    /*
39540393Sbostic 	     * Our commands are ok, but we still have to worry about the -t
39640393Sbostic 	     * flag...
39740393Sbostic 	     */
39840393Sbostic 	    if (!touchFlag) {
39940393Sbostic 		curTarg = gn;
40040393Sbostic 		Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
40140393Sbostic 		curTarg = NILGNODE;
40240393Sbostic 	    } else {
40340393Sbostic 		Job_Touch (gn, gn->type & OP_SILENT);
40440393Sbostic 	    }
40540393Sbostic 	} else {
40640393Sbostic 	    gn->made = ERROR;
40740393Sbostic 	}
40840393Sbostic 
40940393Sbostic 	if (gn->made != ERROR) {
41040393Sbostic 	    /*
41140393Sbostic 	     * If the node was made successfully, mark it so, update
41240393Sbostic 	     * its modification time and timestamp all its parents. Note
41340393Sbostic 	     * that for .ZEROTIME targets, the timestamping isn't done.
41440393Sbostic 	     * This is to keep its state from affecting that of its parent.
41540393Sbostic 	     */
41640393Sbostic 	    gn->made = MADE;
41740393Sbostic #ifndef RECHECK
41840393Sbostic 	    /*
41940393Sbostic 	     * We can't re-stat the thing, but we can at least take care of
42040393Sbostic 	     * rules where a target depends on a source that actually creates
42140393Sbostic 	     * the target, but only if it has changed, e.g.
42240393Sbostic 	     *
42340393Sbostic 	     * parse.h : parse.o
42440393Sbostic 	     *
42540393Sbostic 	     * parse.o : parse.y
42640393Sbostic 	     *  	yacc -d parse.y
42740393Sbostic 	     *  	cc -c y.tab.c
42840393Sbostic 	     *  	mv y.tab.o parse.o
42940393Sbostic 	     *  	cmp -s y.tab.h parse.h || mv y.tab.h parse.h
43040393Sbostic 	     *
43140393Sbostic 	     * In this case, if the definitions produced by yacc haven't
43240393Sbostic 	     * changed from before, parse.h won't have been updated and
43340393Sbostic 	     * gn->mtime will reflect the current modification time for
43440393Sbostic 	     * parse.h. This is something of a kludge, I admit, but it's a
43540393Sbostic 	     * useful one..
43640393Sbostic 	     *
43740393Sbostic 	     * XXX: People like to use a rule like
43840393Sbostic 	     *
43940393Sbostic 	     * FRC:
44040393Sbostic 	     *
44140393Sbostic 	     * To force things that depend on FRC to be made, so we have to
44240393Sbostic 	     * check for gn->children being empty as well...
44340393Sbostic 	     */
44440393Sbostic 	    if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
44540393Sbostic 		gn->mtime = now;
44640393Sbostic 	    }
44740393Sbostic #else
44840393Sbostic 	    /*
44940393Sbostic 	     * This is what Make does and it's actually a good thing, as it
45040393Sbostic 	     * allows rules like
45140393Sbostic 	     *
45240393Sbostic 	     *	cmp -s y.tab.h parse.h || cp y.tab.h parse.h
45340393Sbostic 	     *
45440393Sbostic 	     * to function as intended. Unfortunately, thanks to the stateless
45540393Sbostic 	     * nature of NFS (and the speed of this program), there are times
45640393Sbostic 	     * when the modification time of a file created on a remote
45740393Sbostic 	     * machine will not be modified before the stat() implied by
45840393Sbostic 	     * the Dir_MTime occurs, thus leading us to believe that the file
45940393Sbostic 	     * is unchanged, wreaking havoc with files that depend on this one.
46040393Sbostic 	     *
46140393Sbostic 	     * I have decided it is better to make too much than to make too
46240393Sbostic 	     * little, so this stuff is commented out unless you're sure it's
46340393Sbostic 	     * ok.
46440393Sbostic 	     * -- ardeb 1/12/88
46540393Sbostic 	     */
46640393Sbostic 	    if (noExecute || Dir_MTime(gn) == 0) {
46740393Sbostic 		gn->mtime = now;
46840393Sbostic 	    }
46960285Sbostic 	    if (gn->cmtime > gn->mtime)
47060285Sbostic 		gn->mtime = gn->cmtime;
47140393Sbostic 	    if (DEBUG(MAKE)) {
47240393Sbostic 		printf("update time: %s\n", Targ_FmtTime(gn->mtime));
47340393Sbostic 	    }
47440393Sbostic #endif
47540393Sbostic 	    if (!(gn->type & OP_EXEC)) {
47640393Sbostic 		pgn->childMade = TRUE;
47740393Sbostic 		Make_TimeStamp(pgn, gn);
47840393Sbostic 	    }
47940393Sbostic 	} else if (keepgoing) {
48040393Sbostic 	    pgn->make = FALSE;
48140393Sbostic 	} else {
48240393Sbostic 	    printf ("\n\nStop.\n");
48340393Sbostic 	    exit (1);
48440393Sbostic 	}
48540393Sbostic     } else if (gn->made == ERROR) {
48640393Sbostic 	/*
48740393Sbostic 	 * Already had an error when making this beastie. Tell the parent
48840393Sbostic 	 * to abort.
48940393Sbostic 	 */
49040393Sbostic 	pgn->make = FALSE;
49140393Sbostic     } else {
49240393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
49340393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
49440393Sbostic 	}
49540393Sbostic 	switch(gn->made) {
49640393Sbostic 	    case BEINGMADE:
49740393Sbostic 		Error("Graph cycles through %s\n", gn->name);
49840393Sbostic 		gn->made = ERROR;
49940393Sbostic 		pgn->make = FALSE;
50040393Sbostic 		break;
50140393Sbostic 	    case MADE:
50240393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
50340393Sbostic 		    pgn->childMade = TRUE;
50440393Sbostic 		    Make_TimeStamp(pgn, gn);
50540393Sbostic 		}
50640393Sbostic 		break;
50740393Sbostic 	    case UPTODATE:
50840393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
50940393Sbostic 		    Make_TimeStamp(pgn, gn);
51040393Sbostic 		}
51140393Sbostic 		break;
51260285Sbostic 	    default:
51360285Sbostic 		break;
51440393Sbostic 	}
51540393Sbostic     }
51640393Sbostic 
51740393Sbostic     return (0);
51840393Sbostic }
51940393Sbostic 
52040393Sbostic /*-
52140393Sbostic  *-----------------------------------------------------------------------
52240393Sbostic  * Compat_Run --
52340393Sbostic  *	Initialize this mode and start making.
52440393Sbostic  *
52540393Sbostic  * Results:
52640393Sbostic  *	None.
52740393Sbostic  *
52840393Sbostic  * Side Effects:
52940393Sbostic  *	Guess what?
53040393Sbostic  *
53140393Sbostic  *-----------------------------------------------------------------------
53240393Sbostic  */
53340393Sbostic void
53440393Sbostic Compat_Run(targs)
53540393Sbostic     Lst	    	  targs;    /* List of target nodes to re-create */
53640393Sbostic {
53740393Sbostic     char    	  *cp;	    /* Pointer to string of shell meta-characters */
53860285Sbostic     GNode   	  *gn = NULL;/* Current root target */
53940393Sbostic     int	    	  errors;   /* Number of targets not remade due to errors */
54040393Sbostic 
54140393Sbostic     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
54240393Sbostic 	signal(SIGINT, CompatInterrupt);
54340393Sbostic     }
54440393Sbostic     if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
54540393Sbostic 	signal(SIGTERM, CompatInterrupt);
54640393Sbostic     }
54740393Sbostic     if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
54840393Sbostic 	signal(SIGHUP, CompatInterrupt);
54940393Sbostic     }
55040393Sbostic     if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
55140393Sbostic 	signal(SIGQUIT, CompatInterrupt);
55240393Sbostic     }
55340393Sbostic 
55440393Sbostic     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
55560285Sbostic 	meta[(unsigned char) *cp] = 1;
55640393Sbostic     }
55740393Sbostic     /*
55840393Sbostic      * The null character serves as a sentinel in the string.
55940393Sbostic      */
56040393Sbostic     meta[0] = 1;
56140393Sbostic 
56240393Sbostic     ENDNode = Targ_FindNode(".END", TARG_CREATE);
56340393Sbostic     /*
56440393Sbostic      * If the user has defined a .BEGIN target, execute the commands attached
56540393Sbostic      * to it.
56640393Sbostic      */
56740393Sbostic     if (!queryFlag) {
56840393Sbostic 	gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
56940393Sbostic 	if (gn != NILGNODE) {
57040393Sbostic 	    Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
57140393Sbostic 	}
57240393Sbostic     }
57340393Sbostic 
57440393Sbostic     /*
57540393Sbostic      * For each entry in the list of targets to create, call CompatMake on
57640393Sbostic      * it to create the thing. CompatMake will leave the 'made' field of gn
57740393Sbostic      * in one of several states:
57840393Sbostic      *	    UPTODATE	    gn was already up-to-date
57940393Sbostic      *	    MADE  	    gn was recreated successfully
58040393Sbostic      *	    ERROR 	    An error occurred while gn was being created
58140393Sbostic      *	    ABORTED	    gn was not remade because one of its inferiors
58240393Sbostic      *	    	  	    could not be made due to errors.
58340393Sbostic      */
58440393Sbostic     errors = 0;
58540393Sbostic     while (!Lst_IsEmpty (targs)) {
58640393Sbostic 	gn = (GNode *) Lst_DeQueue (targs);
58740393Sbostic 	CompatMake (gn, gn);
58840393Sbostic 
58940393Sbostic 	if (gn->made == UPTODATE) {
59040393Sbostic 	    printf ("`%s' is up to date.\n", gn->name);
59140393Sbostic 	} else if (gn->made == ABORTED) {
59240393Sbostic 	    printf ("`%s' not remade because of errors.\n", gn->name);
59340393Sbostic 	    errors += 1;
59440393Sbostic 	}
59540393Sbostic     }
59640393Sbostic 
59740393Sbostic     /*
59840393Sbostic      * If the user has defined a .END target, run its commands.
59940393Sbostic      */
60040393Sbostic     if (errors == 0) {
60140393Sbostic 	Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
60240393Sbostic     }
60340393Sbostic }
604