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*40527Sbostic static char sccsid[] = "@(#)compat.c 5.4 (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 /* 145*40527Sbostic * 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') { 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. 222*40527Sbostic * brk_string sticks our name in av[0], so we have to 22340393Sbostic * skip over it... 22440393Sbostic */ 225*40527Sbostic av = brk_string(cmd, &argc); 22640393Sbostic av += 1; 22740393Sbostic } 22840393Sbostic 22940438Sbostic local = TRUE; 23040393Sbostic 23140393Sbostic /* 23240393Sbostic * Fork and execute the single command. If the fork fails, we abort. 23340393Sbostic */ 23440393Sbostic cpid = vfork(); 23540393Sbostic if (cpid < 0) { 23640393Sbostic Fatal("Could not fork"); 23740393Sbostic } 23840393Sbostic if (cpid == 0) { 23940393Sbostic if (local) { 24040393Sbostic execvp(av[0], av); 24140393Sbostic numWritten = write (2, av[0], strlen (av[0])); 24240393Sbostic numWritten = write (2, ": not found\n", sizeof(": not found")); 24340393Sbostic } else { 24440438Sbostic (void)execv(av[0], av); 24540393Sbostic } 24640393Sbostic exit(1); 24740393Sbostic } 24840393Sbostic 24940393Sbostic /* 25040393Sbostic * The child is off and running. Now all we can do is wait... 25140393Sbostic */ 25240393Sbostic while (1) { 25340393Sbostic int id; 25440393Sbostic 25540393Sbostic if (!local) { 25640438Sbostic id = 0; 25740393Sbostic } 25840393Sbostic 25940393Sbostic while ((stat = wait(&reason)) != cpid) { 26040393Sbostic if (stat == -1 && errno != EINTR) { 26140393Sbostic break; 26240393Sbostic } 26340393Sbostic } 26440393Sbostic 26540393Sbostic if (stat > -1) { 26640393Sbostic if (WIFSTOPPED(reason)) { 26740393Sbostic status = reason.w_stopval; /* stopped */ 26840393Sbostic } else if (WIFEXITED(reason)) { 26940393Sbostic status = reason.w_retcode; /* exited */ 27040393Sbostic if (status != 0) { 27140393Sbostic printf ("*** Error code %d", status); 27240393Sbostic } 27340393Sbostic } else { 27440393Sbostic status = reason.w_termsig; /* signaled */ 27540393Sbostic printf ("*** Signal %d", status); 27640393Sbostic } 27740393Sbostic 27840393Sbostic 27940393Sbostic if (!WIFEXITED(reason) || (status != 0)) { 28040393Sbostic if (errCheck) { 28140393Sbostic gn->made = ERROR; 28240393Sbostic if (keepgoing) { 28340393Sbostic /* 28440393Sbostic * Abort the current target, but let others 28540393Sbostic * continue. 28640393Sbostic */ 28740393Sbostic printf (" (continuing)\n"); 28840393Sbostic } 28940393Sbostic } else { 29040393Sbostic /* 29140393Sbostic * Continue executing commands for this target. 29240393Sbostic * If we return 0, this will happen... 29340393Sbostic */ 29440393Sbostic printf (" (ignored)\n"); 29540393Sbostic status = 0; 29640393Sbostic } 29740393Sbostic } 29840393Sbostic break; 29940393Sbostic } else { 30040393Sbostic Fatal ("error in wait: %d", stat); 30140393Sbostic /*NOTREACHED*/ 30240393Sbostic } 30340393Sbostic } 30440393Sbostic 30540393Sbostic return (status); 30640393Sbostic } 30740393Sbostic 30840393Sbostic /*- 30940393Sbostic *----------------------------------------------------------------------- 31040393Sbostic * CompatMake -- 31140393Sbostic * Make a target. 31240393Sbostic * 31340393Sbostic * Results: 31440393Sbostic * 0 31540393Sbostic * 31640393Sbostic * Side Effects: 31740393Sbostic * If an error is detected and not being ignored, the process exits. 31840393Sbostic * 31940393Sbostic *----------------------------------------------------------------------- 32040393Sbostic */ 32140393Sbostic static int 32240393Sbostic CompatMake (gn, pgn) 32340393Sbostic GNode *gn; /* The node to make */ 32440393Sbostic GNode *pgn; /* Parent to abort if necessary */ 32540393Sbostic { 32640393Sbostic if (gn->type & OP_USE) { 32740393Sbostic Make_HandleUse(gn, pgn); 32840393Sbostic } else if (gn->made == UNMADE) { 32940393Sbostic /* 33040393Sbostic * First mark ourselves to be made, then apply whatever transformations 33140393Sbostic * the suffix module thinks are necessary. Once that's done, we can 33240393Sbostic * descend and make all our children. If any of them has an error 33340393Sbostic * but the -k flag was given, our 'make' field will be set FALSE again. 33440393Sbostic * This is our signal to not attempt to do anything but abort our 33540393Sbostic * parent as well. 33640393Sbostic */ 33740393Sbostic gn->make = TRUE; 33840393Sbostic gn->made = BEINGMADE; 33940393Sbostic Suff_FindDeps (gn); 34040393Sbostic Lst_ForEach (gn->children, CompatMake, (ClientData)gn); 34140393Sbostic if (!gn->make) { 34240393Sbostic gn->made = ABORTED; 34340393Sbostic pgn->make = FALSE; 34440393Sbostic return (0); 34540393Sbostic } 34640393Sbostic 34740393Sbostic if (Lst_Member (gn->iParents, pgn) != NILLNODE) { 34840393Sbostic Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn); 34940393Sbostic } 35040393Sbostic 35140393Sbostic /* 35240393Sbostic * All the children were made ok. Now cmtime contains the modification 35340393Sbostic * time of the newest child, we need to find out if we exist and when 35440393Sbostic * we were modified last. The criteria for datedness are defined by the 35540393Sbostic * Make_OODate function. 35640393Sbostic */ 35740393Sbostic if (DEBUG(MAKE)) { 35840393Sbostic printf("Examining %s...", gn->name); 35940393Sbostic } 36040393Sbostic if (! Make_OODate(gn)) { 36140393Sbostic gn->made = UPTODATE; 36240393Sbostic if (DEBUG(MAKE)) { 36340393Sbostic printf("up-to-date.\n"); 36440393Sbostic } 36540393Sbostic return (0); 36640393Sbostic } else if (DEBUG(MAKE)) { 36740393Sbostic printf("out-of-date.\n"); 36840393Sbostic } 36940393Sbostic 37040393Sbostic /* 37140393Sbostic * If the user is just seeing if something is out-of-date, exit now 37240393Sbostic * to tell him/her "yes". 37340393Sbostic */ 37440393Sbostic if (queryFlag) { 37540393Sbostic exit (-1); 37640393Sbostic } 37740393Sbostic 37840393Sbostic /* 37940393Sbostic * We need to be re-made. We also have to make sure we've got a $? 38040393Sbostic * variable. To be nice, we also define the $> variable using 38140393Sbostic * Make_DoAllVar(). 38240393Sbostic */ 38340393Sbostic Make_DoAllVar(gn); 38440393Sbostic 38540393Sbostic /* 38640393Sbostic * Alter our type to tell if errors should be ignored or things 38740393Sbostic * should not be printed so CompatRunCommand knows what to do. 38840393Sbostic */ 38940393Sbostic if (Targ_Ignore (gn)) { 39040393Sbostic gn->type |= OP_IGNORE; 39140393Sbostic } 39240393Sbostic if (Targ_Silent (gn)) { 39340393Sbostic gn->type |= OP_SILENT; 39440393Sbostic } 39540393Sbostic 39640393Sbostic if (Job_CheckCommands (gn, Fatal)) { 39740393Sbostic /* 39840393Sbostic * Our commands are ok, but we still have to worry about the -t 39940393Sbostic * flag... 40040393Sbostic */ 40140393Sbostic if (!touchFlag) { 40240393Sbostic curTarg = gn; 40340393Sbostic Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn); 40440393Sbostic curTarg = NILGNODE; 40540393Sbostic } else { 40640393Sbostic Job_Touch (gn, gn->type & OP_SILENT); 40740393Sbostic } 40840393Sbostic } else { 40940393Sbostic gn->made = ERROR; 41040393Sbostic } 41140393Sbostic 41240393Sbostic if (gn->made != ERROR) { 41340393Sbostic /* 41440393Sbostic * If the node was made successfully, mark it so, update 41540393Sbostic * its modification time and timestamp all its parents. Note 41640393Sbostic * that for .ZEROTIME targets, the timestamping isn't done. 41740393Sbostic * This is to keep its state from affecting that of its parent. 41840393Sbostic */ 41940393Sbostic gn->made = MADE; 42040393Sbostic #ifndef RECHECK 42140393Sbostic /* 42240393Sbostic * We can't re-stat the thing, but we can at least take care of 42340393Sbostic * rules where a target depends on a source that actually creates 42440393Sbostic * the target, but only if it has changed, e.g. 42540393Sbostic * 42640393Sbostic * parse.h : parse.o 42740393Sbostic * 42840393Sbostic * parse.o : parse.y 42940393Sbostic * yacc -d parse.y 43040393Sbostic * cc -c y.tab.c 43140393Sbostic * mv y.tab.o parse.o 43240393Sbostic * cmp -s y.tab.h parse.h || mv y.tab.h parse.h 43340393Sbostic * 43440393Sbostic * In this case, if the definitions produced by yacc haven't 43540393Sbostic * changed from before, parse.h won't have been updated and 43640393Sbostic * gn->mtime will reflect the current modification time for 43740393Sbostic * parse.h. This is something of a kludge, I admit, but it's a 43840393Sbostic * useful one.. 43940393Sbostic * 44040393Sbostic * XXX: People like to use a rule like 44140393Sbostic * 44240393Sbostic * FRC: 44340393Sbostic * 44440393Sbostic * To force things that depend on FRC to be made, so we have to 44540393Sbostic * check for gn->children being empty as well... 44640393Sbostic */ 44740393Sbostic if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) { 44840393Sbostic gn->mtime = now; 44940393Sbostic } 45040393Sbostic #else 45140393Sbostic /* 45240393Sbostic * This is what Make does and it's actually a good thing, as it 45340393Sbostic * allows rules like 45440393Sbostic * 45540393Sbostic * cmp -s y.tab.h parse.h || cp y.tab.h parse.h 45640393Sbostic * 45740393Sbostic * to function as intended. Unfortunately, thanks to the stateless 45840393Sbostic * nature of NFS (and the speed of this program), there are times 45940393Sbostic * when the modification time of a file created on a remote 46040393Sbostic * machine will not be modified before the stat() implied by 46140393Sbostic * the Dir_MTime occurs, thus leading us to believe that the file 46240393Sbostic * is unchanged, wreaking havoc with files that depend on this one. 46340393Sbostic * 46440393Sbostic * I have decided it is better to make too much than to make too 46540393Sbostic * little, so this stuff is commented out unless you're sure it's 46640393Sbostic * ok. 46740393Sbostic * -- ardeb 1/12/88 46840393Sbostic */ 46940393Sbostic if (noExecute || Dir_MTime(gn) == 0) { 47040393Sbostic gn->mtime = now; 47140393Sbostic } 47240393Sbostic if (DEBUG(MAKE)) { 47340393Sbostic printf("update time: %s\n", Targ_FmtTime(gn->mtime)); 47440393Sbostic } 47540393Sbostic #endif 47640393Sbostic if (!(gn->type & OP_EXEC)) { 47740393Sbostic pgn->childMade = TRUE; 47840393Sbostic Make_TimeStamp(pgn, gn); 47940393Sbostic } 48040393Sbostic } else if (keepgoing) { 48140393Sbostic pgn->make = FALSE; 48240393Sbostic } else { 48340393Sbostic printf ("\n\nStop.\n"); 48440393Sbostic exit (1); 48540393Sbostic } 48640393Sbostic } else if (gn->made == ERROR) { 48740393Sbostic /* 48840393Sbostic * Already had an error when making this beastie. Tell the parent 48940393Sbostic * to abort. 49040393Sbostic */ 49140393Sbostic pgn->make = FALSE; 49240393Sbostic } else { 49340393Sbostic if (Lst_Member (gn->iParents, pgn) != NILLNODE) { 49440393Sbostic Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn); 49540393Sbostic } 49640393Sbostic switch(gn->made) { 49740393Sbostic case BEINGMADE: 49840393Sbostic Error("Graph cycles through %s\n", gn->name); 49940393Sbostic gn->made = ERROR; 50040393Sbostic pgn->make = FALSE; 50140393Sbostic break; 50240393Sbostic case MADE: 50340393Sbostic if ((gn->type & OP_EXEC) == 0) { 50440393Sbostic pgn->childMade = TRUE; 50540393Sbostic Make_TimeStamp(pgn, gn); 50640393Sbostic } 50740393Sbostic break; 50840393Sbostic case UPTODATE: 50940393Sbostic if ((gn->type & OP_EXEC) == 0) { 51040393Sbostic Make_TimeStamp(pgn, gn); 51140393Sbostic } 51240393Sbostic break; 51340393Sbostic } 51440393Sbostic } 51540393Sbostic 51640393Sbostic return (0); 51740393Sbostic } 51840393Sbostic 51940393Sbostic /*- 52040393Sbostic *----------------------------------------------------------------------- 52140393Sbostic * Compat_Run -- 52240393Sbostic * Initialize this mode and start making. 52340393Sbostic * 52440393Sbostic * Results: 52540393Sbostic * None. 52640393Sbostic * 52740393Sbostic * Side Effects: 52840393Sbostic * Guess what? 52940393Sbostic * 53040393Sbostic *----------------------------------------------------------------------- 53140393Sbostic */ 53240393Sbostic void 53340393Sbostic Compat_Run(targs) 53440393Sbostic Lst targs; /* List of target nodes to re-create */ 53540393Sbostic { 53640393Sbostic char *cp; /* Pointer to string of shell meta-characters */ 53740393Sbostic GNode *gn; /* Current root target */ 53840393Sbostic int errors; /* Number of targets not remade due to errors */ 53940393Sbostic 54040393Sbostic if (signal(SIGINT, SIG_IGN) != SIG_IGN) { 54140393Sbostic signal(SIGINT, CompatInterrupt); 54240393Sbostic } 54340393Sbostic if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { 54440393Sbostic signal(SIGTERM, CompatInterrupt); 54540393Sbostic } 54640393Sbostic if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { 54740393Sbostic signal(SIGHUP, CompatInterrupt); 54840393Sbostic } 54940393Sbostic if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) { 55040393Sbostic signal(SIGQUIT, CompatInterrupt); 55140393Sbostic } 55240393Sbostic 55340393Sbostic for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) { 55440393Sbostic meta[*cp] = 1; 55540393Sbostic } 55640393Sbostic /* 55740393Sbostic * The null character serves as a sentinel in the string. 55840393Sbostic */ 55940393Sbostic meta[0] = 1; 56040393Sbostic 56140393Sbostic ENDNode = Targ_FindNode(".END", TARG_CREATE); 56240393Sbostic /* 56340393Sbostic * If the user has defined a .BEGIN target, execute the commands attached 56440393Sbostic * to it. 56540393Sbostic */ 56640393Sbostic if (!queryFlag) { 56740393Sbostic gn = Targ_FindNode(".BEGIN", TARG_NOCREATE); 56840393Sbostic if (gn != NILGNODE) { 56940393Sbostic Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn); 57040393Sbostic } 57140393Sbostic } 57240393Sbostic 57340393Sbostic /* 57440393Sbostic * For each entry in the list of targets to create, call CompatMake on 57540393Sbostic * it to create the thing. CompatMake will leave the 'made' field of gn 57640393Sbostic * in one of several states: 57740393Sbostic * UPTODATE gn was already up-to-date 57840393Sbostic * MADE gn was recreated successfully 57940393Sbostic * ERROR An error occurred while gn was being created 58040393Sbostic * ABORTED gn was not remade because one of its inferiors 58140393Sbostic * could not be made due to errors. 58240393Sbostic */ 58340393Sbostic errors = 0; 58440393Sbostic while (!Lst_IsEmpty (targs)) { 58540393Sbostic gn = (GNode *) Lst_DeQueue (targs); 58640393Sbostic CompatMake (gn, gn); 58740393Sbostic 58840393Sbostic if (gn->made == UPTODATE) { 58940393Sbostic printf ("`%s' is up to date.\n", gn->name); 59040393Sbostic } else if (gn->made == ABORTED) { 59140393Sbostic printf ("`%s' not remade because of errors.\n", gn->name); 59240393Sbostic errors += 1; 59340393Sbostic } 59440393Sbostic } 59540393Sbostic 59640393Sbostic /* 59740393Sbostic * If the user has defined a .END target, run its commands. 59840393Sbostic */ 59940393Sbostic if (errors == 0) { 60040393Sbostic Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn); 60140393Sbostic } 60240393Sbostic } 603