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