Annotation of src/usr.bin/make/compat.c, Revision 1.33
1.33 ! espie 1: /* $OpenBSD: compat.c,v 1.32 2000/06/30 23:26:25 espie Exp $ */
1.8 millert 2: /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
6: * Copyright (c) 1988, 1989 by Adam de Boor
7: * Copyright (c) 1989 by Berkeley Softworks
8: * All rights reserved.
9: *
10: * This code is derived from software contributed to Berkeley by
11: * Adam de Boor.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: */
41:
42: /*-
43: * compat.c --
44: * The routines in this file implement the full-compatibility
45: * mode of PMake. Most of the special functionality of PMake
46: * is available in this mode. Things not supported:
47: * - different shells.
48: * - friendly variable substitution.
49: *
50: * Interface:
51: * Compat_Run Initialize things for this module and recreate
52: * thems as need creatin'
53: */
54:
55: #include <stdio.h>
56: #include <sys/types.h>
57: #include <sys/stat.h>
58: #include <sys/wait.h>
59: #include <ctype.h>
60: #include <errno.h>
61: #include <signal.h>
62: #include "make.h"
63: #include "hash.h"
64: #include "dir.h"
65: #include "job.h"
1.33 ! espie 66:
! 67: #ifndef lint
! 68: #if 0
! 69: static char sccsid[] = "@(#)compat.c 8.2 (Berkeley) 3/19/94";
! 70: #else
! 71: UNUSED
! 72: static char rcsid[] = "$OpenBSD: compat.c,v 1.32 2000/06/30 23:26:25 espie Exp $";
! 73: #endif
! 74: #endif /* not lint */
1.1 deraadt 75:
76: /*
77: * The following array is used to make a fast determination of which
78: * characters are interpreted specially by the shell. If a command
79: * contains any of these characters, it is executed by the shell, not
80: * directly by us.
81: */
82:
83: static char meta[256];
84:
1.18 espie 85: static GNode *curTarg = NULL;
1.1 deraadt 86: static GNode *ENDNode;
87: static void CompatInterrupt __P((int));
1.27 espie 88: static int CompatRunCommand __P((void *, void *));
89: static void CompatMake __P((void *, void *));
1.13 espie 90: static int shellneed __P((char **av));
1.1 deraadt 91:
92: /*-
93: *-----------------------------------------------------------------------
94: * CompatInterrupt --
95: * Interrupt the creation of the current target and remove it if
96: * it ain't precious.
97: *
98: * Results:
99: * None.
100: *
101: * Side Effects:
102: * The target is removed and the process exits. If .INTERRUPT exists,
103: * its commands are run first WITH INTERRUPTS IGNORED..
104: *
105: *-----------------------------------------------------------------------
106: */
107: static void
108: CompatInterrupt (signo)
109: int signo;
110: {
111: GNode *gn;
1.4 millert 112:
1.18 espie 113: if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
1.29 espie 114: char *file = Varq_Value(TARGET_INDEX, curTarg);
1.1 deraadt 115:
1.2 deraadt 116: if (!noExecute && eunlink(file) != -1) {
1.12 espie 117: Error("*** %s removed\n", file);
1.1 deraadt 118: }
119:
120: /*
121: * Run .INTERRUPT only if hit with interrupt signal
122: */
123: if (signo == SIGINT) {
124: gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
1.18 espie 125: if (gn != NULL) {
1.28 espie 126: Lst_Find(&gn->commands, CompatRunCommand, gn);
1.1 deraadt 127: }
128: }
129:
130: }
131: exit (signo);
132: }
133:
134: /*-
135: *-----------------------------------------------------------------------
1.10 deraadt 136: * shellneed --
137: *
138: * Results:
1.12 espie 139: * Returns 1 if a specified set of arguments
140: * must be executed by the shell,
141: * 0 if it can be run via execve, and -1 if the command can be
142: * handled internally
1.10 deraadt 143: *
144: * Side Effects:
1.12 espie 145: * May modify the process umask
1.10 deraadt 146: *
147: *-----------------------------------------------------------------------
148: */
149: static int
1.12 espie 150: shellneed (av)
151: char **av;
1.10 deraadt 152: {
1.11 deraadt 153: char *runsh[] = {
154: "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
1.12 espie 155: "unalias", "unset", "wait",
1.11 deraadt 156: NULL
157: };
158:
1.12 espie 159: char **p;
1.11 deraadt 160:
1.12 espie 161: /* FIXME most of these ARE actual no-ops */
1.11 deraadt 162: for (p = runsh; *p; p++)
1.12 espie 163: if (strcmp(av[0], *p) == 0)
1.11 deraadt 164: return (1);
165:
1.12 espie 166: if (strcmp(av[0], "umask") == 0) {
1.10 deraadt 167: long umi;
168: char *ep = NULL;
169: mode_t um;
170:
1.12 espie 171: if (av[1] != NULL) {
172: umi = strtol(av[1], &ep, 8);
1.10 deraadt 173: if (ep == NULL)
174: return (1);
175: um = umi;
176: }
1.12 espie 177: else {
178: um = umask(0);
179: printf("%o\n", um);
180: }
1.10 deraadt 181: (void) umask(um);
182: return (-1);
183: }
184:
185: return (0);
186: }
187:
188: /*-
189: *-----------------------------------------------------------------------
1.1 deraadt 190: * CompatRunCommand --
191: * Execute the next command for a target. If the command returns an
192: * error, the node's made field is set to ERROR and creation stops.
193: *
194: * Results:
1.25 espie 195: * 1 if the command succeeded, 0 if an error occurred.
1.1 deraadt 196: *
197: * Side Effects:
198: * The node's 'made' field may be set to ERROR.
199: *
200: *-----------------------------------------------------------------------
201: */
202: static int
203: CompatRunCommand (cmdp, gnp)
1.27 espie 204: void *cmdp; /* Command to execute */
205: void *gnp; /* Node from which the command came */
1.1 deraadt 206: {
207: char *cmdStart; /* Start of expanded command */
1.12 espie 208: char *cp, *bp = NULL;
1.1 deraadt 209: Boolean silent, /* Don't print command */
1.32 espie 210: errCheck, /* Check errors */
211: doExecute; /* Execute the command */
1.2 deraadt 212: int reason; /* Reason for child's death */
1.1 deraadt 213: int status; /* Description of child's death */
214: int cpid; /* Child actually found */
215: ReturnStatus stat; /* Status of fork */
216: LstNode cmdNode; /* Node where current command is located */
217: char **av; /* Argument vector for thing to exec */
218: int argc; /* Number of arguments in av or 0 if not
219: * dynamically allocated */
220: Boolean local; /* TRUE if command should be executed
221: * locally */
222: char *cmd = (char *) cmdp;
223: GNode *gn = (GNode *) gnp;
1.12 espie 224: static char *shargv[4] = { "/bin/sh" };
1.1 deraadt 225:
1.4 millert 226: /*
1.1 deraadt 227: * Avoid clobbered variable warnings by forcing the compiler
228: * to ``unregister'' variables
229: */
230: #if __GNUC__
231: (void) &av;
232: (void) &errCheck;
233: #endif
234: silent = gn->type & OP_SILENT;
235: errCheck = !(gn->type & OP_IGNORE);
1.32 espie 236: doExecute = !noExecute;
1.1 deraadt 237:
1.28 espie 238: cmdNode = Lst_Member(&gn->commands, cmd);
1.30 espie 239: cmdStart = Var_Subst(cmd, &gn->context, FALSE);
1.1 deraadt 240:
241: /*
1.12 espie 242: * brk_string will return an argv with a NULL in av[0], thus causing
1.1 deraadt 243: * execvp to choke and die horribly. Besides, how can we execute a null
244: * command? In any case, we warn the user that the command expanded to
245: * nothing (is this the right thing to do?).
246: */
1.4 millert 247:
1.1 deraadt 248: if (*cmdStart == '\0') {
249: free(cmdStart);
250: Error("%s expands to empty string", cmd);
1.25 espie 251: return 1;
1.1 deraadt 252: } else {
253: cmd = cmdStart;
254: }
1.23 espie 255: Lst_Replace(cmdNode, cmdStart);
1.1 deraadt 256:
257: if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
1.28 espie 258: Lst_AtEnd(&ENDNode->commands, cmdStart);
1.25 espie 259: return 1;
1.1 deraadt 260: } else if (strcmp(cmdStart, "...") == 0) {
261: gn->type |= OP_SAVE_CMDS;
1.25 espie 262: return 1;
1.1 deraadt 263: }
264:
1.32 espie 265: for (;; cmd++) {
266: if (*cmd == '@')
1.1 deraadt 267: silent = TRUE;
1.32 espie 268: else if (*cmd == '-')
1.1 deraadt 269: errCheck = FALSE;
1.32 espie 270: else if (*cmd == '+')
271: doExecute = TRUE;
272: else
273: break;
1.1 deraadt 274: }
275:
276: while (isspace((unsigned char)*cmd))
277: cmd++;
1.4 millert 278:
1.1 deraadt 279: /*
280: * Search for meta characters in the command. If there are no meta
281: * characters, there's no need to execute a shell to execute the
282: * command.
283: */
284: for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
285: continue;
286: }
287:
288: /*
289: * Print the command before echoing if we're not supposed to be quiet for
290: * this one. We also print the command if -n given.
291: */
292: if (!silent || noExecute) {
293: printf ("%s\n", cmd);
294: fflush(stdout);
295: }
296:
297: /*
298: * If we're not supposed to execute any commands, this is as far as
299: * we go...
300: */
1.32 espie 301: if (!doExecute)
1.25 espie 302: return 1;
1.4 millert 303:
1.1 deraadt 304: if (*cp != '\0') {
305: /*
306: * If *cp isn't the null character, we hit a "meta" character and
307: * need to pass the command off to the shell. We give the shell the
308: * -e flag as well as -c if it's supposed to exit when it hits an
309: * error.
310: */
1.10 deraadt 311:
312: shargv[1] = (errCheck ? "-ec" : "-c");
313: shargv[2] = cmd;
314: shargv[3] = (char *)NULL;
315: av = shargv;
316: argc = 0;
1.12 espie 317: } else {
1.10 deraadt 318: /*
1.12 espie 319: * No meta-characters, so probably no need to exec a shell.
320: * Break the command into words to form an argument vector
321: * we can execute.
1.10 deraadt 322: */
1.12 espie 323: av = brk_string(cmd, &argc, TRUE, &bp);
324: switch(shellneed(av)) {
325: case -1: /* handled internally */
326: free(bp);
327: free(av);
1.25 espie 328: return 1;
1.12 espie 329: case 1:
330: shargv[1] = (errCheck ? "-ec" : "-c");
331: shargv[2] = cmd;
332: shargv[3] = (char *)NULL;
1.14 espie 333: free(bp);
334: free(av);
335: bp = NULL;
1.12 espie 336: av = shargv;
337: argc = 0;
338: break;
339: default: /* nothing needed */
340: break;
1.10 deraadt 341: }
1.1 deraadt 342: }
1.4 millert 343:
1.1 deraadt 344: local = TRUE;
345:
346: /*
347: * Fork and execute the single command. If the fork fails, we abort.
348: */
349: cpid = vfork();
350: if (cpid < 0) {
351: Fatal("Could not fork");
352: }
353: if (cpid == 0) {
354: if (local) {
355: execvp(av[0], av);
1.17 espie 356: if (errno == ENOENT)
357: fprintf(stderr, "%s: not found\n", av[0]);
358: else
359: perror(av[0]);
1.1 deraadt 360: } else {
361: (void)execv(av[0], av);
362: }
1.9 deraadt 363: _exit(1);
1.1 deraadt 364: }
1.12 espie 365: if (bp) {
366: free(av);
367: free(bp);
368: }
1.1 deraadt 369: free(cmdStart);
1.23 espie 370: Lst_Replace(cmdNode, NULL);
1.4 millert 371:
1.1 deraadt 372: /*
373: * The child is off and running. Now all we can do is wait...
374: */
375: while (1) {
376:
1.2 deraadt 377: while ((stat = wait(&reason)) != cpid) {
1.1 deraadt 378: if (stat == -1 && errno != EINTR) {
379: break;
380: }
381: }
1.4 millert 382:
1.1 deraadt 383: if (stat > -1) {
384: if (WIFSTOPPED(reason)) {
1.2 deraadt 385: status = WSTOPSIG(reason); /* stopped */
1.1 deraadt 386: } else if (WIFEXITED(reason)) {
1.2 deraadt 387: status = WEXITSTATUS(reason); /* exited */
1.1 deraadt 388: if (status != 0) {
389: printf ("*** Error code %d", status);
390: }
391: } else {
1.2 deraadt 392: status = WTERMSIG(reason); /* signaled */
1.1 deraadt 393: printf ("*** Signal %d", status);
1.4 millert 394: }
395:
1.1 deraadt 396:
397: if (!WIFEXITED(reason) || (status != 0)) {
398: if (errCheck) {
399: gn->made = ERROR;
400: if (keepgoing) {
401: /*
402: * Abort the current target, but let others
403: * continue.
404: */
405: printf (" (continuing)\n");
406: }
407: } else {
408: /*
409: * Continue executing commands for this target.
410: * If we return 0, this will happen...
411: */
412: printf (" (ignored)\n");
413: status = 0;
414: }
415: }
416: break;
417: } else {
418: Fatal ("error in wait: %d", stat);
419: /*NOTREACHED*/
420: }
421: }
422:
1.25 espie 423: return !status;
1.1 deraadt 424: }
425:
426: /*-
427: *-----------------------------------------------------------------------
428: * CompatMake --
429: * Make a target.
430: *
431: * Side Effects:
432: * If an error is detected and not being ignored, the process exits.
433: *
434: *-----------------------------------------------------------------------
435: */
1.26 espie 436: static void
437: CompatMake(gnp, pgnp)
1.27 espie 438: void *gnp; /* The node to make */
439: void *pgnp; /* Parent to abort if necessary */
1.1 deraadt 440: {
441: GNode *gn = (GNode *) gnp;
442: GNode *pgn = (GNode *) pgnp;
1.5 millert 443:
1.7 deraadt 444: if (pgn->type & OP_MADE) {
445: (void) Dir_MTime(gn);
446: gn->made = UPTODATE;
447: }
448:
1.8 millert 449: if (gn->type & OP_USE) {
450: Make_HandleUse(gn, pgn);
451: } else if (gn->made == UNMADE) {
1.1 deraadt 452: /*
453: * First mark ourselves to be made, then apply whatever transformations
454: * the suffix module thinks are necessary. Once that's done, we can
455: * descend and make all our children. If any of them has an error
456: * but the -k flag was given, our 'make' field will be set FALSE again.
457: * This is our signal to not attempt to do anything but abort our
458: * parent as well.
459: */
460: gn->make = TRUE;
461: gn->made = BEINGMADE;
462: Suff_FindDeps (gn);
1.28 espie 463: Lst_ForEach(&gn->children, CompatMake, gn);
1.1 deraadt 464: if (!gn->make) {
465: gn->made = ABORTED;
466: pgn->make = FALSE;
1.26 espie 467: return;
1.1 deraadt 468: }
469:
1.29 espie 470: if (Lst_Member(&gn->iParents, pgn) != NULL)
471: Varq_Set(IMPSRC_INDEX, Varq_Value(TARGET_INDEX, gn), pgn);
1.4 millert 472:
1.1 deraadt 473: /*
474: * All the children were made ok. Now cmtime contains the modification
475: * time of the newest child, we need to find out if we exist and when
476: * we were modified last. The criteria for datedness are defined by the
477: * Make_OODate function.
478: */
479: if (DEBUG(MAKE)) {
480: printf("Examining %s...", gn->name);
481: }
482: if (! Make_OODate(gn)) {
483: gn->made = UPTODATE;
484: if (DEBUG(MAKE)) {
485: printf("up-to-date.\n");
486: }
1.26 espie 487: return;
1.1 deraadt 488: } else if (DEBUG(MAKE)) {
489: printf("out-of-date.\n");
490: }
491:
492: /*
493: * If the user is just seeing if something is out-of-date, exit now
494: * to tell him/her "yes".
495: */
496: if (queryFlag) {
497: exit (-1);
498: }
499:
500: /*
501: * We need to be re-made. We also have to make sure we've got a $?
502: * variable. To be nice, we also define the $> variable using
503: * Make_DoAllVar().
504: */
505: Make_DoAllVar(gn);
1.4 millert 506:
1.1 deraadt 507: /*
508: * Alter our type to tell if errors should be ignored or things
509: * should not be printed so CompatRunCommand knows what to do.
510: */
511: if (Targ_Ignore (gn)) {
512: gn->type |= OP_IGNORE;
513: }
514: if (Targ_Silent (gn)) {
515: gn->type |= OP_SILENT;
516: }
517:
518: if (Job_CheckCommands (gn, Fatal)) {
519: /*
520: * Our commands are ok, but we still have to worry about the -t
521: * flag...
522: */
523: if (!touchFlag) {
524: curTarg = gn;
1.28 espie 525: Lst_Find(&gn->commands, CompatRunCommand, gn);
1.18 espie 526: curTarg = NULL;
1.1 deraadt 527: } else {
528: Job_Touch (gn, gn->type & OP_SILENT);
529: }
530: } else {
531: gn->made = ERROR;
532: }
533:
534: if (gn->made != ERROR) {
535: /*
536: * If the node was made successfully, mark it so, update
537: * its modification time and timestamp all its parents. Note
538: * that for .ZEROTIME targets, the timestamping isn't done.
539: * This is to keep its state from affecting that of its parent.
540: */
541: gn->made = MADE;
542: #ifndef RECHECK
543: /*
544: * We can't re-stat the thing, but we can at least take care of
545: * rules where a target depends on a source that actually creates
546: * the target, but only if it has changed, e.g.
547: *
548: * parse.h : parse.o
549: *
550: * parse.o : parse.y
551: * yacc -d parse.y
552: * cc -c y.tab.c
553: * mv y.tab.o parse.o
554: * cmp -s y.tab.h parse.h || mv y.tab.h parse.h
555: *
556: * In this case, if the definitions produced by yacc haven't
557: * changed from before, parse.h won't have been updated and
558: * gn->mtime will reflect the current modification time for
559: * parse.h. This is something of a kludge, I admit, but it's a
560: * useful one..
561: *
562: * XXX: People like to use a rule like
563: *
564: * FRC:
565: *
566: * To force things that depend on FRC to be made, so we have to
567: * check for gn->children being empty as well...
568: */
1.28 espie 569: if (!Lst_IsEmpty(&gn->commands) || Lst_IsEmpty(&gn->children)) {
1.1 deraadt 570: gn->mtime = now;
571: }
572: #else
573: /*
574: * This is what Make does and it's actually a good thing, as it
575: * allows rules like
576: *
577: * cmp -s y.tab.h parse.h || cp y.tab.h parse.h
578: *
579: * to function as intended. Unfortunately, thanks to the stateless
580: * nature of NFS (and the speed of this program), there are times
581: * when the modification time of a file created on a remote
582: * machine will not be modified before the stat() implied by
583: * the Dir_MTime occurs, thus leading us to believe that the file
584: * is unchanged, wreaking havoc with files that depend on this one.
585: *
586: * I have decided it is better to make too much than to make too
587: * little, so this stuff is commented out unless you're sure it's
588: * ok.
589: * -- ardeb 1/12/88
590: */
1.22 espie 591: if (noExecute || Dir_MTime(gn) == FALSE) {
1.1 deraadt 592: gn->mtime = now;
593: }
594: if (gn->cmtime > gn->mtime)
595: gn->mtime = gn->cmtime;
596: if (DEBUG(MAKE)) {
597: printf("update time: %s\n", Targ_FmtTime(gn->mtime));
598: }
599: #endif
600: if (!(gn->type & OP_EXEC)) {
601: pgn->childMade = TRUE;
602: Make_TimeStamp(pgn, gn);
603: }
604: } else if (keepgoing) {
605: pgn->make = FALSE;
606: } else {
1.24 espie 607: if (gn->lineno)
608: printf("\n\nStop in %s (line %lu of %s).\n",
1.31 espie 609: Var_Value(".CURDIR", VAR_GLOBAL),
1.24 espie 610: (unsigned long)gn->lineno,
611: gn->fname);
612: else
1.31 espie 613: printf("\n\nStop in %s.\n", Var_Value(".CURDIR", VAR_GLOBAL));
1.1 deraadt 614: exit (1);
615: }
616: } else if (gn->made == ERROR) {
617: /*
618: * Already had an error when making this beastie. Tell the parent
619: * to abort.
620: */
621: pgn->make = FALSE;
622: } else {
1.28 espie 623: if (Lst_Member(&gn->iParents, pgn) != NULL)
1.29 espie 624: Varq_Set(IMPSRC_INDEX, Varq_Value(TARGET_INDEX, gn), pgn);
1.1 deraadt 625: switch(gn->made) {
626: case BEINGMADE:
627: Error("Graph cycles through %s\n", gn->name);
628: gn->made = ERROR;
629: pgn->make = FALSE;
630: break;
631: case MADE:
632: if ((gn->type & OP_EXEC) == 0) {
633: pgn->childMade = TRUE;
634: Make_TimeStamp(pgn, gn);
635: }
636: break;
637: case UPTODATE:
638: if ((gn->type & OP_EXEC) == 0) {
639: Make_TimeStamp(pgn, gn);
640: }
641: break;
642: default:
643: break;
644: }
645: }
646: }
1.4 millert 647:
1.1 deraadt 648: /*-
649: *-----------------------------------------------------------------------
650: * Compat_Run --
651: * Initialize this mode and start making.
652: *
653: * Results:
654: * None.
655: *
656: * Side Effects:
657: * Guess what?
658: *
659: *-----------------------------------------------------------------------
660: */
661: void
662: Compat_Run(targs)
663: Lst targs; /* List of target nodes to re-create */
664: {
665: char *cp; /* Pointer to string of shell meta-characters */
666: GNode *gn = NULL;/* Current root target */
667: int errors; /* Number of targets not remade due to errors */
668:
669: if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
670: signal(SIGINT, CompatInterrupt);
671: }
672: if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
673: signal(SIGTERM, CompatInterrupt);
674: }
675: if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
676: signal(SIGHUP, CompatInterrupt);
677: }
678: if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
679: signal(SIGQUIT, CompatInterrupt);
680: }
681:
682: for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
683: meta[(unsigned char) *cp] = 1;
684: }
685: /*
686: * The null character serves as a sentinel in the string.
687: */
688: meta[0] = 1;
689:
690: ENDNode = Targ_FindNode(".END", TARG_CREATE);
691: /*
692: * If the user has defined a .BEGIN target, execute the commands attached
693: * to it.
694: */
695: if (!queryFlag) {
696: gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
1.18 espie 697: if (gn != NULL) {
1.28 espie 698: Lst_Find(&gn->commands, CompatRunCommand, gn);
1.4 millert 699: if (gn->made == ERROR) {
700: printf("\n\nStop.\n");
701: exit(1);
702: }
1.1 deraadt 703: }
704: }
705:
706: /*
707: * For each entry in the list of targets to create, call CompatMake on
708: * it to create the thing. CompatMake will leave the 'made' field of gn
709: * in one of several states:
710: * UPTODATE gn was already up-to-date
711: * MADE gn was recreated successfully
712: * ERROR An error occurred while gn was being created
713: * ABORTED gn was not remade because one of its inferiors
714: * could not be made due to errors.
715: */
716: errors = 0;
1.19 espie 717: while ((gn = (GNode *)Lst_DeQueue(targs)) != NULL) {
1.26 espie 718: CompatMake(gn, gn);
1.1 deraadt 719:
720: if (gn->made == UPTODATE) {
721: printf ("`%s' is up to date.\n", gn->name);
722: } else if (gn->made == ABORTED) {
723: printf ("`%s' not remade because of errors.\n", gn->name);
724: errors += 1;
725: }
726: }
727:
728: /*
729: * If the user has defined a .END target, run its commands.
730: */
731: if (errors == 0) {
1.28 espie 732: Lst_Find(&ENDNode->commands, CompatRunCommand, gn);
1.1 deraadt 733: }
734: }