xref: /csrg-svn/usr.bin/make/compat.c (revision 40539)
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  *
1040394Sbostic  * Redistribution and use in source and binary forms are permitted
1140394Sbostic  * provided that the above copyright notice and this paragraph are
1240394Sbostic  * duplicated in all such forms and that any documentation,
1340394Sbostic  * advertising materials, and other materials related to such
1440394Sbostic  * distribution and use acknowledge that the software was developed
1540394Sbostic  * by the University of California, Berkeley.  The name of the
1640394Sbostic  * University may not be used to endorse or promote products derived
1740394Sbostic  * from this software without specific prior written permission.
1840394Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1940394Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
2040394Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2140394Sbostic  */
2240394Sbostic 
2340394Sbostic #ifndef lint
24*40539Sbostic static char sccsid[] = "@(#)compat.c	5.5 (Berkeley) 03/19/90";
2540394Sbostic #endif /* not lint */
2640394Sbostic 
2740393Sbostic /*-
2840393Sbostic  * compat.c --
2940393Sbostic  *	The routines in this file implement the full-compatibility
3040393Sbostic  *	mode of PMake. Most of the special functionality of PMake
3140393Sbostic  *	is available in this mode. Things not supported:
3240393Sbostic  *	    - different shells.
3340393Sbostic  *	    - friendly variable substitution.
3440393Sbostic  *
3540393Sbostic  * Interface:
3640393Sbostic  *	Compat_Run	    Initialize things for this module and recreate
3740393Sbostic  *	    	  	    thems as need creatin'
3840393Sbostic  */
3940393Sbostic 
4040393Sbostic #include    <stdio.h>
4140393Sbostic #include    <sys/types.h>
4240393Sbostic #include    <sys/signal.h>
4340393Sbostic #include    <sys/wait.h>
4440393Sbostic #include    <sys/errno.h>
4540393Sbostic #include    <ctype.h>
4640393Sbostic #include    "make.h"
4740393Sbostic extern int errno;
4840393Sbostic 
4940393Sbostic /*
5040393Sbostic  * The following array is used to make a fast determination of which
5140393Sbostic  * characters are interpreted specially by the shell.  If a command
5240393Sbostic  * contains any of these characters, it is executed by the shell, not
5340393Sbostic  * directly by us.
5440393Sbostic  */
5540393Sbostic 
5640393Sbostic static char 	    meta[256];
5740393Sbostic 
5840393Sbostic static GNode	    *curTarg = NILGNODE;
5940393Sbostic static GNode	    *ENDNode;
6040393Sbostic static int  	    CompatRunCommand();
6140393Sbostic 
6240393Sbostic /*-
6340393Sbostic  *-----------------------------------------------------------------------
6440393Sbostic  * CompatInterrupt --
6540393Sbostic  *	Interrupt the creation of the current target and remove it if
6640393Sbostic  *	it ain't precious.
6740393Sbostic  *
6840393Sbostic  * Results:
6940393Sbostic  *	None.
7040393Sbostic  *
7140393Sbostic  * Side Effects:
7240393Sbostic  *	The target is removed and the process exits. If .INTERRUPT exists,
7340393Sbostic  *	its commands are run first WITH INTERRUPTS IGNORED..
7440393Sbostic  *
7540393Sbostic  *-----------------------------------------------------------------------
7640393Sbostic  */
7740393Sbostic static int
7840393Sbostic CompatInterrupt (signo)
7940393Sbostic     int	    signo;
8040393Sbostic {
8140393Sbostic     GNode   *gn;
8240393Sbostic 
8340393Sbostic     if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
8440393Sbostic 	char 	  *file = Var_Value (TARGET, curTarg);
8540393Sbostic 
8640393Sbostic 	if (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     int	    	  numWritten;	/* Number of bytes written for error message */
13040393Sbostic     ReturnStatus  stat;	    	/* Status of fork */
13140393Sbostic     LstNode 	  cmdNode;  	/* Node where current command is located */
13240393Sbostic     char    	  **av;	    	/* Argument vector for thing to exec */
13340393Sbostic     int	    	  argc;	    	/* Number of arguments in av or 0 if not
13440393Sbostic 				 * dynamically allocated */
13540393Sbostic     Boolean 	  local;    	/* TRUE if command should be executed
13640393Sbostic 				 * locally */
13740393Sbostic 
13840393Sbostic     silent = gn->type & OP_SILENT;
13940393Sbostic     errCheck = !(gn->type & OP_IGNORE);
14040393Sbostic 
14140393Sbostic     cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
14240393Sbostic     cmdStart = Var_Subst (cmd, gn, FALSE);
14340393Sbostic 
14440393Sbostic     /*
14540527Sbostic      * brk_string will return an argv with a NULL in av[1], thus causing
14640393Sbostic      * execvp to choke and die horribly. Besides, how can we execute a null
14740393Sbostic      * command? In any case, we warn the user that the command expanded to
14840393Sbostic      * nothing (is this the right thing to do?).
14940393Sbostic      */
15040393Sbostic 
15140393Sbostic     if (*cmdStart == '\0') {
152*40539Sbostic 	Error("%s expands to empty string", cmd);
15340393Sbostic 	return(0);
15440393Sbostic     } else {
15540393Sbostic 	cmd = cmdStart;
15640393Sbostic     }
15740393Sbostic     Lst_Replace (cmdNode, (ClientData)cmdStart);
15840393Sbostic 
15940393Sbostic     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
16040393Sbostic 	(void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
16140393Sbostic 	return(0);
16240393Sbostic     } else if (strcmp(cmdStart, "...") == 0) {
16340393Sbostic 	gn->type |= OP_SAVE_CMDS;
16440393Sbostic 	return(0);
16540393Sbostic     }
16640393Sbostic 
16740393Sbostic     while ((*cmd == '@') || (*cmd == '-')) {
16840393Sbostic 	if (*cmd == '@') {
16940393Sbostic 	    silent = TRUE;
17040393Sbostic 	} else {
17140393Sbostic 	    errCheck = FALSE;
17240393Sbostic 	}
17340393Sbostic 	cmd++;
17440393Sbostic     }
17540393Sbostic 
17640393Sbostic     /*
17740393Sbostic      * Search for meta characters in the command. If there are no meta
17840393Sbostic      * characters, there's no need to execute a shell to execute the
17940393Sbostic      * command.
18040393Sbostic      */
18140393Sbostic     for (cp = cmd; !meta[*cp]; cp++) {
18240393Sbostic 	continue;
18340393Sbostic     }
18440393Sbostic 
18540393Sbostic     /*
18640393Sbostic      * Print the command before echoing if we're not supposed to be quiet for
18740393Sbostic      * this one. We also print the command if -n given.
18840393Sbostic      */
18940393Sbostic     if (!silent || noExecute) {
19040393Sbostic 	printf ("%s\n", cmd);
19140393Sbostic 	fflush(stdout);
19240393Sbostic     }
19340393Sbostic 
19440393Sbostic     /*
19540393Sbostic      * If we're not supposed to execute any commands, this is as far as
19640393Sbostic      * we go...
19740393Sbostic      */
19840393Sbostic     if (noExecute) {
19940393Sbostic 	return (0);
20040393Sbostic     }
20140393Sbostic 
20240393Sbostic     if (*cp != '\0') {
20340393Sbostic 	/*
20440393Sbostic 	 * If *cp isn't the null character, we hit a "meta" character and
20540393Sbostic 	 * need to pass the command off to the shell. We give the shell the
20640393Sbostic 	 * -e flag as well as -c if it's supposed to exit when it hits an
20740393Sbostic 	 * error.
20840393Sbostic 	 */
20940393Sbostic 	static char	*shargv[4] = { "/bin/sh" };
21040393Sbostic 
21140393Sbostic 	shargv[1] = (errCheck ? "-ec" : "-c");
21240393Sbostic 	shargv[2] = cmd;
21340393Sbostic 	shargv[3] = (char *)NULL;
21440393Sbostic 	av = shargv;
21540393Sbostic 	argc = 0;
21640393Sbostic     } else {
21740393Sbostic 	/*
21840393Sbostic 	 * No meta-characters, so no need to exec a shell. Break the command
21940393Sbostic 	 * into words to form an argument vector we can execute.
22040527Sbostic 	 * brk_string sticks our name in av[0], so we have to
22140393Sbostic 	 * skip over it...
22240393Sbostic 	 */
22340527Sbostic 	av = brk_string(cmd, &argc);
22440393Sbostic 	av += 1;
22540393Sbostic     }
22640393Sbostic 
22740438Sbostic     local = TRUE;
22840393Sbostic 
22940393Sbostic     /*
23040393Sbostic      * Fork and execute the single command. If the fork fails, we abort.
23140393Sbostic      */
23240393Sbostic     cpid = vfork();
23340393Sbostic     if (cpid < 0) {
23440393Sbostic 	Fatal("Could not fork");
23540393Sbostic     }
23640393Sbostic     if (cpid == 0) {
23740393Sbostic 	if (local) {
23840393Sbostic 	    execvp(av[0], av);
23940393Sbostic 	    numWritten = write (2, av[0], strlen (av[0]));
24040393Sbostic 	    numWritten = write (2, ": not found\n", sizeof(": not found"));
24140393Sbostic 	} else {
24240438Sbostic 	    (void)execv(av[0], av);
24340393Sbostic 	}
24440393Sbostic 	exit(1);
24540393Sbostic     }
24640393Sbostic 
24740393Sbostic     /*
24840393Sbostic      * The child is off and running. Now all we can do is wait...
24940393Sbostic      */
25040393Sbostic     while (1) {
25140393Sbostic 	int 	  id;
25240393Sbostic 
25340393Sbostic 	if (!local) {
25440438Sbostic 	    id = 0;
25540393Sbostic 	}
25640393Sbostic 
25740393Sbostic 	while ((stat = wait(&reason)) != cpid) {
25840393Sbostic 	    if (stat == -1 && errno != EINTR) {
25940393Sbostic 		break;
26040393Sbostic 	    }
26140393Sbostic 	}
26240393Sbostic 
26340393Sbostic 	if (stat > -1) {
26440393Sbostic 	    if (WIFSTOPPED(reason)) {
26540393Sbostic 		status = reason.w_stopval;		/* stopped */
26640393Sbostic 	    } else if (WIFEXITED(reason)) {
26740393Sbostic 		status = reason.w_retcode;		/* exited */
26840393Sbostic 		if (status != 0) {
26940393Sbostic 		    printf ("*** Error code %d", status);
27040393Sbostic 		}
27140393Sbostic 	    } else {
27240393Sbostic 		status = reason.w_termsig;		/* signaled */
27340393Sbostic 		printf ("*** Signal %d", status);
27440393Sbostic 	    }
27540393Sbostic 
27640393Sbostic 
27740393Sbostic 	    if (!WIFEXITED(reason) || (status != 0)) {
27840393Sbostic 		if (errCheck) {
27940393Sbostic 		    gn->made = ERROR;
28040393Sbostic 		    if (keepgoing) {
28140393Sbostic 			/*
28240393Sbostic 			 * Abort the current target, but let others
28340393Sbostic 			 * continue.
28440393Sbostic 			 */
28540393Sbostic 			printf (" (continuing)\n");
28640393Sbostic 		    }
28740393Sbostic 		} else {
28840393Sbostic 		    /*
28940393Sbostic 		     * Continue executing commands for this target.
29040393Sbostic 		     * If we return 0, this will happen...
29140393Sbostic 		     */
29240393Sbostic 		    printf (" (ignored)\n");
29340393Sbostic 		    status = 0;
29440393Sbostic 		}
29540393Sbostic 	    }
29640393Sbostic 	    break;
29740393Sbostic 	} else {
29840393Sbostic 	    Fatal ("error in wait: %d", stat);
29940393Sbostic 	    /*NOTREACHED*/
30040393Sbostic 	}
30140393Sbostic     }
30240393Sbostic 
30340393Sbostic     return (status);
30440393Sbostic }
30540393Sbostic 
30640393Sbostic /*-
30740393Sbostic  *-----------------------------------------------------------------------
30840393Sbostic  * CompatMake --
30940393Sbostic  *	Make a target.
31040393Sbostic  *
31140393Sbostic  * Results:
31240393Sbostic  *	0
31340393Sbostic  *
31440393Sbostic  * Side Effects:
31540393Sbostic  *	If an error is detected and not being ignored, the process exits.
31640393Sbostic  *
31740393Sbostic  *-----------------------------------------------------------------------
31840393Sbostic  */
31940393Sbostic static int
32040393Sbostic CompatMake (gn, pgn)
32140393Sbostic     GNode   	  *gn;	    /* The node to make */
32240393Sbostic     GNode   	  *pgn;	    /* Parent to abort if necessary */
32340393Sbostic {
32440393Sbostic     if (gn->type & OP_USE) {
32540393Sbostic 	Make_HandleUse(gn, pgn);
32640393Sbostic     } else if (gn->made == UNMADE) {
32740393Sbostic 	/*
32840393Sbostic 	 * First mark ourselves to be made, then apply whatever transformations
32940393Sbostic 	 * the suffix module thinks are necessary. Once that's done, we can
33040393Sbostic 	 * descend and make all our children. If any of them has an error
33140393Sbostic 	 * but the -k flag was given, our 'make' field will be set FALSE again.
33240393Sbostic 	 * This is our signal to not attempt to do anything but abort our
33340393Sbostic 	 * parent as well.
33440393Sbostic 	 */
33540393Sbostic 	gn->make = TRUE;
33640393Sbostic 	gn->made = BEINGMADE;
33740393Sbostic 	Suff_FindDeps (gn);
33840393Sbostic 	Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
33940393Sbostic 	if (!gn->make) {
34040393Sbostic 	    gn->made = ABORTED;
34140393Sbostic 	    pgn->make = FALSE;
34240393Sbostic 	    return (0);
34340393Sbostic 	}
34440393Sbostic 
34540393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
34640393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
34740393Sbostic 	}
34840393Sbostic 
34940393Sbostic 	/*
35040393Sbostic 	 * All the children were made ok. Now cmtime contains the modification
35140393Sbostic 	 * time of the newest child, we need to find out if we exist and when
35240393Sbostic 	 * we were modified last. The criteria for datedness are defined by the
35340393Sbostic 	 * Make_OODate function.
35440393Sbostic 	 */
35540393Sbostic 	if (DEBUG(MAKE)) {
35640393Sbostic 	    printf("Examining %s...", gn->name);
35740393Sbostic 	}
35840393Sbostic 	if (! Make_OODate(gn)) {
35940393Sbostic 	    gn->made = UPTODATE;
36040393Sbostic 	    if (DEBUG(MAKE)) {
36140393Sbostic 		printf("up-to-date.\n");
36240393Sbostic 	    }
36340393Sbostic 	    return (0);
36440393Sbostic 	} else if (DEBUG(MAKE)) {
36540393Sbostic 	    printf("out-of-date.\n");
36640393Sbostic 	}
36740393Sbostic 
36840393Sbostic 	/*
36940393Sbostic 	 * If the user is just seeing if something is out-of-date, exit now
37040393Sbostic 	 * to tell him/her "yes".
37140393Sbostic 	 */
37240393Sbostic 	if (queryFlag) {
37340393Sbostic 	    exit (-1);
37440393Sbostic 	}
37540393Sbostic 
37640393Sbostic 	/*
37740393Sbostic 	 * We need to be re-made. We also have to make sure we've got a $?
37840393Sbostic 	 * variable. To be nice, we also define the $> variable using
37940393Sbostic 	 * Make_DoAllVar().
38040393Sbostic 	 */
38140393Sbostic 	Make_DoAllVar(gn);
38240393Sbostic 
38340393Sbostic 	/*
38440393Sbostic 	 * Alter our type to tell if errors should be ignored or things
38540393Sbostic 	 * should not be printed so CompatRunCommand knows what to do.
38640393Sbostic 	 */
38740393Sbostic 	if (Targ_Ignore (gn)) {
38840393Sbostic 	    gn->type |= OP_IGNORE;
38940393Sbostic 	}
39040393Sbostic 	if (Targ_Silent (gn)) {
39140393Sbostic 	    gn->type |= OP_SILENT;
39240393Sbostic 	}
39340393Sbostic 
39440393Sbostic 	if (Job_CheckCommands (gn, Fatal)) {
39540393Sbostic 	    /*
39640393Sbostic 	     * Our commands are ok, but we still have to worry about the -t
39740393Sbostic 	     * flag...
39840393Sbostic 	     */
39940393Sbostic 	    if (!touchFlag) {
40040393Sbostic 		curTarg = gn;
40140393Sbostic 		Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
40240393Sbostic 		curTarg = NILGNODE;
40340393Sbostic 	    } else {
40440393Sbostic 		Job_Touch (gn, gn->type & OP_SILENT);
40540393Sbostic 	    }
40640393Sbostic 	} else {
40740393Sbostic 	    gn->made = ERROR;
40840393Sbostic 	}
40940393Sbostic 
41040393Sbostic 	if (gn->made != ERROR) {
41140393Sbostic 	    /*
41240393Sbostic 	     * If the node was made successfully, mark it so, update
41340393Sbostic 	     * its modification time and timestamp all its parents. Note
41440393Sbostic 	     * that for .ZEROTIME targets, the timestamping isn't done.
41540393Sbostic 	     * This is to keep its state from affecting that of its parent.
41640393Sbostic 	     */
41740393Sbostic 	    gn->made = MADE;
41840393Sbostic #ifndef RECHECK
41940393Sbostic 	    /*
42040393Sbostic 	     * We can't re-stat the thing, but we can at least take care of
42140393Sbostic 	     * rules where a target depends on a source that actually creates
42240393Sbostic 	     * the target, but only if it has changed, e.g.
42340393Sbostic 	     *
42440393Sbostic 	     * parse.h : parse.o
42540393Sbostic 	     *
42640393Sbostic 	     * parse.o : parse.y
42740393Sbostic 	     *  	yacc -d parse.y
42840393Sbostic 	     *  	cc -c y.tab.c
42940393Sbostic 	     *  	mv y.tab.o parse.o
43040393Sbostic 	     *  	cmp -s y.tab.h parse.h || mv y.tab.h parse.h
43140393Sbostic 	     *
43240393Sbostic 	     * In this case, if the definitions produced by yacc haven't
43340393Sbostic 	     * changed from before, parse.h won't have been updated and
43440393Sbostic 	     * gn->mtime will reflect the current modification time for
43540393Sbostic 	     * parse.h. This is something of a kludge, I admit, but it's a
43640393Sbostic 	     * useful one..
43740393Sbostic 	     *
43840393Sbostic 	     * XXX: People like to use a rule like
43940393Sbostic 	     *
44040393Sbostic 	     * FRC:
44140393Sbostic 	     *
44240393Sbostic 	     * To force things that depend on FRC to be made, so we have to
44340393Sbostic 	     * check for gn->children being empty as well...
44440393Sbostic 	     */
44540393Sbostic 	    if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
44640393Sbostic 		gn->mtime = now;
44740393Sbostic 	    }
44840393Sbostic #else
44940393Sbostic 	    /*
45040393Sbostic 	     * This is what Make does and it's actually a good thing, as it
45140393Sbostic 	     * allows rules like
45240393Sbostic 	     *
45340393Sbostic 	     *	cmp -s y.tab.h parse.h || cp y.tab.h parse.h
45440393Sbostic 	     *
45540393Sbostic 	     * to function as intended. Unfortunately, thanks to the stateless
45640393Sbostic 	     * nature of NFS (and the speed of this program), there are times
45740393Sbostic 	     * when the modification time of a file created on a remote
45840393Sbostic 	     * machine will not be modified before the stat() implied by
45940393Sbostic 	     * the Dir_MTime occurs, thus leading us to believe that the file
46040393Sbostic 	     * is unchanged, wreaking havoc with files that depend on this one.
46140393Sbostic 	     *
46240393Sbostic 	     * I have decided it is better to make too much than to make too
46340393Sbostic 	     * little, so this stuff is commented out unless you're sure it's
46440393Sbostic 	     * ok.
46540393Sbostic 	     * -- ardeb 1/12/88
46640393Sbostic 	     */
46740393Sbostic 	    if (noExecute || Dir_MTime(gn) == 0) {
46840393Sbostic 		gn->mtime = now;
46940393Sbostic 	    }
47040393Sbostic 	    if (DEBUG(MAKE)) {
47140393Sbostic 		printf("update time: %s\n", Targ_FmtTime(gn->mtime));
47240393Sbostic 	    }
47340393Sbostic #endif
47440393Sbostic 	    if (!(gn->type & OP_EXEC)) {
47540393Sbostic 		pgn->childMade = TRUE;
47640393Sbostic 		Make_TimeStamp(pgn, gn);
47740393Sbostic 	    }
47840393Sbostic 	} else if (keepgoing) {
47940393Sbostic 	    pgn->make = FALSE;
48040393Sbostic 	} else {
48140393Sbostic 	    printf ("\n\nStop.\n");
48240393Sbostic 	    exit (1);
48340393Sbostic 	}
48440393Sbostic     } else if (gn->made == ERROR) {
48540393Sbostic 	/*
48640393Sbostic 	 * Already had an error when making this beastie. Tell the parent
48740393Sbostic 	 * to abort.
48840393Sbostic 	 */
48940393Sbostic 	pgn->make = FALSE;
49040393Sbostic     } else {
49140393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
49240393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
49340393Sbostic 	}
49440393Sbostic 	switch(gn->made) {
49540393Sbostic 	    case BEINGMADE:
49640393Sbostic 		Error("Graph cycles through %s\n", gn->name);
49740393Sbostic 		gn->made = ERROR;
49840393Sbostic 		pgn->make = FALSE;
49940393Sbostic 		break;
50040393Sbostic 	    case MADE:
50140393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
50240393Sbostic 		    pgn->childMade = TRUE;
50340393Sbostic 		    Make_TimeStamp(pgn, gn);
50440393Sbostic 		}
50540393Sbostic 		break;
50640393Sbostic 	    case UPTODATE:
50740393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
50840393Sbostic 		    Make_TimeStamp(pgn, gn);
50940393Sbostic 		}
51040393Sbostic 		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 */
53540393Sbostic     GNode   	  *gn;	    /* 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++) {
55240393Sbostic 	meta[*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