140394Sbostic /* 262092Sbostic * Copyright (c) 1988, 1989, 1990, 1993 362092Sbostic * The Regents of the University of California. All rights reserved. 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*66394Schristos static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 03/19/94"; 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> 3160304Sbostic #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 { 7960304Sbostic struct stat sb; 8040393Sbostic GNode *gn; 8140393Sbostic 8240393Sbostic if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) { 8340393Sbostic char *file = Var_Value (TARGET, curTarg); 8440393Sbostic 8560304Sbostic if (!stat(file, &sb) && S_ISREG(sb.st_mode) && 8660304Sbostic 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 137*66394Schristos /* 138*66394Schristos * Avoid clobbered variable warnings by forcing the compiler 139*66394Schristos * to ``unregister'' variables 140*66394Schristos */ 141*66394Schristos #if __GNUC__ 142*66394Schristos (void) &av; 143*66394Schristos (void) &errCheck; 144*66394Schristos #endif 145*66394Schristos 14640393Sbostic silent = gn->type & OP_SILENT; 14740393Sbostic errCheck = !(gn->type & OP_IGNORE); 14840393Sbostic 14940393Sbostic cmdNode = Lst_Member (gn->commands, (ClientData)cmd); 15060285Sbostic cmdStart = Var_Subst (NULL, cmd, gn, FALSE); 15140393Sbostic 15240393Sbostic /* 15340527Sbostic * brk_string will return an argv with a NULL in av[1], thus causing 15440393Sbostic * execvp to choke and die horribly. Besides, how can we execute a null 15540393Sbostic * command? In any case, we warn the user that the command expanded to 15640393Sbostic * nothing (is this the right thing to do?). 15740393Sbostic */ 15840393Sbostic 15940393Sbostic if (*cmdStart == '\0') { 16040539Sbostic Error("%s expands to empty string", cmd); 16140393Sbostic return(0); 16240393Sbostic } else { 16340393Sbostic cmd = cmdStart; 16440393Sbostic } 16540393Sbostic Lst_Replace (cmdNode, (ClientData)cmdStart); 16640393Sbostic 16740393Sbostic if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { 16840393Sbostic (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart); 16940393Sbostic return(0); 17040393Sbostic } else if (strcmp(cmdStart, "...") == 0) { 17140393Sbostic gn->type |= OP_SAVE_CMDS; 17240393Sbostic return(0); 17340393Sbostic } 17440393Sbostic 17540393Sbostic while ((*cmd == '@') || (*cmd == '-')) { 17640393Sbostic if (*cmd == '@') { 17740393Sbostic silent = TRUE; 17840393Sbostic } else { 17940393Sbostic errCheck = FALSE; 18040393Sbostic } 18140393Sbostic cmd++; 18240393Sbostic } 183*66394Schristos 184*66394Schristos while (isspace((unsigned char)*cmd)) 185*66394Schristos cmd++; 18640393Sbostic 18740393Sbostic /* 18840393Sbostic * Search for meta characters in the command. If there are no meta 18940393Sbostic * characters, there's no need to execute a shell to execute the 19040393Sbostic * command. 19140393Sbostic */ 19260285Sbostic for (cp = cmd; !meta[(unsigned char)*cp]; cp++) { 19340393Sbostic continue; 19440393Sbostic } 19540393Sbostic 19640393Sbostic /* 19740393Sbostic * Print the command before echoing if we're not supposed to be quiet for 19840393Sbostic * this one. We also print the command if -n given. 19940393Sbostic */ 20040393Sbostic if (!silent || noExecute) { 20140393Sbostic printf ("%s\n", cmd); 20240393Sbostic fflush(stdout); 20340393Sbostic } 20440393Sbostic 20540393Sbostic /* 20640393Sbostic * If we're not supposed to execute any commands, this is as far as 20740393Sbostic * we go... 20840393Sbostic */ 20940393Sbostic if (noExecute) { 21040393Sbostic return (0); 21140393Sbostic } 21240393Sbostic 21340393Sbostic if (*cp != '\0') { 21440393Sbostic /* 21540393Sbostic * If *cp isn't the null character, we hit a "meta" character and 21640393Sbostic * need to pass the command off to the shell. We give the shell the 21740393Sbostic * -e flag as well as -c if it's supposed to exit when it hits an 21840393Sbostic * error. 21940393Sbostic */ 22040393Sbostic static char *shargv[4] = { "/bin/sh" }; 22140393Sbostic 22240393Sbostic shargv[1] = (errCheck ? "-ec" : "-c"); 22340393Sbostic shargv[2] = cmd; 22440393Sbostic shargv[3] = (char *)NULL; 22540393Sbostic av = shargv; 22640393Sbostic argc = 0; 22740393Sbostic } else { 22840393Sbostic /* 22940393Sbostic * No meta-characters, so no need to exec a shell. Break the command 23040393Sbostic * into words to form an argument vector we can execute. 23140527Sbostic * brk_string sticks our name in av[0], so we have to 23240393Sbostic * skip over it... 23340393Sbostic */ 23440527Sbostic av = brk_string(cmd, &argc); 23540393Sbostic av += 1; 23640393Sbostic } 23740393Sbostic 23840438Sbostic local = TRUE; 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); 25060285Sbostic (void) write (2, av[0], strlen (av[0])); 25160285Sbostic (void) write (2, ": not found\n", sizeof(": not found")); 25240393Sbostic } else { 25340438Sbostic (void)execv(av[0], av); 25440393Sbostic } 25540393Sbostic exit(1); 25640393Sbostic } 25740393Sbostic 25840393Sbostic /* 25940393Sbostic * The child is off and running. Now all we can do is wait... 26040393Sbostic */ 26140393Sbostic while (1) { 26240393Sbostic int id; 26340393Sbostic 26440393Sbostic if (!local) { 26540438Sbostic id = 0; 26640393Sbostic } 26740393Sbostic 26846837Sbostic while ((stat = wait((int *)&reason)) != cpid) { 26940393Sbostic if (stat == -1 && errno != EINTR) { 27040393Sbostic break; 27140393Sbostic } 27240393Sbostic } 27340393Sbostic 27440393Sbostic if (stat > -1) { 27540393Sbostic if (WIFSTOPPED(reason)) { 27640393Sbostic status = reason.w_stopval; /* stopped */ 27740393Sbostic } else if (WIFEXITED(reason)) { 27840393Sbostic status = reason.w_retcode; /* exited */ 27940393Sbostic if (status != 0) { 28040393Sbostic printf ("*** Error code %d", status); 28140393Sbostic } 28240393Sbostic } else { 28340393Sbostic status = reason.w_termsig; /* signaled */ 28440393Sbostic printf ("*** Signal %d", status); 28540393Sbostic } 28640393Sbostic 28740393Sbostic 28840393Sbostic if (!WIFEXITED(reason) || (status != 0)) { 28940393Sbostic if (errCheck) { 29040393Sbostic gn->made = ERROR; 29140393Sbostic if (keepgoing) { 29240393Sbostic /* 29340393Sbostic * Abort the current target, but let others 29440393Sbostic * continue. 29540393Sbostic */ 29640393Sbostic printf (" (continuing)\n"); 29740393Sbostic } 29840393Sbostic } else { 29940393Sbostic /* 30040393Sbostic * Continue executing commands for this target. 30140393Sbostic * If we return 0, this will happen... 30240393Sbostic */ 30340393Sbostic printf (" (ignored)\n"); 30440393Sbostic status = 0; 30540393Sbostic } 30640393Sbostic } 30740393Sbostic break; 30840393Sbostic } else { 30940393Sbostic Fatal ("error in wait: %d", stat); 31040393Sbostic /*NOTREACHED*/ 31140393Sbostic } 31240393Sbostic } 31340393Sbostic 31440393Sbostic return (status); 31540393Sbostic } 31640393Sbostic 31740393Sbostic /*- 31840393Sbostic *----------------------------------------------------------------------- 31940393Sbostic * CompatMake -- 32040393Sbostic * Make a target. 32140393Sbostic * 32240393Sbostic * Results: 32340393Sbostic * 0 32440393Sbostic * 32540393Sbostic * Side Effects: 32640393Sbostic * If an error is detected and not being ignored, the process exits. 32740393Sbostic * 32840393Sbostic *----------------------------------------------------------------------- 32940393Sbostic */ 33040393Sbostic static int 33140393Sbostic CompatMake (gn, pgn) 33240393Sbostic GNode *gn; /* The node to make */ 33340393Sbostic GNode *pgn; /* Parent to abort if necessary */ 33440393Sbostic { 33540393Sbostic if (gn->type & OP_USE) { 33640393Sbostic Make_HandleUse(gn, pgn); 33740393Sbostic } else if (gn->made == UNMADE) { 33840393Sbostic /* 33940393Sbostic * First mark ourselves to be made, then apply whatever transformations 34040393Sbostic * the suffix module thinks are necessary. Once that's done, we can 34140393Sbostic * descend and make all our children. If any of them has an error 34240393Sbostic * but the -k flag was given, our 'make' field will be set FALSE again. 34340393Sbostic * This is our signal to not attempt to do anything but abort our 34440393Sbostic * parent as well. 34540393Sbostic */ 34640393Sbostic gn->make = TRUE; 34740393Sbostic gn->made = BEINGMADE; 34840393Sbostic Suff_FindDeps (gn); 34940393Sbostic Lst_ForEach (gn->children, CompatMake, (ClientData)gn); 35040393Sbostic if (!gn->make) { 35140393Sbostic gn->made = ABORTED; 35240393Sbostic pgn->make = FALSE; 35340393Sbostic return (0); 35440393Sbostic } 35540393Sbostic 35640393Sbostic if (Lst_Member (gn->iParents, pgn) != NILLNODE) { 35740393Sbostic Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn); 35840393Sbostic } 35940393Sbostic 36040393Sbostic /* 36140393Sbostic * All the children were made ok. Now cmtime contains the modification 36240393Sbostic * time of the newest child, we need to find out if we exist and when 36340393Sbostic * we were modified last. The criteria for datedness are defined by the 36440393Sbostic * Make_OODate function. 36540393Sbostic */ 36640393Sbostic if (DEBUG(MAKE)) { 36740393Sbostic printf("Examining %s...", gn->name); 36840393Sbostic } 36940393Sbostic if (! Make_OODate(gn)) { 37040393Sbostic gn->made = UPTODATE; 37140393Sbostic if (DEBUG(MAKE)) { 37240393Sbostic printf("up-to-date.\n"); 37340393Sbostic } 37440393Sbostic return (0); 37540393Sbostic } else if (DEBUG(MAKE)) { 37640393Sbostic printf("out-of-date.\n"); 37740393Sbostic } 37840393Sbostic 37940393Sbostic /* 38040393Sbostic * If the user is just seeing if something is out-of-date, exit now 38140393Sbostic * to tell him/her "yes". 38240393Sbostic */ 38340393Sbostic if (queryFlag) { 38440393Sbostic exit (-1); 38540393Sbostic } 38640393Sbostic 38740393Sbostic /* 38840393Sbostic * We need to be re-made. We also have to make sure we've got a $? 38940393Sbostic * variable. To be nice, we also define the $> variable using 39040393Sbostic * Make_DoAllVar(). 39140393Sbostic */ 39240393Sbostic Make_DoAllVar(gn); 39340393Sbostic 39440393Sbostic /* 39540393Sbostic * Alter our type to tell if errors should be ignored or things 39640393Sbostic * should not be printed so CompatRunCommand knows what to do. 39740393Sbostic */ 39840393Sbostic if (Targ_Ignore (gn)) { 39940393Sbostic gn->type |= OP_IGNORE; 40040393Sbostic } 40140393Sbostic if (Targ_Silent (gn)) { 40240393Sbostic gn->type |= OP_SILENT; 40340393Sbostic } 40440393Sbostic 40540393Sbostic if (Job_CheckCommands (gn, Fatal)) { 40640393Sbostic /* 40740393Sbostic * Our commands are ok, but we still have to worry about the -t 40840393Sbostic * flag... 40940393Sbostic */ 41040393Sbostic if (!touchFlag) { 41140393Sbostic curTarg = gn; 41240393Sbostic Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn); 41340393Sbostic curTarg = NILGNODE; 41440393Sbostic } else { 41540393Sbostic Job_Touch (gn, gn->type & OP_SILENT); 41640393Sbostic } 41740393Sbostic } else { 41840393Sbostic gn->made = ERROR; 41940393Sbostic } 42040393Sbostic 42140393Sbostic if (gn->made != ERROR) { 42240393Sbostic /* 42340393Sbostic * If the node was made successfully, mark it so, update 42440393Sbostic * its modification time and timestamp all its parents. Note 42540393Sbostic * that for .ZEROTIME targets, the timestamping isn't done. 42640393Sbostic * This is to keep its state from affecting that of its parent. 42740393Sbostic */ 42840393Sbostic gn->made = MADE; 42940393Sbostic #ifndef RECHECK 43040393Sbostic /* 43140393Sbostic * We can't re-stat the thing, but we can at least take care of 43240393Sbostic * rules where a target depends on a source that actually creates 43340393Sbostic * the target, but only if it has changed, e.g. 43440393Sbostic * 43540393Sbostic * parse.h : parse.o 43640393Sbostic * 43740393Sbostic * parse.o : parse.y 43840393Sbostic * yacc -d parse.y 43940393Sbostic * cc -c y.tab.c 44040393Sbostic * mv y.tab.o parse.o 44140393Sbostic * cmp -s y.tab.h parse.h || mv y.tab.h parse.h 44240393Sbostic * 44340393Sbostic * In this case, if the definitions produced by yacc haven't 44440393Sbostic * changed from before, parse.h won't have been updated and 44540393Sbostic * gn->mtime will reflect the current modification time for 44640393Sbostic * parse.h. This is something of a kludge, I admit, but it's a 44740393Sbostic * useful one.. 44840393Sbostic * 44940393Sbostic * XXX: People like to use a rule like 45040393Sbostic * 45140393Sbostic * FRC: 45240393Sbostic * 45340393Sbostic * To force things that depend on FRC to be made, so we have to 45440393Sbostic * check for gn->children being empty as well... 45540393Sbostic */ 45640393Sbostic if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) { 45740393Sbostic gn->mtime = now; 45840393Sbostic } 45940393Sbostic #else 46040393Sbostic /* 46140393Sbostic * This is what Make does and it's actually a good thing, as it 46240393Sbostic * allows rules like 46340393Sbostic * 46440393Sbostic * cmp -s y.tab.h parse.h || cp y.tab.h parse.h 46540393Sbostic * 46640393Sbostic * to function as intended. Unfortunately, thanks to the stateless 46740393Sbostic * nature of NFS (and the speed of this program), there are times 46840393Sbostic * when the modification time of a file created on a remote 46940393Sbostic * machine will not be modified before the stat() implied by 47040393Sbostic * the Dir_MTime occurs, thus leading us to believe that the file 47140393Sbostic * is unchanged, wreaking havoc with files that depend on this one. 47240393Sbostic * 47340393Sbostic * I have decided it is better to make too much than to make too 47440393Sbostic * little, so this stuff is commented out unless you're sure it's 47540393Sbostic * ok. 47640393Sbostic * -- ardeb 1/12/88 47740393Sbostic */ 47840393Sbostic if (noExecute || Dir_MTime(gn) == 0) { 47940393Sbostic gn->mtime = now; 48040393Sbostic } 48160285Sbostic if (gn->cmtime > gn->mtime) 48260285Sbostic gn->mtime = gn->cmtime; 48340393Sbostic if (DEBUG(MAKE)) { 48440393Sbostic printf("update time: %s\n", Targ_FmtTime(gn->mtime)); 48540393Sbostic } 48640393Sbostic #endif 48740393Sbostic if (!(gn->type & OP_EXEC)) { 48840393Sbostic pgn->childMade = TRUE; 48940393Sbostic Make_TimeStamp(pgn, gn); 49040393Sbostic } 49140393Sbostic } else if (keepgoing) { 49240393Sbostic pgn->make = FALSE; 49340393Sbostic } else { 49440393Sbostic printf ("\n\nStop.\n"); 49540393Sbostic exit (1); 49640393Sbostic } 49740393Sbostic } else if (gn->made == ERROR) { 49840393Sbostic /* 49940393Sbostic * Already had an error when making this beastie. Tell the parent 50040393Sbostic * to abort. 50140393Sbostic */ 50240393Sbostic pgn->make = FALSE; 50340393Sbostic } else { 50440393Sbostic if (Lst_Member (gn->iParents, pgn) != NILLNODE) { 50540393Sbostic Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn); 50640393Sbostic } 50740393Sbostic switch(gn->made) { 50840393Sbostic case BEINGMADE: 50940393Sbostic Error("Graph cycles through %s\n", gn->name); 51040393Sbostic gn->made = ERROR; 51140393Sbostic pgn->make = FALSE; 51240393Sbostic break; 51340393Sbostic case MADE: 51440393Sbostic if ((gn->type & OP_EXEC) == 0) { 51540393Sbostic pgn->childMade = TRUE; 51640393Sbostic Make_TimeStamp(pgn, gn); 51740393Sbostic } 51840393Sbostic break; 51940393Sbostic case UPTODATE: 52040393Sbostic if ((gn->type & OP_EXEC) == 0) { 52140393Sbostic Make_TimeStamp(pgn, gn); 52240393Sbostic } 52340393Sbostic break; 52460285Sbostic default: 52560285Sbostic break; 52640393Sbostic } 52740393Sbostic } 52840393Sbostic 52940393Sbostic return (0); 53040393Sbostic } 53140393Sbostic 53240393Sbostic /*- 53340393Sbostic *----------------------------------------------------------------------- 53440393Sbostic * Compat_Run -- 53540393Sbostic * Initialize this mode and start making. 53640393Sbostic * 53740393Sbostic * Results: 53840393Sbostic * None. 53940393Sbostic * 54040393Sbostic * Side Effects: 54140393Sbostic * Guess what? 54240393Sbostic * 54340393Sbostic *----------------------------------------------------------------------- 54440393Sbostic */ 54540393Sbostic void 54640393Sbostic Compat_Run(targs) 54740393Sbostic Lst targs; /* List of target nodes to re-create */ 54840393Sbostic { 54940393Sbostic char *cp; /* Pointer to string of shell meta-characters */ 55060285Sbostic GNode *gn = NULL;/* Current root target */ 55140393Sbostic int errors; /* Number of targets not remade due to errors */ 55240393Sbostic 55340393Sbostic if (signal(SIGINT, SIG_IGN) != SIG_IGN) { 55440393Sbostic signal(SIGINT, CompatInterrupt); 55540393Sbostic } 55640393Sbostic if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { 55740393Sbostic signal(SIGTERM, CompatInterrupt); 55840393Sbostic } 55940393Sbostic if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { 56040393Sbostic signal(SIGHUP, CompatInterrupt); 56140393Sbostic } 56240393Sbostic if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) { 56340393Sbostic signal(SIGQUIT, CompatInterrupt); 56440393Sbostic } 56540393Sbostic 56640393Sbostic for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) { 56760285Sbostic meta[(unsigned char) *cp] = 1; 56840393Sbostic } 56940393Sbostic /* 57040393Sbostic * The null character serves as a sentinel in the string. 57140393Sbostic */ 57240393Sbostic meta[0] = 1; 57340393Sbostic 57440393Sbostic ENDNode = Targ_FindNode(".END", TARG_CREATE); 57540393Sbostic /* 57640393Sbostic * If the user has defined a .BEGIN target, execute the commands attached 57740393Sbostic * to it. 57840393Sbostic */ 57940393Sbostic if (!queryFlag) { 58040393Sbostic gn = Targ_FindNode(".BEGIN", TARG_NOCREATE); 58140393Sbostic if (gn != NILGNODE) { 58240393Sbostic Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn); 58340393Sbostic } 58440393Sbostic } 58540393Sbostic 58640393Sbostic /* 58740393Sbostic * For each entry in the list of targets to create, call CompatMake on 58840393Sbostic * it to create the thing. CompatMake will leave the 'made' field of gn 58940393Sbostic * in one of several states: 59040393Sbostic * UPTODATE gn was already up-to-date 59140393Sbostic * MADE gn was recreated successfully 59240393Sbostic * ERROR An error occurred while gn was being created 59340393Sbostic * ABORTED gn was not remade because one of its inferiors 59440393Sbostic * could not be made due to errors. 59540393Sbostic */ 59640393Sbostic errors = 0; 59740393Sbostic while (!Lst_IsEmpty (targs)) { 59840393Sbostic gn = (GNode *) Lst_DeQueue (targs); 59940393Sbostic CompatMake (gn, gn); 60040393Sbostic 60140393Sbostic if (gn->made == UPTODATE) { 60240393Sbostic printf ("`%s' is up to date.\n", gn->name); 60340393Sbostic } else if (gn->made == ABORTED) { 60440393Sbostic printf ("`%s' not remade because of errors.\n", gn->name); 60540393Sbostic errors += 1; 60640393Sbostic } 60740393Sbostic } 60840393Sbostic 60940393Sbostic /* 61040393Sbostic * If the user has defined a .END target, run its commands. 61140393Sbostic */ 61240393Sbostic if (errors == 0) { 61340393Sbostic Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn); 61440393Sbostic } 61540393Sbostic } 616