VirtualBox

Changeset 51 in kBuild for trunk/src/kmk/compat.c


Ignore:
Timestamp:
Apr 7, 2003 1:30:32 AM (22 years ago)
Author:
bird
Message:

kMk and porting to kLib.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/compat.c

    r35 r51  
    1818 * 3. All advertising materials mentioning features or use of this software
    1919 *    must display the following acknowledgement:
    20  *      This product includes software developed by the University of
    21  *      California, Berkeley and its contributors.
     20 *      This product includes software developed by the University of
     21 *      California, Berkeley and its contributors.
    2222 * 4. Neither the name of the University nor the names of its contributors
    2323 *    may be used to endorse or promote products derived from this software
     
    3939#ifndef lint
    4040#if 0
    41 static char sccsid[] = "@(#)compat.c    8.2 (Berkeley) 3/19/94";
     41static char sccsid[] = "@(#)compat.c    8.2 (Berkeley) 3/19/94";
    4242#else
    4343static const char rcsid[] =
    4444  "$FreeBSD: src/usr.bin/make/compat.c,v 1.16.2.2 2000/07/01 12:24:21 ps Exp $";
    4545#endif
     46#define KLIBFILEDEF rcsid
    4647#endif /* not lint */
    4748
    4849/*-
    4950 * compat.c --
    50  *      The routines in this file implement the full-compatibility
    51  *      mode of PMake. Most of the special functionality of PMake
    52  *      is available in this mode. Things not supported:
    53  *          - different shells.
    54  *          - friendly variable substitution.
     51 *      The routines in this file implement the full-compatibility
     52 *      mode of PMake. Most of the special functionality of PMake
     53 *      is available in this mode. Things not supported:
     54 *          - different shells.
     55 *          - friendly variable substitution.
    5556 *
    5657 * Interface:
    57  *      Compat_Run          Initialize things for this module and recreate
    58  *                          thems as need creatin'
     58 *      Compat_Run          Initialize things for this module and recreate
     59 *                          thems as need creatin'
    5960 */
    6061
     
    8788 */
    8889
    89 static char         meta[256];
    90 
    91 static GNode        *curTarg = NILGNODE;
    92 static GNode        *ENDNode;
     90static char         meta[256];
     91
     92static GNode        *curTarg = NILGNODE;
     93static GNode        *ENDNode;
    9394static void CompatInterrupt __P((int));
    9495static int CompatRunCommand __P((ClientData, ClientData));
     
    9697
    9798static char *sh_builtin[] = {
    98         "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
    99         "unalias", "umask", "unset", "wait", ":", 0};
     99        "alias", "cd", "eval", "exec", "exit", "read", "set", "ulimit",
     100        "unalias", "umask", "unset", "wait", ":", 0};
    100101
    101102/*-
    102103 *-----------------------------------------------------------------------
    103104 * CompatInterrupt --
    104  *      Interrupt the creation of the current target and remove it if
    105  *      it ain't precious.
     105 *      Interrupt the creation of the current target and remove it if
     106 *      it ain't precious.
    106107 *
    107108 * Results:
    108  *      None.
     109 *      None.
    109110 *
    110111 * Side Effects:
    111  *      The target is removed and the process exits. If .INTERRUPT exists,
    112  *      its commands are run first WITH INTERRUPTS IGNORED..
     112 *      The target is removed and the process exits. If .INTERRUPT exists,
     113 *      its commands are run first WITH INTERRUPTS IGNORED..
    113114 *
    114115 *-----------------------------------------------------------------------
     
    116117static void
    117118CompatInterrupt (signo)
    118     int     signo;
     119    int     signo;
    119120{
    120121    GNode   *gn;
    121122
    122123    if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
    123         char      *p1;
    124         char      *file = Var_Value (TARGET, curTarg, &p1);
    125 
    126         if (!noExecute && eunlink(file) != -1) {
    127             printf ("*** %s removed\n", file);
    128         }
    129         efree(p1);
    130 
    131         /*
    132         * Run .INTERRUPT only if hit with interrupt signal
    133         */
    134         if (signo == SIGINT) {
    135             gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    136             if (gn != NILGNODE) {
    137                 Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    138             }
    139         }
     124        char      *p1;
     125        char      *file = Var_Value (TARGET, curTarg, &p1);
     126
     127        if (!noExecute && eunlink(file) != -1) {
     128            printf ("*** %s removed\n", file);
     129        }
     130        efree(p1);
     131
     132        /*
     133        * Run .INTERRUPT only if hit with interrupt signal
     134        */
     135        if (signo == SIGINT) {
     136            gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
     137            if (gn != NILGNODE) {
     138                Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
     139            }
     140        }
    140141
    141142    }
    142143    #if !(defined(OS2) && defined(__IBMC__))
    143144    if (signo == SIGQUIT)
    144         exit(signo);
     145        exit(signo);
    145146    #endif
    146147    (void) signal(signo, SIG_DFL);
     
    152153 *-----------------------------------------------------------------------
    153154 * shellneed --
    154  *     
     155 *
    155156 * Results:
    156  *      Returns 1 if a specified line must be executed by the shell,
    157  *      0 if it can be run via execve, and -1 if the command is a no-op.
     157 *      Returns 1 if a specified line must be executed by the shell,
     158 *      0 if it can be run via execve, and -1 if the command is a no-op.
    158159 *
    159160 * Side Effects:
    160  *      None.
    161  *     
     161 *      None.
     162 *
    162163 *-----------------------------------------------------------------------
    163164 */
    164165static int
    165166shellneed (cmd)
    166         char *cmd;
     167        char *cmd;
    167168{
    168         char **av, **p;
    169         int ac;
    170 
    171         av = brk_string(cmd, &ac, TRUE);
    172         for(p = sh_builtin; *p != 0; p++)
    173                 if (strcmp(av[1], *p) == 0)
    174                         return (1);
    175         return (0);
     169        char **av, **p;
     170        int ac;
     171
     172        av = brk_string(cmd, &ac, TRUE);
     173        for(p = sh_builtin; *p != 0; p++)
     174                if (strcmp(av[1], *p) == 0)
     175                        return (1);
     176        return (0);
    176177}
    177178
     
    180181 *-----------------------------------------------------------------------
    181182 * CompatRunCommand --
    182  *      Execute the next command for a target. If the command returns an
    183  *      error, the node's made field is set to ERROR and creation stops.
     183 *      Execute the next command for a target. If the command returns an
     184 *      error, the node's made field is set to ERROR and creation stops.
    184185 *
    185186 * Results:
    186  *      0 if the command succeeded, 1 if an error occurred.
     187 *      0 if the command succeeded, 1 if an error occurred.
    187188 *
    188189 * Side Effects:
    189  *      The node's 'made' field may be set to ERROR.
     190 *      The node's 'made' field may be set to ERROR.
    190191 *
    191192 *-----------------------------------------------------------------------
     
    193194static int
    194195CompatRunCommand (cmdp, gnp)
    195     ClientData    cmdp;         /* Command to execute */
    196     ClientData    gnp;          /* Node from which the command came */
     196    ClientData    cmdp;         /* Command to execute */
     197    ClientData    gnp;          /* Node from which the command came */
    197198{
    198     char          *cmdStart;    /* Start of expanded command */
     199    char          *cmdStart;    /* Start of expanded command */
    199200    register char *cp;
    200     Boolean       silent,       /* Don't print command */
    201                   errCheck;     /* Check errors */
    202     int           reason;       /* Reason for child's death */
    203     int           status;       /* Description of child's death */
    204     int           cpid;         /* Child actually found */
    205     ReturnStatus  stat;         /* Status of fork */
    206     LstNode       cmdNode;      /* Node where current command is located */
    207     char          **av;         /* Argument vector for thing to exec */
    208     int           argc;         /* Number of arguments in av or 0 if not
    209                                 * dynamically allocated */
    210     Boolean       local;        /* TRUE if command should be executed
    211                                 * locally */
    212     int           internal;     /* Various values.. */
    213     char          *cmd = (char *) cmdp;
    214     GNode         *gn = (GNode *) gnp;
     201    Boolean       silent,       /* Don't print command */
     202                  errCheck;     /* Check errors */
     203    int           reason;       /* Reason for child's death */
     204    int           status;       /* Description of child's death */
     205    int           cpid;         /* Child actually found */
     206    ReturnStatus  stat;         /* Status of fork */
     207    LstNode       cmdNode;      /* Node where current command is located */
     208    char          **av;         /* Argument vector for thing to exec */
     209    int           argc;         /* Number of arguments in av or 0 if not
     210                                * dynamically allocated */
     211    Boolean       local;        /* TRUE if command should be executed
     212                                * locally */
     213    int           internal;     /* Various values.. */
     214    char          *cmd = (char *) cmdp;
     215    GNode         *gn = (GNode *) gnp;
    215216
    216217    /*
     
    236237
    237238    if (*cmdStart == '\0') {
    238         efree(cmdStart);
    239         Error("%s expands to empty string", cmd);
    240         return(0);
     239        efree(cmdStart);
     240        Error("%s expands to empty string", cmd);
     241        return(0);
    241242    } else {
    242         cmd = cmdStart;
     243        cmd = cmdStart;
    243244    }
    244245    Lst_Replace (cmdNode, (ClientData)cmdStart);
    245246
    246247    if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
    247         (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
    248         return(0);
     248        (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
     249        return(0);
    249250    } else if (strcmp(cmdStart, "...") == 0) {
    250         gn->type |= OP_SAVE_CMDS;
    251         return(0);
     251        gn->type |= OP_SAVE_CMDS;
     252        return(0);
    252253    }
    253254
    254255    while ((*cmd == '@') || (*cmd == '-')) {
    255         if (*cmd == '@') {
    256             silent = DEBUG(LOUD) ? FALSE : TRUE;
    257         } else {
    258             errCheck = FALSE;
    259         }
    260         cmd++;
     256        if (*cmd == '@') {
     257            silent = DEBUG(LOUD) ? FALSE : TRUE;
     258        } else {
     259            errCheck = FALSE;
     260        }
     261        cmd++;
    261262    }
    262263
    263264    while (isspace((unsigned char)*cmd))
    264         cmd++;
     265        cmd++;
    265266
    266267    /*
     
    270271     */
    271272    for (cp = cmd; !meta[(unsigned char)*cp]; cp++) {
    272         continue;
     273        continue;
    273274    }
    274275
     
    278279     */
    279280    if (!silent || noExecute) {
    280         printf ("%s\n", cmd);
    281         fflush(stdout);
     281        printf ("%s\n", cmd);
     282        fflush(stdout);
    282283    }
    283284
     
    287288     */
    288289    if (noExecute) {
    289         return (0);
     290        return (0);
    290291    }
    291292
    292293    if (*cp != '\0') {
    293         /*
    294         * If *cp isn't the null character, we hit a "meta" character and
    295         * need to pass the command off to the shell. We give the shell the
    296         * -e flag as well as -c if it's supposed to exit when it hits an
    297         * error.
    298         */
    299         static char     *shargv[4] = { "/bin/sh" };
    300 
    301         shargv[1] = (errCheck ? "-ec" : "-c");
    302         shargv[2] = cmd;
    303         shargv[3] = (char *)NULL;
    304         av = shargv;
    305         argc = 0;
     294        /*
     295        * If *cp isn't the null character, we hit a "meta" character and
     296        * need to pass the command off to the shell. We give the shell the
     297        * -e flag as well as -c if it's supposed to exit when it hits an
     298        * error.
     299        */
     300        static char     *shargv[4] = { "/bin/sh" };
     301
     302        shargv[1] = (errCheck ? "-ec" : "-c");
     303        shargv[2] = cmd;
     304        shargv[3] = (char *)NULL;
     305        av = shargv;
     306        argc = 0;
    306307    } else if ((internal = shellneed(cmd))) {
    307         /*
    308         * This command must be passed by the shell for other reasons..
    309         * or.. possibly not at all.
    310         */
    311         static char     *shargv[4] = { "/bin/sh" };
    312 
    313         if (internal == -1) {
    314                 /* Command does not need to be executed */
    315                 return (0);
    316         }
    317 
    318         shargv[1] = (errCheck ? "-ec" : "-c");
    319         shargv[2] = cmd;
    320         shargv[3] = (char *)NULL;
    321         av = shargv;
    322         argc = 0;
     308        /*
     309        * This command must be passed by the shell for other reasons..
     310        * or.. possibly not at all.
     311        */
     312        static char     *shargv[4] = { "/bin/sh" };
     313
     314        if (internal == -1) {
     315                /* Command does not need to be executed */
     316                return (0);
     317        }
     318
     319        shargv[1] = (errCheck ? "-ec" : "-c");
     320        shargv[2] = cmd;
     321        shargv[3] = (char *)NULL;
     322        av = shargv;
     323        argc = 0;
    323324    } else {
    324         /*
    325         * No meta-characters, so no need to exec a shell. Break the command
    326         * into words to form an argument vector we can execute.
    327         * brk_string sticks our name in av[0], so we have to
    328         * skip over it...
    329         */
    330         av = brk_string(cmd, &argc, TRUE);
    331         av += 1;
     325        /*
     326        * No meta-characters, so no need to exec a shell. Break the command
     327        * into words to form an argument vector we can execute.
     328        * brk_string sticks our name in av[0], so we have to
     329        * skip over it...
     330        */
     331        av = brk_string(cmd, &argc, TRUE);
     332        av += 1;
    332333    }
    333334
     
    342343    cpid = vfork();
    343344    if (cpid < 0) {
    344         Fatal("Could not fork");
     345        Fatal("Could not fork");
    345346    }
    346347    if (cpid == 0) {
    347         if (local) {
    348             execvp(av[0], av);
    349             (void) write (2, av[0], strlen (av[0]));
    350             (void) write (2, ":", 1);
    351             (void) write (2, strerror(errno), strlen(strerror(errno)));
    352             (void) write (2, "\n", 1);
    353         } else {
    354             (void)execv(av[0], av);
    355         }
    356         exit(1);
     348        if (local) {
     349            execvp(av[0], av);
     350            (void) write (2, av[0], strlen (av[0]));
     351            (void) write (2, ":", 1);
     352            (void) write (2, strerror(errno), strlen(strerror(errno)));
     353            (void) write (2, "\n", 1);
     354        } else {
     355            (void)execv(av[0], av);
     356        }
     357        exit(1);
    357358    }
    358359#endif
     
    365366     */
    366367    if (!DEBUG(GRAPH2)) {
    367         efree(cmdStart);
    368         Lst_Replace (cmdNode, cmdp);
     368        efree(cmdStart);
     369        Lst_Replace (cmdNode, cmdp);
    369370    }
    370371
     
    374375    while (1) {
    375376
    376         while ((stat = wait(&reason)) != cpid) {
    377             if (stat == -1 && errno != EINTR) {
    378                 break;
    379             }
    380         }
    381 
    382         if (stat > -1) {
    383             if (WIFSTOPPED(reason)) {
    384                 status = WSTOPSIG(reason);              /* stopped */
    385             } else if (WIFEXITED(reason)) {
    386                 status = WEXITSTATUS(reason);           /* exited */
    387                 if (status != 0) {
    388                     printf ("*** Error code %d", status);
    389                 }
    390             } else {
    391                 status = WTERMSIG(reason);              /* signaled */
    392                 printf ("*** Signal %d", status);
    393             }
    394 
    395 
    396             if (!WIFEXITED(reason) || (status != 0)) {
    397                 if (errCheck) {
    398                     gn->made = ERROR;
    399                     if (keepgoing) {
    400                         /*
    401                         * Abort the current target, but let others
    402                         * continue.
    403                         */
    404                         printf (" (continuing)\n");
    405                     }
    406                 } else {
    407                     /*
    408                      * Continue executing commands for this target.
    409                      * If we return 0, this will happen...
    410                      */
    411                     printf (" (ignored)\n");
    412                     status = 0;
    413                 }
    414             }
    415             break;
    416         } else {
    417             Fatal ("error in wait: %d", stat);
    418             /*NOTREACHED*/
    419         }
     377        while ((stat = wait(&reason)) != cpid) {
     378            if (stat == -1 && errno != EINTR) {
     379                break;
     380            }
     381        }
     382
     383        if (stat > -1) {
     384            if (WIFSTOPPED(reason)) {
     385                status = WSTOPSIG(reason);              /* stopped */
     386            } else if (WIFEXITED(reason)) {
     387                status = WEXITSTATUS(reason);           /* exited */
     388                if (status != 0) {
     389                    printf ("*** Error code %d", status);
     390                }
     391            } else {
     392                status = WTERMSIG(reason);              /* signaled */
     393                printf ("*** Signal %d", status);
     394            }
     395
     396
     397            if (!WIFEXITED(reason) || (status != 0)) {
     398                if (errCheck) {
     399                    gn->made = ERROR;
     400                    if (keepgoing) {
     401                        /*
     402                        * Abort the current target, but let others
     403                        * continue.
     404                        */
     405                        printf (" (continuing)\n");
     406                    }
     407                } else {
     408                    /*
     409                     * Continue executing commands for this target.
     410                     * If we return 0, this will happen...
     411                     */
     412                    printf (" (ignored)\n");
     413                    status = 0;
     414                }
     415            }
     416            break;
     417        } else {
     418            Fatal ("error in wait: %d", stat);
     419            /*NOTREACHED*/
     420        }
    420421    }
    421422
     
    427428 *-----------------------------------------------------------------------
    428429 * CompatMake --
    429  *      Make a target.
     430 *      Make a target.
    430431 *
    431432 * Results:
    432  *      0
     433 *      0
    433434 *
    434435 * Side Effects:
    435  *      If an error is detected and not being ignored, the process exits.
     436 *      If an error is detected and not being ignored, the process exits.
    436437 *
    437438 *-----------------------------------------------------------------------
     
    439440static int
    440441CompatMake (gnp, pgnp)
    441     ClientData  gnp;        /* The node to make */
    442     ClientData  pgnp;       /* Parent to abort if necessary */
     442    ClientData  gnp;        /* The node to make */
     443    ClientData  pgnp;       /* Parent to abort if necessary */
    443444{
    444445    GNode *gn = (GNode *) gnp;
    445446    GNode *pgn = (GNode *) pgnp;
    446447    if (gn->type & OP_USE) {
    447         Make_HandleUse(gn, pgn);
     448        Make_HandleUse(gn, pgn);
    448449    } else if (gn->made == UNMADE) {
    449         /*
    450         * First mark ourselves to be made, then apply whatever transformations
    451         * the suffix module thinks are necessary. Once that's done, we can
    452         * descend and make all our children. If any of them has an error
    453         * but the -k flag was given, our 'make' field will be set FALSE again.
    454         * This is our signal to not attempt to do anything but abort our
    455         * parent as well.
    456         */
    457         gn->make = TRUE;
    458         gn->made = BEINGMADE;
    459         Suff_FindDeps (gn);
    460         Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
    461         if (!gn->make) {
    462             gn->made = ABORTED;
    463             pgn->make = FALSE;
    464             return (0);
    465         }
    466 
    467         if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    468             char *p1;
    469             Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
    470             efree(p1);
    471         }
    472 
    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);
    506 
    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;
    525                 Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
    526                 curTarg = NILGNODE;
    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;
     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            efree(p1);
     472        }
     473
     474        /*
     475        * All the children were made ok. Now cmtime contains the modification
     476        * time of the newest child, we need to find out if we exist and when
     477        * we were modified last. The criteria for datedness are defined by the
     478        * Make_OODate function.
     479        */
     480        if (DEBUG(MAKE)) {
     481            printf("Examining %s...", gn->name);
     482        }
     483        if (! Make_OODate(gn)) {
     484            gn->made = UPTODATE;
     485            if (DEBUG(MAKE)) {
     486                printf("up-to-date.\n");
     487            }
     488            return (0);
     489        } else if (DEBUG(MAKE)) {
     490            printf("out-of-date.\n");
     491        }
     492
     493        /*
     494        * If the user is just seeing if something is out-of-date, exit now
     495        * to tell him/her "yes".
     496        */
     497        if (queryFlag) {
     498            exit (-1);
     499        }
     500
     501        /*
     502        * We need to be re-made. We also have to make sure we've got a $?
     503        * variable. To be nice, we also define the $> variable using
     504        * Make_DoAllVar().
     505        */
     506        Make_DoAllVar(gn);
     507
     508        /*
     509        * Alter our type to tell if errors should be ignored or things
     510        * should not be printed so CompatRunCommand knows what to do.
     511        */
     512        if (Targ_Ignore (gn)) {
     513            gn->type |= OP_IGNORE;
     514        }
     515        if (Targ_Silent (gn)) {
     516            gn->type |= OP_SILENT;
     517        }
     518
     519        if (Job_CheckCommands (gn, Fatal)) {
     520            /*
     521             * Our commands are ok, but we still have to worry about the -t
     522             * flag...
     523             */
     524            if (!touchFlag) {
     525                curTarg = gn;
     526                Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
     527                curTarg = NILGNODE;
     528            } else {
     529                Job_Touch (gn, gn->type & OP_SILENT);
     530            }
     531        } else {
     532            gn->made = ERROR;
     533        }
     534
     535        if (gn->made != ERROR) {
     536            /*
     537             * If the node was made successfully, mark it so, update
     538             * its modification time and timestamp all its parents. Note
     539             * that for .ZEROTIME targets, the timestamping isn't done.
     540             * This is to keep its state from affecting that of its parent.
     541             */
     542            gn->made = MADE;
    542543#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             }
     544            /*
     545             * We can't re-stat the thing, but we can at least take care of
     546             * rules where a target depends on a source that actually creates
     547             * the target, but only if it has changed, e.g.
     548             *
     549             * parse.h : parse.o
     550             *
     551             * parse.o : parse.y
     552             *          yacc -d parse.y
     553             *          cc -c y.tab.c
     554             *          mv y.tab.o parse.o
     555             *          cmp -s y.tab.h parse.h || mv y.tab.h parse.h
     556             *
     557             * In this case, if the definitions produced by yacc haven't
     558             * changed from before, parse.h won't have been updated and
     559             * gn->mtime will reflect the current modification time for
     560             * parse.h. This is something of a kludge, I admit, but it's a
     561             * useful one..
     562             *
     563             * XXX: People like to use a rule like
     564             *
     565             * FRC:
     566             *
     567             * To force things that depend on FRC to be made, so we have to
     568             * check for gn->children being empty as well...
     569             */
     570            if (!Lst_IsEmpty(gn->commands) || Lst_IsEmpty(gn->children)) {
     571                gn->mtime = now;
     572            }
    572573#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              */
    591             if (noExecute || Dir_MTime(gn) == 0) {
    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             }
     574            /*
     575             * This is what Make does and it's actually a good thing, as it
     576             * allows rules like
     577             *
     578             *  cmp -s y.tab.h parse.h || cp y.tab.h parse.h
     579             *
     580             * to function as intended. Unfortunately, thanks to the stateless
     581             * nature of NFS (and the speed of this program), there are times
     582             * when the modification time of a file created on a remote
     583             * machine will not be modified before the stat() implied by
     584             * the Dir_MTime occurs, thus leading us to believe that the file
     585             * is unchanged, wreaking havoc with files that depend on this one.
     586             *
     587             * I have decided it is better to make too much than to make too
     588             * little, so this stuff is commented out unless you're sure it's
     589             * ok.
     590             * -- ardeb 1/12/88
     591             */
     592            if (noExecute || Dir_MTime(gn) == 0) {
     593                gn->mtime = now;
     594            }
     595            if (gn->cmtime > gn->mtime)
     596                gn->mtime = gn->cmtime;
     597            if (DEBUG(MAKE)) {
     598                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
     599            }
    599600#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 {
    607             char *p1;
    608 
    609             printf ("\n\nStop in %s.\n", Var_Value(".CURDIR", gn, &p1));
    610             efree(p1);
    611             exit (1);
    612         }
     601            if (!(gn->type & OP_EXEC)) {
     602                pgn->childMade = TRUE;
     603                Make_TimeStamp(pgn, gn);
     604            }
     605        } else if (keepgoing) {
     606            pgn->make = FALSE;
     607        } else {
     608            char *p1;
     609
     610            printf ("\n\nStop in %s.\n", Var_Value(".CURDIR", gn, &p1));
     611            efree(p1);
     612            exit (1);
     613        }
    613614    } else if (gn->made == ERROR) {
    614         /*
    615         * Already had an error when making this beastie. Tell the parent
    616         * to abort.
    617         */
    618         pgn->make = FALSE;
     615        /*
     616        * Already had an error when making this beastie. Tell the parent
     617        * to abort.
     618        */
     619        pgn->make = FALSE;
    619620    } else {
    620         if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    621             char *p1;
    622             Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
    623             efree(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         }
     621        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
     622            char *p1;
     623            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
     624            efree(p1);
     625        }
     626        switch(gn->made) {
     627            case BEINGMADE:
     628                Error("Graph cycles through %s\n", gn->name);
     629                gn->made = ERROR;
     630                pgn->make = FALSE;
     631                break;
     632            case MADE:
     633                if ((gn->type & OP_EXEC) == 0) {
     634                    pgn->childMade = TRUE;
     635                    Make_TimeStamp(pgn, gn);
     636                }
     637                break;
     638            case UPTODATE:
     639                if ((gn->type & OP_EXEC) == 0) {
     640                    Make_TimeStamp(pgn, gn);
     641                }
     642                break;
     643            default:
     644                break;
     645        }
    645646    }
    646647
     
    652653 *-----------------------------------------------------------------------
    653654 * Compat_Run --
    654  *      Initialize this mode and start making.
     655 *      Initialize this mode and start making.
    655656 *
    656657 * Results:
    657  *      None.
     658 *      None.
    658659 *
    659660 * Side Effects:
    660  *      Guess what?
     661 *      Guess what?
    661662 *
    662663 *-----------------------------------------------------------------------
     
    664665void
    665666Compat_Run(targs)
    666     Lst           targs;    /* List of target nodes to re-create */
     667    Lst           targs;    /* List of target nodes to re-create */
    667668{
    668     char          *cp;      /* Pointer to string of shell meta-characters */
    669     GNode         *gn = NULL;/* Current root target */
    670     int           errors;   /* Number of targets not remade due to errors */
     669    char          *cp;      /* Pointer to string of shell meta-characters */
     670    GNode         *gn = NULL;/* Current root target */
     671    int           errors;   /* Number of targets not remade due to errors */
    671672
    672673    if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
    673         signal(SIGINT, CompatInterrupt);
     674        signal(SIGINT, CompatInterrupt);
    674675    }
    675676    if (signal(SIGTERM, SIG_IGN) != SIG_IGN) {
    676         signal(SIGTERM, CompatInterrupt);
     677        signal(SIGTERM, CompatInterrupt);
    677678    }
    678679    #if !(defined(OS2) && defined(__IBMC__))
    679680    if (signal(SIGHUP, SIG_IGN) != SIG_IGN) {
    680         signal(SIGHUP, CompatInterrupt);
     681        signal(SIGHUP, CompatInterrupt);
    681682    }
    682683    #endif
    683684    #if !(defined(OS2) && defined(__IBMC__))
    684685    if (signal(SIGQUIT, SIG_IGN) != SIG_IGN) {
    685         signal(SIGQUIT, CompatInterrupt);
     686        signal(SIGQUIT, CompatInterrupt);
    686687    }
    687688    #endif
    688689
    689690    for (cp = "#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
    690         meta[(unsigned char) *cp] = 1;
     691        meta[(unsigned char) *cp] = 1;
    691692    }
    692693    /*
     
    701702     */
    702703    if (!queryFlag) {
    703         gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    704         if (gn != NILGNODE) {
    705             Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
     704        gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
     705        if (gn != NILGNODE) {
     706            Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    706707            if (gn->made == ERROR) {
    707708                printf("\n\nStop.\n");
    708709                exit(1);
    709710            }
    710         }
     711        }
    711712    }
    712713
     
    715716     * it to create the thing. CompatMake will leave the 'made' field of gn
    716717     * in one of several states:
    717      *      UPTODATE        gn was already up-to-date
    718      *      MADE            gn was recreated successfully
    719      *      ERROR           An error occurred while gn was being created
    720      *      ABORTED         gn was not remade because one of its inferiors
    721      *                      could not be made due to errors.
     718     *      UPTODATE        gn was already up-to-date
     719     *      MADE            gn was recreated successfully
     720     *      ERROR           An error occurred while gn was being created
     721     *      ABORTED         gn was not remade because one of its inferiors
     722     *                      could not be made due to errors.
    722723     */
    723724    errors = 0;
    724725    while (!Lst_IsEmpty (targs)) {
    725         gn = (GNode *) Lst_DeQueue (targs);
    726         CompatMake (gn, gn);
    727 
    728         if (gn->made == UPTODATE) {
    729             printf ("`%s' is up to date.\n", gn->name);
    730         } else if (gn->made == ABORTED) {
    731             printf ("`%s' not remade because of errors.\n", gn->name);
    732             errors += 1;
    733         }
     726        gn = (GNode *) Lst_DeQueue (targs);
     727        CompatMake (gn, gn);
     728
     729        if (gn->made == UPTODATE) {
     730            printf ("`%s' is up to date.\n", gn->name);
     731        } else if (gn->made == ABORTED) {
     732            printf ("`%s' not remade because of errors.\n", gn->name);
     733            errors += 1;
     734        }
    734735    }
    735736
     
    738739     */
    739740    if (errors == 0) {
    740         Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
     741        Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
    741742    }
    742743}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette