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

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