Ignore:
Timestamp:
Nov 26, 2002, 10:24:54 PM (23 years ago)
Author:
bird
Message:

Import of RELENG_4_7_0_RELEASE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/kmk/compat.c

    r10 r24  
    11/*
    2  * Copyright (c) 1988, 1989, 1990, 1993
    3  *      The Regents of the University of California.  All rights reserved.
     2 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
    43 * Copyright (c) 1988, 1989 by Adam de Boor
    54 * Copyright (c) 1989 by Berkeley Softworks
     
    3635 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    3736 * SUCH DAMAGE.
    38  *
    39  * @(#)compat.c 8.2 (Berkeley) 3/19/94
    4037 */
    4138
    42 #include <sys/cdefs.h>
    43 __FBSDID("$FreeBSD: src/usr.bin/make/compat.c,v 1.34 2002/10/09 03:42:09 jmallett Exp $");
     39#ifndef lint
     40#if 0
     41static char sccsid[] = "@(#)compat.c    8.2 (Berkeley) 3/19/94";
     42#else
     43static const char rcsid[] =
     44  "$FreeBSD: src/usr.bin/make/compat.c,v 1.16.2.2 2000/07/01 12:24:21 ps Exp $";
     45#endif
     46#endif /* not lint */
    4447
    4548/*-
     
    6366#include    <errno.h>
    6467#include    <signal.h>
    65 #include    <unistd.h>
    6668#include    "make.h"
    6769#include    "hash.h"
     
    7880static char         meta[256];
    7981
    80 static GNode        *curTarg = NULL;
     82static GNode        *curTarg = NILGNODE;
    8183static GNode        *ENDNode;
    82 static void CompatInterrupt(int);
    83 static int CompatRunCommand(void *, void *);
    84 static int CompatMake(void *, void *);
    85 static int shellneed(char *);
     84static void CompatInterrupt __P((int));
     85static int CompatRunCommand __P((ClientData, ClientData));
     86static int CompatMake __P((ClientData, ClientData));
    8687
    8788static char *sh_builtin[] = {
     
    105106 */
    106107static void
    107 CompatInterrupt (int signo)
     108CompatInterrupt (signo)
     109    int     signo;
    108110{
    109111    GNode   *gn;
    110112
    111     if ((curTarg != NULL) && !Targ_Precious (curTarg)) {
     113    if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
    112114        char      *p1;
    113115        char      *file = Var_Value (TARGET, curTarg, &p1);
     
    123125        if (signo == SIGINT) {
    124126            gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
    125             if (gn != NULL) {
    126                 Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
     127            if (gn != NILGNODE) {
     128                Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    127129            }
    128130        }
     
    150152 */
    151153static int
    152 shellneed (char *cmd)
     154shellneed (cmd)
     155        char *cmd;
    153156{
    154157        char **av, **p;
     
    168171 *      Execute the next command for a target. If the command returns an
    169172 *      error, the node's made field is set to ERROR and creation stops.
    170  *      The node from which the command came is also given.
    171173 *
    172174 * Results:
     
    179181 */
    180182static int
    181 CompatRunCommand (void *cmdp, void *gnp)
     183CompatRunCommand (cmdp, gnp)
     184    ClientData    cmdp;         /* Command to execute */
     185    ClientData    gnp;          /* Node from which the command came */
    182186{
    183187    char          *cmdStart;    /* Start of expanded command */
    184     char          *cp;
     188    register char *cp;
    185189    Boolean       silent,       /* Don't print command */
    186190                  errCheck;     /* Check errors */
     
    188192    int           status;       /* Description of child's death */
    189193    int           cpid;         /* Child actually found */
    190     ReturnStatus  rstat;        /* Status of fork */
     194    ReturnStatus  stat;         /* Status of fork */
    191195    LstNode       cmdNode;      /* Node where current command is located */
    192196    char          **av;         /* Argument vector for thing to exec */
    193197    int           argc;         /* Number of arguments in av or 0 if not
    194198                                 * dynamically allocated */
     199    Boolean       local;        /* TRUE if command should be executed
     200                                 * locally */
    195201    int           internal;     /* Various values.. */
    196202    char          *cmd = (char *) cmdp;
     
    208214    errCheck = !(gn->type & OP_IGNORE);
    209215
    210     cmdNode = Lst_Member (gn->commands, (void *)cmd);
     216    cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
    211217    cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
    212218
     
    225231        cmd = cmdStart;
    226232    }
    227     Lst_Replace (cmdNode, (void *)cmdStart);
     233    Lst_Replace (cmdNode, (ClientData)cmdStart);
    228234
    229235    if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
    230         (void)Lst_AtEnd(ENDNode->commands, (void *)cmdStart);
     236        (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
    231237        return(0);
    232238    } else if (strcmp(cmdStart, "...") == 0) {
     
    315321    }
    316322
     323    local = TRUE;
     324
    317325    /*
    318326     * Fork and execute the single command. If the fork fails, we abort.
     
    323331    }
    324332    if (cpid == 0) {
    325         execvp(av[0], av);
    326         (void) write (STDERR_FILENO, av[0], strlen (av[0]));
    327         (void) write (STDERR_FILENO, ":", 1);
    328         (void) write (STDERR_FILENO, strerror(errno), strlen(strerror(errno)));
    329         (void) write (STDERR_FILENO, "\n", 1);
     333        if (local) {
     334            execvp(av[0], av);
     335            (void) write (2, av[0], strlen (av[0]));
     336            (void) write (2, ":", 1);
     337            (void) write (2, strerror(errno), strlen(strerror(errno)));
     338            (void) write (2, "\n", 1);
     339        } else {
     340            (void)execv(av[0], av);
     341        }
    330342        exit(1);
    331343    }
     
    347359    while (1) {
    348360
    349         while ((rstat = wait(&reason)) != cpid) {
    350             if (rstat == -1 && errno != EINTR) {
     361        while ((stat = wait(&reason)) != cpid) {
     362            if (stat == -1 && errno != EINTR) {
    351363                break;
    352364            }
    353365        }
    354366
    355         if (rstat > -1) {
     367        if (stat > -1) {
    356368            if (WIFSTOPPED(reason)) {
    357369                status = WSTOPSIG(reason);              /* stopped */
     
    388400            break;
    389401        } else {
    390             Fatal ("error in wait: %d", rstat);
     402            Fatal ("error in wait: %d", stat);
    391403            /*NOTREACHED*/
    392404        }
     
    400412 *-----------------------------------------------------------------------
    401413 * CompatMake --
    402  *      Make a target, given the parent, to abort if necessary.
     414 *      Make a target.
    403415 *
    404416 * Results:
     
    411423 */
    412424static int
    413 CompatMake (void *gnp, void *pgnp)
     425CompatMake (gnp, pgnp)
     426    ClientData  gnp;        /* The node to make */
     427    ClientData  pgnp;       /* Parent to abort if necessary */
    414428{
    415429    GNode *gn = (GNode *) gnp;
     
    429443        gn->made = BEINGMADE;
    430444        Suff_FindDeps (gn);
    431         Lst_ForEach (gn->children, CompatMake, (void *)gn);
     445        Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
    432446        if (!gn->make) {
    433447            gn->made = ABORTED;
     
    436450        }
    437451
    438         if (Lst_Member (gn->iParents, pgn) != NULL) {
     452        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    439453            char *p1;
    440454            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
     
    448462         * Make_OODate function.
    449463         */
    450         DEBUGF(MAKE, ("Examining %s...", gn->name));
     464        if (DEBUG(MAKE)) {
     465            printf("Examining %s...", gn->name);
     466        }
    451467        if (! Make_OODate(gn)) {
    452468            gn->made = UPTODATE;
    453             DEBUGF(MAKE, ("up-to-date.\n"));
     469            if (DEBUG(MAKE)) {
     470                printf("up-to-date.\n");
     471            }
    454472            return (0);
    455         } else {
    456             DEBUGF(MAKE, ("out-of-date.\n"));
     473        } else if (DEBUG(MAKE)) {
     474            printf("out-of-date.\n");
    457475        }
    458476
     
    490508            if (!touchFlag) {
    491509                curTarg = gn;
    492                 Lst_ForEach (gn->commands, CompatRunCommand, (void *)gn);
    493                 curTarg = NULL;
     510                Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
     511                curTarg = NILGNODE;
    494512            } else {
    495513                Job_Touch (gn, gn->type & OP_SILENT);
     
    561579            if (gn->cmtime > gn->mtime)
    562580                gn->mtime = gn->cmtime;
    563             DEBUGF(MAKE, ("update time: %s\n", Targ_FmtTime(gn->mtime)));
     581            if (DEBUG(MAKE)) {
     582                printf("update time: %s\n", Targ_FmtTime(gn->mtime));
     583            }
    564584#endif
    565585            if (!(gn->type & OP_EXEC)) {
     
    583603        pgn->make = FALSE;
    584604    } else {
    585         if (Lst_Member (gn->iParents, pgn) != NULL) {
     605        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
    586606            char *p1;
    587607            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn);
     
    617637 *-----------------------------------------------------------------------
    618638 * Compat_Run --
    619  *      Start making again, given a list of target nodes.
     639 *      Initialize this mode and start making.
    620640 *
    621641 * Results:
     
    628648 */
    629649void
    630 Compat_Run(Lst targs)
     650Compat_Run(targs)
     651    Lst           targs;    /* List of target nodes to re-create */
    631652{
    632653    char          *cp;      /* Pointer to string of shell meta-characters */
     
    662683    if (!queryFlag) {
    663684        gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
    664         if (gn != NULL) {
    665             Lst_ForEach(gn->commands, CompatRunCommand, (void *)gn);
     685        if (gn != NILGNODE) {
     686            Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
    666687            if (gn->made == ERROR) {
    667688                printf("\n\nStop.\n");
     
    698719     */
    699720    if (errors == 0) {
    700         Lst_ForEach(ENDNode->commands, CompatRunCommand, (void *)gn);
     721        Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
    701722    }
    702723}
Note: See TracChangeset for help on using the changeset viewer.