[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.43

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