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