xref: /csrg-svn/usr.bin/make/compat.c (revision 40394)
1*40394Sbostic /*
2*40394Sbostic  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3*40394Sbostic  * Copyright (c) 1988, 1989 by Adam de Boor
4*40394Sbostic  * Copyright (c) 1989 by Berkeley Softworks
5*40394Sbostic  * All rights reserved.
6*40394Sbostic  *
7*40394Sbostic  * This code is derived from software contributed to Berkeley by
8*40394Sbostic  * Adam de Boor.
9*40394Sbostic  *
10*40394Sbostic  * Redistribution and use in source and binary forms are permitted
11*40394Sbostic  * provided that the above copyright notice and this paragraph are
12*40394Sbostic  * duplicated in all such forms and that any documentation,
13*40394Sbostic  * advertising materials, and other materials related to such
14*40394Sbostic  * distribution and use acknowledge that the software was developed
15*40394Sbostic  * by the University of California, Berkeley.  The name of the
16*40394Sbostic  * University may not be used to endorse or promote products derived
17*40394Sbostic  * from this software without specific prior written permission.
18*40394Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19*40394Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20*40394Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21*40394Sbostic  */
22*40394Sbostic 
23*40394Sbostic #ifndef lint
24*40394Sbostic static char sccsid[] = "@(#)compat.c	5.2 (Berkeley) 03/11/90";
25*40394Sbostic #endif /* not lint */
26*40394Sbostic 
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     /*
14540393Sbostic      * Str_BreakString 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') {
15240393Sbostic 	if (!noWarnings) {
15340393Sbostic 	    Error("%s expands to empty string", cmd);
15440393Sbostic 	}
15540393Sbostic 	return(0);
15640393Sbostic     } else {
15740393Sbostic 	cmd = cmdStart;
15840393Sbostic     }
15940393Sbostic     Lst_Replace (cmdNode, (ClientData)cmdStart);
16040393Sbostic 
16140393Sbostic     if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
16240393Sbostic 	(void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
16340393Sbostic 	return(0);
16440393Sbostic     } else if (strcmp(cmdStart, "...") == 0) {
16540393Sbostic 	gn->type |= OP_SAVE_CMDS;
16640393Sbostic 	return(0);
16740393Sbostic     }
16840393Sbostic 
16940393Sbostic     while ((*cmd == '@') || (*cmd == '-')) {
17040393Sbostic 	if (*cmd == '@') {
17140393Sbostic 	    silent = TRUE;
17240393Sbostic 	} else {
17340393Sbostic 	    errCheck = FALSE;
17440393Sbostic 	}
17540393Sbostic 	cmd++;
17640393Sbostic     }
17740393Sbostic 
17840393Sbostic     /*
17940393Sbostic      * Search for meta characters in the command. If there are no meta
18040393Sbostic      * characters, there's no need to execute a shell to execute the
18140393Sbostic      * command.
18240393Sbostic      */
18340393Sbostic     for (cp = cmd; !meta[*cp]; cp++) {
18440393Sbostic 	continue;
18540393Sbostic     }
18640393Sbostic 
18740393Sbostic     /*
18840393Sbostic      * Print the command before echoing if we're not supposed to be quiet for
18940393Sbostic      * this one. We also print the command if -n given.
19040393Sbostic      */
19140393Sbostic     if (!silent || noExecute) {
19240393Sbostic 	printf ("%s\n", cmd);
19340393Sbostic 	fflush(stdout);
19440393Sbostic     }
19540393Sbostic 
19640393Sbostic     /*
19740393Sbostic      * If we're not supposed to execute any commands, this is as far as
19840393Sbostic      * we go...
19940393Sbostic      */
20040393Sbostic     if (noExecute) {
20140393Sbostic 	return (0);
20240393Sbostic     }
20340393Sbostic 
20440393Sbostic     if (*cp != '\0') {
20540393Sbostic 	/*
20640393Sbostic 	 * If *cp isn't the null character, we hit a "meta" character and
20740393Sbostic 	 * need to pass the command off to the shell. We give the shell the
20840393Sbostic 	 * -e flag as well as -c if it's supposed to exit when it hits an
20940393Sbostic 	 * error.
21040393Sbostic 	 */
21140393Sbostic 	static char	*shargv[4] = { "/bin/sh" };
21240393Sbostic 
21340393Sbostic 	shargv[1] = (errCheck ? "-ec" : "-c");
21440393Sbostic 	shargv[2] = cmd;
21540393Sbostic 	shargv[3] = (char *)NULL;
21640393Sbostic 	av = shargv;
21740393Sbostic 	argc = 0;
21840393Sbostic     } else {
21940393Sbostic 	/*
22040393Sbostic 	 * No meta-characters, so no need to exec a shell. Break the command
22140393Sbostic 	 * into words to form an argument vector we can execute.
22240393Sbostic 	 * Str_BreakString sticks our name in av[0], so we have to
22340393Sbostic 	 * skip over it...
22440393Sbostic 	 */
22540393Sbostic 	av = Str_BreakString(cmd, " \t", "\n", &argc);
22640393Sbostic 	av += 1;
22740393Sbostic     }
22840393Sbostic 
22940393Sbostic     /*
23040393Sbostic      * If the job has not been marked unexportable, tell the Rmt module we've
23140393Sbostic      * got something for it...local is set TRUE if the job should be run
23240393Sbostic      * locally.
23340393Sbostic      */
23440393Sbostic     if (!(gn->type & OP_NOEXPORT)) {
23540393Sbostic 	local = !Rmt_Begin(av[0], av, gn);
23640393Sbostic     } else {
23740393Sbostic 	local = TRUE;
23840393Sbostic     }
23940393Sbostic 
24040393Sbostic     /*
24140393Sbostic      * Fork and execute the single command. If the fork fails, we abort.
24240393Sbostic      */
24340393Sbostic     cpid = vfork();
24440393Sbostic     if (cpid < 0) {
24540393Sbostic 	Fatal("Could not fork");
24640393Sbostic     }
24740393Sbostic     if (cpid == 0) {
24840393Sbostic 	if (local) {
24940393Sbostic 	    execvp(av[0], av);
25040393Sbostic 	    numWritten = write (2, av[0], strlen (av[0]));
25140393Sbostic 	    numWritten = write (2, ": not found\n", sizeof(": not found"));
25240393Sbostic 	} else {
25340393Sbostic 	    Rmt_Exec(av[0], av, FALSE);
25440393Sbostic 	}
25540393Sbostic 	exit(1);
25640393Sbostic     } else if (argc != 0) {
25740393Sbostic 	/*
25840393Sbostic 	 * If there's a vector that needs freeing (the command was executed
25940393Sbostic 	 * directly), do so now, being sure to back up the argument vector
26040393Sbostic 	 * to where it started...
26140393Sbostic 	 */
26240393Sbostic 	av -= 1;
26340393Sbostic 	Str_FreeVec (argc, av);
26440393Sbostic     }
26540393Sbostic 
26640393Sbostic     /*
26740393Sbostic      * The child is off and running. Now all we can do is wait...
26840393Sbostic      */
26940393Sbostic     while (1) {
27040393Sbostic 	int 	  id;
27140393Sbostic 
27240393Sbostic 	if (!local) {
27340393Sbostic 	    id = Rmt_LastID(cpid);
27440393Sbostic 	}
27540393Sbostic 
27640393Sbostic 	while ((stat = wait(&reason)) != cpid) {
27740393Sbostic 	    if (stat == -1 && errno != EINTR) {
27840393Sbostic 		break;
27940393Sbostic 	    }
28040393Sbostic 	}
28140393Sbostic 
28240393Sbostic 	if (!local) {
28340393Sbostic 	    Rmt_Done(id);
28440393Sbostic 	}
28540393Sbostic 
28640393Sbostic 
28740393Sbostic 	if (stat > -1) {
28840393Sbostic 	    if (WIFSTOPPED(reason)) {
28940393Sbostic 		status = reason.w_stopval;		/* stopped */
29040393Sbostic 	    } else if (WIFEXITED(reason)) {
29140393Sbostic 		status = reason.w_retcode;		/* exited */
29240393Sbostic 		if (status != 0) {
29340393Sbostic 		    printf ("*** Error code %d", status);
29440393Sbostic 		}
29540393Sbostic 	    } else {
29640393Sbostic 		status = reason.w_termsig;		/* signaled */
29740393Sbostic 		printf ("*** Signal %d", status);
29840393Sbostic 	    }
29940393Sbostic 
30040393Sbostic 
30140393Sbostic 	    if (!WIFEXITED(reason) || (status != 0)) {
30240393Sbostic 		if (errCheck) {
30340393Sbostic 		    gn->made = ERROR;
30440393Sbostic 		    if (keepgoing) {
30540393Sbostic 			/*
30640393Sbostic 			 * Abort the current target, but let others
30740393Sbostic 			 * continue.
30840393Sbostic 			 */
30940393Sbostic 			printf (" (continuing)\n");
31040393Sbostic 		    }
31140393Sbostic 		} else {
31240393Sbostic 		    /*
31340393Sbostic 		     * Continue executing commands for this target.
31440393Sbostic 		     * If we return 0, this will happen...
31540393Sbostic 		     */
31640393Sbostic 		    printf (" (ignored)\n");
31740393Sbostic 		    status = 0;
31840393Sbostic 		}
31940393Sbostic 	    }
32040393Sbostic 	    break;
32140393Sbostic 	} else {
32240393Sbostic 	    Fatal ("error in wait: %d", stat);
32340393Sbostic 	    /*NOTREACHED*/
32440393Sbostic 	}
32540393Sbostic     }
32640393Sbostic 
32740393Sbostic     return (status);
32840393Sbostic }
32940393Sbostic 
33040393Sbostic /*-
33140393Sbostic  *-----------------------------------------------------------------------
33240393Sbostic  * CompatMake --
33340393Sbostic  *	Make a target.
33440393Sbostic  *
33540393Sbostic  * Results:
33640393Sbostic  *	0
33740393Sbostic  *
33840393Sbostic  * Side Effects:
33940393Sbostic  *	If an error is detected and not being ignored, the process exits.
34040393Sbostic  *
34140393Sbostic  *-----------------------------------------------------------------------
34240393Sbostic  */
34340393Sbostic static int
34440393Sbostic CompatMake (gn, pgn)
34540393Sbostic     GNode   	  *gn;	    /* The node to make */
34640393Sbostic     GNode   	  *pgn;	    /* Parent to abort if necessary */
34740393Sbostic {
34840393Sbostic     if (gn->type & OP_USE) {
34940393Sbostic 	Make_HandleUse(gn, pgn);
35040393Sbostic     } else if (gn->made == UNMADE) {
35140393Sbostic 	/*
35240393Sbostic 	 * First mark ourselves to be made, then apply whatever transformations
35340393Sbostic 	 * the suffix module thinks are necessary. Once that's done, we can
35440393Sbostic 	 * descend and make all our children. If any of them has an error
35540393Sbostic 	 * but the -k flag was given, our 'make' field will be set FALSE again.
35640393Sbostic 	 * This is our signal to not attempt to do anything but abort our
35740393Sbostic 	 * parent as well.
35840393Sbostic 	 */
35940393Sbostic 	gn->make = TRUE;
36040393Sbostic 	gn->made = BEINGMADE;
36140393Sbostic 	Suff_FindDeps (gn);
36240393Sbostic 	Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
36340393Sbostic 	if (!gn->make) {
36440393Sbostic 	    gn->made = ABORTED;
36540393Sbostic 	    pgn->make = FALSE;
36640393Sbostic 	    return (0);
36740393Sbostic 	}
36840393Sbostic 
36940393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
37040393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
37140393Sbostic 	}
37240393Sbostic 
37340393Sbostic 	/*
37440393Sbostic 	 * All the children were made ok. Now cmtime contains the modification
37540393Sbostic 	 * time of the newest child, we need to find out if we exist and when
37640393Sbostic 	 * we were modified last. The criteria for datedness are defined by the
37740393Sbostic 	 * Make_OODate function.
37840393Sbostic 	 */
37940393Sbostic 	if (DEBUG(MAKE)) {
38040393Sbostic 	    printf("Examining %s...", gn->name);
38140393Sbostic 	}
38240393Sbostic 	if (! Make_OODate(gn)) {
38340393Sbostic 	    gn->made = UPTODATE;
38440393Sbostic 	    if (DEBUG(MAKE)) {
38540393Sbostic 		printf("up-to-date.\n");
38640393Sbostic 	    }
38740393Sbostic 	    return (0);
38840393Sbostic 	} else if (DEBUG(MAKE)) {
38940393Sbostic 	    printf("out-of-date.\n");
39040393Sbostic 	}
39140393Sbostic 
39240393Sbostic 	/*
39340393Sbostic 	 * If the user is just seeing if something is out-of-date, exit now
39440393Sbostic 	 * to tell him/her "yes".
39540393Sbostic 	 */
39640393Sbostic 	if (queryFlag) {
39740393Sbostic 	    exit (-1);
39840393Sbostic 	}
39940393Sbostic 
40040393Sbostic 	/*
40140393Sbostic 	 * We need to be re-made. We also have to make sure we've got a $?
40240393Sbostic 	 * variable. To be nice, we also define the $> variable using
40340393Sbostic 	 * Make_DoAllVar().
40440393Sbostic 	 */
40540393Sbostic 	Make_DoAllVar(gn);
40640393Sbostic 
40740393Sbostic 	/*
40840393Sbostic 	 * Alter our type to tell if errors should be ignored or things
40940393Sbostic 	 * should not be printed so CompatRunCommand knows what to do.
41040393Sbostic 	 */
41140393Sbostic 	if (Targ_Ignore (gn)) {
41240393Sbostic 	    gn->type |= OP_IGNORE;
41340393Sbostic 	}
41440393Sbostic 	if (Targ_Silent (gn)) {
41540393Sbostic 	    gn->type |= OP_SILENT;
41640393Sbostic 	}
41740393Sbostic 
41840393Sbostic 	if (Job_CheckCommands (gn, Fatal)) {
41940393Sbostic 	    /*
42040393Sbostic 	     * Our commands are ok, but we still have to worry about the -t
42140393Sbostic 	     * flag...
42240393Sbostic 	     */
42340393Sbostic 	    if (!touchFlag) {
42440393Sbostic 		curTarg = gn;
42540393Sbostic 		Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
42640393Sbostic 		curTarg = NILGNODE;
42740393Sbostic 	    } else {
42840393Sbostic 		Job_Touch (gn, gn->type & OP_SILENT);
42940393Sbostic 	    }
43040393Sbostic 	} else {
43140393Sbostic 	    gn->made = ERROR;
43240393Sbostic 	}
43340393Sbostic 
43440393Sbostic 	if (gn->made != ERROR) {
43540393Sbostic 	    /*
43640393Sbostic 	     * If the node was made successfully, mark it so, update
43740393Sbostic 	     * its modification time and timestamp all its parents. Note
43840393Sbostic 	     * that for .ZEROTIME targets, the timestamping isn't done.
43940393Sbostic 	     * This is to keep its state from affecting that of its parent.
44040393Sbostic 	     */
44140393Sbostic 	    gn->made = MADE;
44240393Sbostic #ifndef RECHECK
44340393Sbostic 	    /*
44440393Sbostic 	     * We can't re-stat the thing, but we can at least take care of
44540393Sbostic 	     * rules where a target depends on a source that actually creates
44640393Sbostic 	     * the target, but only if it has changed, e.g.
44740393Sbostic 	     *
44840393Sbostic 	     * parse.h : parse.o
44940393Sbostic 	     *
45040393Sbostic 	     * parse.o : parse.y
45140393Sbostic 	     *  	yacc -d parse.y
45240393Sbostic 	     *  	cc -c y.tab.c
45340393Sbostic 	     *  	mv y.tab.o parse.o
45440393Sbostic 	     *  	cmp -s y.tab.h parse.h || mv y.tab.h parse.h
45540393Sbostic 	     *
45640393Sbostic 	     * In this case, if the definitions produced by yacc haven't
45740393Sbostic 	     * changed from before, parse.h won't have been updated and
45840393Sbostic 	     * gn->mtime will reflect the current modification time for
45940393Sbostic 	     * parse.h. This is something of a kludge, I admit, but it's a
46040393Sbostic 	     * useful one..
46140393Sbostic 	     *
46240393Sbostic 	     * XXX: People like to use a rule like
46340393Sbostic 	     *
46440393Sbostic 	     * FRC:
46540393Sbostic 	     *
46640393Sbostic 	     * To force things that depend on FRC to be made, so we have to
46740393Sbostic 	     * check for gn->children being empty as well...
46840393Sbostic 	     */
46940393Sbostic 	    if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
47040393Sbostic 		gn->mtime = now;
47140393Sbostic 	    }
47240393Sbostic #else
47340393Sbostic 	    /*
47440393Sbostic 	     * This is what Make does and it's actually a good thing, as it
47540393Sbostic 	     * allows rules like
47640393Sbostic 	     *
47740393Sbostic 	     *	cmp -s y.tab.h parse.h || cp y.tab.h parse.h
47840393Sbostic 	     *
47940393Sbostic 	     * to function as intended. Unfortunately, thanks to the stateless
48040393Sbostic 	     * nature of NFS (and the speed of this program), there are times
48140393Sbostic 	     * when the modification time of a file created on a remote
48240393Sbostic 	     * machine will not be modified before the stat() implied by
48340393Sbostic 	     * the Dir_MTime occurs, thus leading us to believe that the file
48440393Sbostic 	     * is unchanged, wreaking havoc with files that depend on this one.
48540393Sbostic 	     *
48640393Sbostic 	     * I have decided it is better to make too much than to make too
48740393Sbostic 	     * little, so this stuff is commented out unless you're sure it's
48840393Sbostic 	     * ok.
48940393Sbostic 	     * -- ardeb 1/12/88
49040393Sbostic 	     */
49140393Sbostic 	    if (noExecute || Dir_MTime(gn) == 0) {
49240393Sbostic 		gn->mtime = now;
49340393Sbostic 	    }
49440393Sbostic 	    if (DEBUG(MAKE)) {
49540393Sbostic 		printf("update time: %s\n", Targ_FmtTime(gn->mtime));
49640393Sbostic 	    }
49740393Sbostic #endif
49840393Sbostic 	    if (!(gn->type & OP_EXEC)) {
49940393Sbostic 		pgn->childMade = TRUE;
50040393Sbostic 		Make_TimeStamp(pgn, gn);
50140393Sbostic 	    }
50240393Sbostic 	} else if (keepgoing) {
50340393Sbostic 	    pgn->make = FALSE;
50440393Sbostic 	} else {
50540393Sbostic 	    printf ("\n\nStop.\n");
50640393Sbostic 	    exit (1);
50740393Sbostic 	}
50840393Sbostic     } else if (gn->made == ERROR) {
50940393Sbostic 	/*
51040393Sbostic 	 * Already had an error when making this beastie. Tell the parent
51140393Sbostic 	 * to abort.
51240393Sbostic 	 */
51340393Sbostic 	pgn->make = FALSE;
51440393Sbostic     } else {
51540393Sbostic 	if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
51640393Sbostic 	    Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
51740393Sbostic 	}
51840393Sbostic 	switch(gn->made) {
51940393Sbostic 	    case BEINGMADE:
52040393Sbostic 		Error("Graph cycles through %s\n", gn->name);
52140393Sbostic 		gn->made = ERROR;
52240393Sbostic 		pgn->make = FALSE;
52340393Sbostic 		break;
52440393Sbostic 	    case MADE:
52540393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
52640393Sbostic 		    pgn->childMade = TRUE;
52740393Sbostic 		    Make_TimeStamp(pgn, gn);
52840393Sbostic 		}
52940393Sbostic 		break;
53040393Sbostic 	    case UPTODATE:
53140393Sbostic 		if ((gn->type & OP_EXEC) == 0) {
53240393Sbostic 		    Make_TimeStamp(pgn, gn);
53340393Sbostic 		}
53440393Sbostic 		break;
53540393Sbostic 	}
53640393Sbostic     }
53740393Sbostic 
53840393Sbostic     return (0);
53940393Sbostic }
54040393Sbostic 
54140393Sbostic /*-
54240393Sbostic  *-----------------------------------------------------------------------
54340393Sbostic  * Compat_Run --
54440393Sbostic  *	Initialize this mode and start making.
54540393Sbostic  *
54640393Sbostic  * Results:
54740393Sbostic  *	None.
54840393Sbostic  *
54940393Sbostic  * Side Effects:
55040393Sbostic  *	Guess what?
55140393Sbostic  *
55240393Sbostic  *-----------------------------------------------------------------------
55340393Sbostic  */
55440393Sbostic void
55540393Sbostic Compat_Run(targs)
55640393Sbostic     Lst	    	  targs;    /* List of target nodes to re-create */
55740393Sbostic {
55840393Sbostic     char    	  *cp;	    /* Pointer to string of shell meta-characters */
55940393Sbostic     GNode   	  *gn;	    /* Current root target */
56040393Sbostic     int	    	  errors;   /* Number of targets not remade due to errors */
56140393Sbostic 
56240393Sbostic     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
56340393Sbostic 	signal(SIGINT, CompatInterrupt);
56440393Sbostic     }
56540393Sbostic     if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
56640393Sbostic 	signal(SIGTERM, CompatInterrupt);
56740393Sbostic     }
56840393Sbostic     if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
56940393Sbostic 	signal(SIGHUP, CompatInterrupt);
57040393Sbostic     }
57140393Sbostic     if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
57240393Sbostic 	signal(SIGQUIT, CompatInterrupt);
57340393Sbostic     }
57440393Sbostic 
57540393Sbostic     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
57640393Sbostic 	meta[*cp] = 1;
57740393Sbostic     }
57840393Sbostic     /*
57940393Sbostic      * The null character serves as a sentinel in the string.
58040393Sbostic      */
58140393Sbostic     meta[0] = 1;
58240393Sbostic 
58340393Sbostic     ENDNode = Targ_FindNode(".END", TARG_CREATE);
58440393Sbostic     /*
58540393Sbostic      * If the user has defined a .BEGIN target, execute the commands attached
58640393Sbostic      * to it.
58740393Sbostic      */
58840393Sbostic     if (!queryFlag) {
58940393Sbostic 	gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
59040393Sbostic 	if (gn != NILGNODE) {
59140393Sbostic 	    Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
59240393Sbostic 	}
59340393Sbostic     }
59440393Sbostic 
59540393Sbostic     /*
59640393Sbostic      * For each entry in the list of targets to create, call CompatMake on
59740393Sbostic      * it to create the thing. CompatMake will leave the 'made' field of gn
59840393Sbostic      * in one of several states:
59940393Sbostic      *	    UPTODATE	    gn was already up-to-date
60040393Sbostic      *	    MADE  	    gn was recreated successfully
60140393Sbostic      *	    ERROR 	    An error occurred while gn was being created
60240393Sbostic      *	    ABORTED	    gn was not remade because one of its inferiors
60340393Sbostic      *	    	  	    could not be made due to errors.
60440393Sbostic      */
60540393Sbostic     errors = 0;
60640393Sbostic     while (!Lst_IsEmpty (targs)) {
60740393Sbostic 	gn = (GNode *) Lst_DeQueue (targs);
60840393Sbostic 	CompatMake (gn, gn);
60940393Sbostic 
61040393Sbostic 	if (gn->made == UPTODATE) {
61140393Sbostic 	    printf ("`%s' is up to date.\n", gn->name);
61240393Sbostic 	} else if (gn->made == ABORTED) {
61340393Sbostic 	    printf ("`%s' not remade because of errors.\n", gn->name);
61440393Sbostic 	    errors += 1;
61540393Sbostic 	}
61640393Sbostic     }
61740393Sbostic 
61840393Sbostic     /*
61940393Sbostic      * If the user has defined a .END target, run its commands.
62040393Sbostic      */
62140393Sbostic     if (errors == 0) {
62240393Sbostic 	Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
62340393Sbostic     }
62440393Sbostic }
625