[BACK]Return to compat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/compat.c, Revision 1.49

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