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

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