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

1.23    ! espie       1: /*     $OpenBSD: compat.c,v 1.22 2000/02/02 13:47:47 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.23    ! espie      46: static char rcsid[] = "$OpenBSD: compat.c,v 1.22 2000/02/02 13:47:47 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));
                     87: static int CompatRunCommand __P((ClientData, ClientData));
                     88: static int CompatMake __P((ClientData, ClientData));
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.15      espie     113:        char      *file = Var_Value(TARGET, 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.23    ! espie     125:                Lst_ForEach(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:
                    194:  *     0 if the command succeeded, 1 if an error occurred.
                    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)
                    203:     ClientData    cmdp;                /* Command to execute */
                    204:     ClientData    gnp;         /* Node from which the command came */
                    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.23    ! 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);
                    248:        return(0);
                    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.23    ! espie     255:        Lst_AtEnd(ENDNode->commands, cmdStart);
1.1       deraadt   256:        return(0);
                    257:     } else if (strcmp(cmdStart, "...") == 0) {
                    258:        gn->type |= OP_SAVE_CMDS;
                    259:        return(0);
                    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:      */
                    296:     if (noExecute) {
                    297:        return (0);
                    298:     }
1.4       millert   299:
1.1       deraadt   300:     if (*cp != '\0') {
                    301:        /*
                    302:         * If *cp isn't the null character, we hit a "meta" character and
                    303:         * need to pass the command off to the shell. We give the shell the
                    304:         * -e flag as well as -c if it's supposed to exit when it hits an
                    305:         * error.
                    306:         */
1.10      deraadt   307:
                    308:        shargv[1] = (errCheck ? "-ec" : "-c");
                    309:        shargv[2] = cmd;
                    310:        shargv[3] = (char *)NULL;
                    311:        av = shargv;
                    312:        argc = 0;
1.12      espie     313:     } else {
1.10      deraadt   314:        /*
1.12      espie     315:         * No meta-characters, so probably no need to exec a shell.
                    316:         * Break the command into words to form an argument vector
                    317:         * we can execute.
1.10      deraadt   318:         */
1.12      espie     319:        av = brk_string(cmd, &argc, TRUE, &bp);
                    320:        switch(shellneed(av)) {
                    321:        case -1: /* handled internally */
                    322:                free(bp);
                    323:                free(av);
                    324:                return 0;
                    325:        case 1:
                    326:                shargv[1] = (errCheck ? "-ec" : "-c");
                    327:                shargv[2] = cmd;
                    328:                shargv[3] = (char *)NULL;
1.14      espie     329:                free(bp);
                    330:                free(av);
                    331:                bp = NULL;
1.12      espie     332:                av = shargv;
                    333:                argc = 0;
                    334:                break;
                    335:        default: /* nothing needed */
                    336:                break;
1.10      deraadt   337:        }
1.1       deraadt   338:     }
1.4       millert   339:
1.1       deraadt   340:     local = TRUE;
                    341:
                    342:     /*
                    343:      * Fork and execute the single command. If the fork fails, we abort.
                    344:      */
                    345:     cpid = vfork();
                    346:     if (cpid < 0) {
                    347:        Fatal("Could not fork");
                    348:     }
                    349:     if (cpid == 0) {
                    350:        if (local) {
                    351:            execvp(av[0], av);
1.17      espie     352:            if (errno == ENOENT)
                    353:                fprintf(stderr, "%s: not found\n", av[0]);
                    354:            else
                    355:                perror(av[0]);
1.1       deraadt   356:        } else {
                    357:            (void)execv(av[0], av);
                    358:        }
1.9       deraadt   359:        _exit(1);
1.1       deraadt   360:     }
1.12      espie     361:     if (bp) {
                    362:        free(av);
                    363:        free(bp);
                    364:     }
1.1       deraadt   365:     free(cmdStart);
1.23    ! espie     366:     Lst_Replace(cmdNode, NULL);
1.4       millert   367:
1.1       deraadt   368:     /*
                    369:      * The child is off and running. Now all we can do is wait...
                    370:      */
                    371:     while (1) {
                    372:
1.2       deraadt   373:        while ((stat = wait(&reason)) != cpid) {
1.1       deraadt   374:            if (stat == -1 && errno != EINTR) {
                    375:                break;
                    376:            }
                    377:        }
1.4       millert   378:
1.1       deraadt   379:        if (stat > -1) {
                    380:            if (WIFSTOPPED(reason)) {
1.2       deraadt   381:                status = WSTOPSIG(reason);              /* stopped */
1.1       deraadt   382:            } else if (WIFEXITED(reason)) {
1.2       deraadt   383:                status = WEXITSTATUS(reason);           /* exited */
1.1       deraadt   384:                if (status != 0) {
                    385:                    printf ("*** Error code %d", status);
                    386:                }
                    387:            } else {
1.2       deraadt   388:                status = WTERMSIG(reason);              /* signaled */
1.1       deraadt   389:                printf ("*** Signal %d", status);
1.4       millert   390:            }
                    391:
1.1       deraadt   392:
                    393:            if (!WIFEXITED(reason) || (status != 0)) {
                    394:                if (errCheck) {
                    395:                    gn->made = ERROR;
                    396:                    if (keepgoing) {
                    397:                        /*
                    398:                         * Abort the current target, but let others
                    399:                         * continue.
                    400:                         */
                    401:                        printf (" (continuing)\n");
                    402:                    }
                    403:                } else {
                    404:                    /*
                    405:                     * Continue executing commands for this target.
                    406:                     * If we return 0, this will happen...
                    407:                     */
                    408:                    printf (" (ignored)\n");
                    409:                    status = 0;
                    410:                }
                    411:            }
                    412:            break;
                    413:        } else {
                    414:            Fatal ("error in wait: %d", stat);
                    415:            /*NOTREACHED*/
                    416:        }
                    417:     }
                    418:
                    419:     return (status);
                    420: }
                    421: 
                    422: /*-
                    423:  *-----------------------------------------------------------------------
                    424:  * CompatMake --
                    425:  *     Make a target.
                    426:  *
                    427:  * Results:
                    428:  *     0
                    429:  *
                    430:  * Side Effects:
                    431:  *     If an error is detected and not being ignored, the process exits.
                    432:  *
                    433:  *-----------------------------------------------------------------------
                    434:  */
                    435: static int
                    436: CompatMake (gnp, pgnp)
                    437:     ClientData gnp;        /* The node to make */
                    438:     ClientData  pgnp;      /* Parent to abort if necessary */
                    439: {
                    440:     GNode *gn = (GNode *) gnp;
                    441:     GNode *pgn = (GNode *) pgnp;
1.5       millert   442:
1.7       deraadt   443:     if (pgn->type & OP_MADE) {
                    444:        (void) Dir_MTime(gn);
                    445:        gn->made = UPTODATE;
                    446:     }
                    447:
1.8       millert   448:     if (gn->type & OP_USE) {
                    449:        Make_HandleUse(gn, pgn);
                    450:     } else if (gn->made == UNMADE) {
1.1       deraadt   451:        /*
                    452:         * First mark ourselves to be made, then apply whatever transformations
                    453:         * the suffix module thinks are necessary. Once that's done, we can
                    454:         * descend and make all our children. If any of them has an error
                    455:         * but the -k flag was given, our 'make' field will be set FALSE again.
                    456:         * This is our signal to not attempt to do anything but abort our
                    457:         * parent as well.
                    458:         */
                    459:        gn->make = TRUE;
                    460:        gn->made = BEINGMADE;
                    461:        Suff_FindDeps (gn);
1.23    ! espie     462:        Lst_ForEach(gn->children, CompatMake, gn);
1.1       deraadt   463:        if (!gn->make) {
                    464:            gn->made = ABORTED;
                    465:            pgn->make = FALSE;
                    466:            return (0);
                    467:        }
                    468:
1.18      espie     469:        if (Lst_Member (gn->iParents, pgn) != NULL) {
1.15      espie     470:            Var_Set(IMPSRC, Var_Value(TARGET, gn), pgn);
1.1       deraadt   471:        }
1.4       millert   472:
1.1       deraadt   473:        /*
                    474:         * All the children were made ok. Now cmtime contains the modification
                    475:         * time of the newest child, we need to find out if we exist and when
                    476:         * we were modified last. The criteria for datedness are defined by the
                    477:         * Make_OODate function.
                    478:         */
                    479:        if (DEBUG(MAKE)) {
                    480:            printf("Examining %s...", gn->name);
                    481:        }
                    482:        if (! Make_OODate(gn)) {
                    483:            gn->made = UPTODATE;
                    484:            if (DEBUG(MAKE)) {
                    485:                printf("up-to-date.\n");
                    486:            }
                    487:            return (0);
                    488:        } else if (DEBUG(MAKE)) {
                    489:            printf("out-of-date.\n");
                    490:        }
                    491:
                    492:        /*
                    493:         * If the user is just seeing if something is out-of-date, exit now
                    494:         * to tell him/her "yes".
                    495:         */
                    496:        if (queryFlag) {
                    497:            exit (-1);
                    498:        }
                    499:
                    500:        /*
                    501:         * We need to be re-made. We also have to make sure we've got a $?
                    502:         * variable. To be nice, we also define the $> variable using
                    503:         * Make_DoAllVar().
                    504:         */
                    505:        Make_DoAllVar(gn);
1.4       millert   506:
1.1       deraadt   507:        /*
                    508:         * Alter our type to tell if errors should be ignored or things
                    509:         * should not be printed so CompatRunCommand knows what to do.
                    510:         */
                    511:        if (Targ_Ignore (gn)) {
                    512:            gn->type |= OP_IGNORE;
                    513:        }
                    514:        if (Targ_Silent (gn)) {
                    515:            gn->type |= OP_SILENT;
                    516:        }
                    517:
                    518:        if (Job_CheckCommands (gn, Fatal)) {
                    519:            /*
                    520:             * Our commands are ok, but we still have to worry about the -t
                    521:             * flag...
                    522:             */
                    523:            if (!touchFlag) {
                    524:                curTarg = gn;
1.23    ! espie     525:                Lst_ForEach(gn->commands, CompatRunCommand, gn);
1.18      espie     526:                curTarg = NULL;
1.1       deraadt   527:            } else {
                    528:                Job_Touch (gn, gn->type & OP_SILENT);
                    529:            }
                    530:        } else {
                    531:            gn->made = ERROR;
                    532:        }
                    533:
                    534:        if (gn->made != ERROR) {
                    535:            /*
                    536:             * If the node was made successfully, mark it so, update
                    537:             * its modification time and timestamp all its parents. Note
                    538:             * that for .ZEROTIME targets, the timestamping isn't done.
                    539:             * This is to keep its state from affecting that of its parent.
                    540:             */
                    541:            gn->made = MADE;
                    542: #ifndef RECHECK
                    543:            /*
                    544:             * We can't re-stat the thing, but we can at least take care of
                    545:             * rules where a target depends on a source that actually creates
                    546:             * the target, but only if it has changed, e.g.
                    547:             *
                    548:             * parse.h : parse.o
                    549:             *
                    550:             * parse.o : parse.y
                    551:             *          yacc -d parse.y
                    552:             *          cc -c y.tab.c
                    553:             *          mv y.tab.o parse.o
                    554:             *          cmp -s y.tab.h parse.h || mv y.tab.h parse.h
                    555:             *
                    556:             * In this case, if the definitions produced by yacc haven't
                    557:             * changed from before, parse.h won't have been updated and
                    558:             * gn->mtime will reflect the current modification time for
                    559:             * parse.h. This is something of a kludge, I admit, but it's a
                    560:             * useful one..
                    561:             *
                    562:             * XXX: People like to use a rule like
                    563:             *
                    564:             * FRC:
                    565:             *
                    566:             * To force things that depend on FRC to be made, so we have to
                    567:             * check for gn->children being empty as well...
                    568:             */
                    569:            if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
                    570:                gn->mtime = now;
                    571:            }
                    572: #else
                    573:            /*
                    574:             * This is what Make does and it's actually a good thing, as it
                    575:             * allows rules like
                    576:             *
                    577:             *  cmp -s y.tab.h parse.h || cp y.tab.h parse.h
                    578:             *
                    579:             * to function as intended. Unfortunately, thanks to the stateless
                    580:             * nature of NFS (and the speed of this program), there are times
                    581:             * when the modification time of a file created on a remote
                    582:             * machine will not be modified before the stat() implied by
                    583:             * the Dir_MTime occurs, thus leading us to believe that the file
                    584:             * is unchanged, wreaking havoc with files that depend on this one.
                    585:             *
                    586:             * I have decided it is better to make too much than to make too
                    587:             * little, so this stuff is commented out unless you're sure it's
                    588:             * ok.
                    589:             * -- ardeb 1/12/88
                    590:             */
1.22      espie     591:            if (noExecute || Dir_MTime(gn) == FALSE) {
1.1       deraadt   592:                gn->mtime = now;
                    593:            }
                    594:            if (gn->cmtime > gn->mtime)
                    595:                gn->mtime = gn->cmtime;
                    596:            if (DEBUG(MAKE)) {
                    597:                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
                    598:            }
                    599: #endif
                    600:            if (!(gn->type & OP_EXEC)) {
                    601:                pgn->childMade = TRUE;
                    602:                Make_TimeStamp(pgn, gn);
                    603:            }
                    604:        } else if (keepgoing) {
                    605:            pgn->make = FALSE;
                    606:        } else {
1.15      espie     607:            printf ("\n\nStop in %s.\n", Var_Value(".CURDIR", gn));
1.1       deraadt   608:            exit (1);
                    609:        }
                    610:     } else if (gn->made == ERROR) {
                    611:        /*
                    612:         * Already had an error when making this beastie. Tell the parent
                    613:         * to abort.
                    614:         */
                    615:        pgn->make = FALSE;
                    616:     } else {
1.18      espie     617:        if (Lst_Member (gn->iParents, pgn) != NULL)
1.15      espie     618:            Var_Set (IMPSRC, Var_Value(TARGET, gn), pgn);
1.1       deraadt   619:        switch(gn->made) {
                    620:            case BEINGMADE:
                    621:                Error("Graph cycles through %s\n", gn->name);
                    622:                gn->made = ERROR;
                    623:                pgn->make = FALSE;
                    624:                break;
                    625:            case MADE:
                    626:                if ((gn->type & OP_EXEC) == 0) {
                    627:                    pgn->childMade = TRUE;
                    628:                    Make_TimeStamp(pgn, gn);
                    629:                }
                    630:                break;
                    631:            case UPTODATE:
                    632:                if ((gn->type & OP_EXEC) == 0) {
                    633:                    Make_TimeStamp(pgn, gn);
                    634:                }
                    635:                break;
                    636:            default:
                    637:                break;
                    638:        }
                    639:     }
                    640:
                    641:     return (0);
                    642: }
1.4       millert   643: 
1.1       deraadt   644: /*-
                    645:  *-----------------------------------------------------------------------
                    646:  * Compat_Run --
                    647:  *     Initialize this mode and start making.
                    648:  *
                    649:  * Results:
                    650:  *     None.
                    651:  *
                    652:  * Side Effects:
                    653:  *     Guess what?
                    654:  *
                    655:  *-----------------------------------------------------------------------
                    656:  */
                    657: void
                    658: Compat_Run(targs)
                    659:     Lst                  targs;    /* List of target nodes to re-create */
                    660: {
                    661:     char         *cp;      /* Pointer to string of shell meta-characters */
                    662:     GNode        *gn = NULL;/* Current root target */
                    663:     int                  errors;   /* Number of targets not remade due to errors */
                    664:
                    665:     if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
                    666:        signal(SIGINT, CompatInterrupt);
                    667:     }
                    668:     if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
                    669:        signal(SIGTERM, CompatInterrupt);
                    670:     }
                    671:     if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
                    672:        signal(SIGHUP, CompatInterrupt);
                    673:     }
                    674:     if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
                    675:        signal(SIGQUIT, CompatInterrupt);
                    676:     }
                    677:
                    678:     for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
                    679:        meta[(unsigned char) *cp] = 1;
                    680:     }
                    681:     /*
                    682:      * The null character serves as a sentinel in the string.
                    683:      */
                    684:     meta[0] = 1;
                    685:
                    686:     ENDNode = Targ_FindNode(".END", TARG_CREATE);
                    687:     /*
                    688:      * If the user has defined a .BEGIN target, execute the commands attached
                    689:      * to it.
                    690:      */
                    691:     if (!queryFlag) {
                    692:        gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
1.18      espie     693:        if (gn != NULL) {
1.23    ! espie     694:            Lst_ForEach(gn->commands, CompatRunCommand, gn);
1.4       millert   695:             if (gn->made == ERROR) {
                    696:                 printf("\n\nStop.\n");
                    697:                 exit(1);
                    698:             }
1.1       deraadt   699:        }
                    700:     }
                    701:
                    702:     /*
                    703:      * For each entry in the list of targets to create, call CompatMake on
                    704:      * it to create the thing. CompatMake will leave the 'made' field of gn
                    705:      * in one of several states:
                    706:      *     UPTODATE        gn was already up-to-date
                    707:      *     MADE            gn was recreated successfully
                    708:      *     ERROR           An error occurred while gn was being created
                    709:      *     ABORTED         gn was not remade because one of its inferiors
                    710:      *                     could not be made due to errors.
                    711:      */
                    712:     errors = 0;
1.19      espie     713:     while ((gn = (GNode *)Lst_DeQueue(targs)) != NULL) {
1.1       deraadt   714:        CompatMake (gn, gn);
                    715:
                    716:        if (gn->made == UPTODATE) {
                    717:            printf ("`%s' is up to date.\n", gn->name);
                    718:        } else if (gn->made == ABORTED) {
                    719:            printf ("`%s' not remade because of errors.\n", gn->name);
                    720:            errors += 1;
                    721:        }
                    722:     }
                    723:
                    724:     /*
                    725:      * If the user has defined a .END target, run its commands.
                    726:      */
                    727:     if (errors == 0) {
1.23    ! espie     728:        Lst_ForEach(ENDNode->commands, CompatRunCommand, gn);
1.1       deraadt   729:     }
                    730: }