[BACK]Return to parse.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / make

Annotation of src/usr.bin/make/parse.c, Revision 1.124

1.124   ! dsl         1: /*     $NetBSD: parse.c,v 1.123 2006/12/07 21:07:01 dsl Exp $  */
1.15      christos    2:
1.1       cgd         3: /*
1.27      christos    4:  * Copyright (c) 1988, 1989, 1990, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
1.94      agc         6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Adam de Boor.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. Neither the name of the University nor the names of its contributors
                     19:  *    may be used to endorse or promote products derived from this software
                     20:  *    without specific prior written permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  */
                     34:
                     35: /*
1.1       cgd        36:  * Copyright (c) 1989 by Berkeley Softworks
                     37:  * All rights reserved.
                     38:  *
                     39:  * This code is derived from software contributed to Berkeley by
                     40:  * Adam de Boor.
                     41:  *
                     42:  * Redistribution and use in source and binary forms, with or without
                     43:  * modification, are permitted provided that the following conditions
                     44:  * are met:
                     45:  * 1. Redistributions of source code must retain the above copyright
                     46:  *    notice, this list of conditions and the following disclaimer.
                     47:  * 2. Redistributions in binary form must reproduce the above copyright
                     48:  *    notice, this list of conditions and the following disclaimer in the
                     49:  *    documentation and/or other materials provided with the distribution.
                     50:  * 3. All advertising materials mentioning features or use of this software
                     51:  *    must display the following acknowledgement:
                     52:  *     This product includes software developed by the University of
                     53:  *     California, Berkeley and its contributors.
                     54:  * 4. Neither the name of the University nor the names of its contributors
                     55:  *    may be used to endorse or promote products derived from this software
                     56:  *    without specific prior written permission.
                     57:  *
                     58:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     59:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     60:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     61:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     62:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     63:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     64:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     65:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     66:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     67:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     68:  * SUCH DAMAGE.
                     69:  */
                     70:
1.96      ross       71: #ifndef MAKE_NATIVE
1.124   ! dsl        72: static char rcsid[] = "$NetBSD: parse.c,v 1.123 2006/12/07 21:07:01 dsl Exp $";
1.36      lukem      73: #else
1.34      christos   74: #include <sys/cdefs.h>
1.1       cgd        75: #ifndef lint
1.15      christos   76: #if 0
1.27      christos   77: static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
1.15      christos   78: #else
1.124   ! dsl        79: __RCSID("$NetBSD: parse.c,v 1.123 2006/12/07 21:07:01 dsl Exp $");
1.15      christos   80: #endif
1.1       cgd        81: #endif /* not lint */
1.36      lukem      82: #endif
1.1       cgd        83:
                     84: /*-
                     85:  * parse.c --
                     86:  *     Functions to parse a makefile.
                     87:  *
                     88:  *     One function, Parse_Init, must be called before any functions
                     89:  *     in this module are used. After that, the function Parse_File is the
                     90:  *     main entry point and controls most of the other functions in this
                     91:  *     module.
                     92:  *
                     93:  *     Most important structures are kept in Lsts. Directories for
1.123     dsl        94:  *     the .include "..." function are kept in the 'parseIncPath' Lst, while
                     95:  *     those for the .include <...> are kept in the 'sysIncPath' Lst. The
1.1       cgd        96:  *     targets currently being defined are kept in the 'targets' Lst.
                     97:  *
                     98:  *     The variables 'fname' and 'lineno' are used to track the name
                     99:  *     of the current file and the line number in that file so that error
                    100:  *     messages can be more meaningful.
                    101:  *
                    102:  * Interface:
                    103:  *     Parse_Init                  Initialization function which must be
                    104:  *                                 called before anything else in this module
                    105:  *                                 is used.
                    106:  *
1.9       jtc       107:  *     Parse_End                   Cleanup the module
                    108:  *
1.1       cgd       109:  *     Parse_File                  Function used to parse a makefile. It must
                    110:  *                                 be given the name of the file, which should
                    111:  *                                 already have been opened, and a function
                    112:  *                                 to call to read a character from the file.
                    113:  *
                    114:  *     Parse_IsVar                 Returns TRUE if the given line is a
                    115:  *                                 variable assignment. Used by MainParseArgs
                    116:  *                                 to determine if an argument is a target
                    117:  *                                 or a variable assignment. Used internally
                    118:  *                                 for pretty much the same thing...
                    119:  *
                    120:  *     Parse_Error                 Function called when an error occurs in
                    121:  *                                 parsing. Used by the variable and
                    122:  *                                 conditional modules.
                    123:  *     Parse_MainName              Returns a Lst of the main target to create.
                    124:  */
                    125:
1.84      wiz       126: #include <ctype.h>
                    127: #include <errno.h>
1.5       cgd       128: #include <stdarg.h>
                    129: #include <stdio.h>
1.84      wiz       130:
1.1       cgd       131: #include "make.h"
1.5       cgd       132: #include "hash.h"
                    133: #include "dir.h"
                    134: #include "job.h"
1.1       cgd       135: #include "buf.h"
                    136: #include "pathnames.h"
                    137:
                    138: /*
                    139:  * These values are returned by ParseEOF to tell Parse_File whether to
                    140:  * CONTINUE parsing, i.e. it had only reached the end of an include file,
                    141:  * or if it's DONE.
                    142:  */
                    143: #define        CONTINUE        1
                    144: #define        DONE            0
                    145: static Lst                 targets;    /* targets we're working on */
1.45      mycroft   146: #ifdef CLEANUP
1.9       jtc       147: static Lst                 targCmds;   /* command lines for targets */
1.45      mycroft   148: #endif
1.1       cgd       149: static Boolean     inLine;     /* true if currently in a dependency
                    150:                                 * line or its commands */
                    151: static int         fatals = 0;
                    152:
                    153: static GNode       *mainNode;  /* The main target to create. This is the
                    154:                                 * first target on the first dependency
                    155:                                 * line in the first makefile */
                    156: typedef struct IFile {
1.122     dsl       157:     const char      *fname;        /* name of file */
                    158:     int             lineno;        /* line number in file */
1.123     dsl       159:     FILE            *F;                    /* the open stream */
                    160:     char            *P_str;         /* point to base of string buffer */
                    161:     char            *P_ptr;         /* point to next char of string buffer */
1.5       cgd       162: } IFile;
1.1       cgd       163:
1.82      reinoud   164: static IFile       curFile;
                    165:
                    166:
                    167: /*
                    168:  * Definitions for handling #include specifications
                    169:  */
                    170:
1.123     dsl       171: static Lst      includes;      /* stack of IFiles generated by .includes */
1.1       cgd       172: Lst            parseIncPath;   /* list of directories for "..." includes */
                    173: Lst            sysIncPath;     /* list of directories for <...> includes */
1.74      tv        174: Lst            defIncPath;     /* default directories for <...> includes */
1.1       cgd       175:
                    176: /*-
                    177:  * specType contains the SPECial TYPE of the current target. It is
                    178:  * Not if the target is unspecial. If it *is* special, however, the children
                    179:  * are linked as children of the parent but not vice versa. This variable is
                    180:  * set in ParseDoDependency
                    181:  */
                    182: typedef enum {
                    183:     Begin,         /* .BEGIN */
                    184:     Default,       /* .DEFAULT */
                    185:     End,           /* .END */
                    186:     Ignore,        /* .IGNORE */
                    187:     Includes,      /* .INCLUDES */
                    188:     Interrupt,     /* .INTERRUPT */
                    189:     Libs,          /* .LIBS */
                    190:     MFlags,        /* .MFLAGS or .MAKEFLAGS */
                    191:     Main,          /* .MAIN and we don't have anything user-specified to
                    192:                     * make */
1.5       cgd       193:     NoExport,      /* .NOEXPORT */
1.32      gwr       194:     NoPath,        /* .NOPATH */
1.1       cgd       195:     Not,           /* Not special */
1.75      tv        196:     NotParallel,    /* .NOTPARALLEL */
1.1       cgd       197:     Null,          /* .NULL */
1.75      tv        198:     ExObjdir,      /* .OBJDIR */
1.1       cgd       199:     Order,         /* .ORDER */
1.18      christos  200:     Parallel,      /* .PARALLEL */
1.5       cgd       201:     ExPath,        /* .PATH */
1.22      christos  202:     Phony,         /* .PHONY */
1.48      sjg       203: #ifdef POSIX
                    204:     Posix,         /* .POSIX */
                    205: #endif
1.1       cgd       206:     Precious,      /* .PRECIOUS */
1.5       cgd       207:     ExShell,       /* .SHELL */
1.1       cgd       208:     Silent,        /* .SILENT */
                    209:     SingleShell,    /* .SINGLESHELL */
                    210:     Suffixes,      /* .SUFFIXES */
1.18      christos  211:     Wait,          /* .WAIT */
1.5       cgd       212:     Attribute      /* Generic attribute */
1.1       cgd       213: } ParseSpecial;
                    214:
1.5       cgd       215: static ParseSpecial specType;
1.1       cgd       216:
1.77      christos  217: #define        LPAREN  '('
                    218: #define        RPAREN  ')'
1.1       cgd       219: /*
                    220:  * Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER
                    221:  * seen, then set to each successive source on the line.
                    222:  */
                    223: static GNode   *predecessor;
                    224:
                    225: /*
                    226:  * The parseKeywords table is searched using binary search when deciding
                    227:  * if a target or source is special. The 'spec' field is the ParseSpecial
                    228:  * type of the keyword ("Not" if the keyword isn't special as a target) while
                    229:  * the 'op' field is the operator to apply to the list of targets if the
                    230:  * keyword is used as a source ("0" if the keyword isn't special as a source)
                    231:  */
                    232: static struct {
1.93      christos  233:     const char   *name;        /* Name of keyword */
1.1       cgd       234:     ParseSpecial  spec;                /* Type when used as a target */
                    235:     int                  op;           /* Operator when used as a source */
                    236: } parseKeywords[] = {
                    237: { ".BEGIN",      Begin,        0 },
                    238: { ".DEFAULT",    Default,      0 },
                    239: { ".END",        End,          0 },
                    240: { ".EXEC",       Attribute,    OP_EXEC },
                    241: { ".IGNORE",     Ignore,       OP_IGNORE },
                    242: { ".INCLUDES",   Includes,     0 },
                    243: { ".INTERRUPT",          Interrupt,    0 },
                    244: { ".INVISIBLE",          Attribute,    OP_INVISIBLE },
                    245: { ".JOIN",       Attribute,    OP_JOIN },
                    246: { ".LIBS",       Libs,         0 },
1.29      christos  247: { ".MADE",       Attribute,    OP_MADE },
1.1       cgd       248: { ".MAIN",       Main,         0 },
                    249: { ".MAKE",       Attribute,    OP_MAKE },
                    250: { ".MAKEFLAGS",          MFlags,       0 },
                    251: { ".MFLAGS",     MFlags,       0 },
1.32      gwr       252: { ".NOPATH",     NoPath,       OP_NOPATH },
1.1       cgd       253: { ".NOTMAIN",    Attribute,    OP_NOTMAIN },
                    254: { ".NOTPARALLEL", NotParallel, 0 },
1.18      christos  255: { ".NO_PARALLEL", NotParallel, 0 },
1.1       cgd       256: { ".NULL",       Null,         0 },
1.75      tv        257: { ".OBJDIR",     ExObjdir,     0 },
1.14      ws        258: { ".OPTIONAL",   Attribute,    OP_OPTIONAL },
1.1       cgd       259: { ".ORDER",      Order,        0 },
1.18      christos  260: { ".PARALLEL",   Parallel,     0 },
1.5       cgd       261: { ".PATH",       ExPath,       0 },
1.22      christos  262: { ".PHONY",      Phony,        OP_PHONY },
1.48      sjg       263: #ifdef POSIX
                    264: { ".POSIX",      Posix,        0 },
                    265: #endif
1.1       cgd       266: { ".PRECIOUS",   Precious,     OP_PRECIOUS },
                    267: { ".RECURSIVE",          Attribute,    OP_MAKE },
1.5       cgd       268: { ".SHELL",      ExShell,      0 },
1.1       cgd       269: { ".SILENT",     Silent,       OP_SILENT },
                    270: { ".SINGLESHELL", SingleShell, 0 },
                    271: { ".SUFFIXES",   Suffixes,     0 },
                    272: { ".USE",        Attribute,    OP_USE },
1.71      christos  273: { ".USEBEFORE",   Attribute,           OP_USEBEFORE },
1.18      christos  274: { ".WAIT",       Wait,         0 },
1.1       cgd       275: };
                    276:
1.84      wiz       277: static int ParseIsEscaped(const char *, const char *);
1.122     dsl       278: static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
1.53      is        279:      __attribute__((__format__(__printf__, 4, 5)));
1.122     dsl       280: static void ParseVErrorInternal(const char *, size_t, int, const char *, va_list)
1.53      is        281:      __attribute__((__format__(__printf__, 4, 0)));
1.120     dsl       282: static int ParseFindKeyword(const char *);
1.84      wiz       283: static int ParseLinkSrc(ClientData, ClientData);
                    284: static int ParseDoOp(ClientData, ClientData);
1.120     dsl       285: static void ParseDoSrc(int, const char *);
1.84      wiz       286: static int ParseFindMain(ClientData, ClientData);
                    287: static int ParseAddDir(ClientData, ClientData);
                    288: static int ParseClearPath(ClientData, ClientData);
                    289: static void ParseDoDependency(char *);
                    290: static int ParseAddCmd(ClientData, ClientData);
1.107     perry     291: static inline int ParseReadc(void);
1.84      wiz       292: static void ParseUnreadc(int);
                    293: static void ParseHasCommands(ClientData);
                    294: static void ParseDoInclude(char *);
1.122     dsl       295: static void ParseSetParseFile(const char *);
1.5       cgd       296: #ifdef SYSVINCLUDE
1.84      wiz       297: static void ParseTraditionalInclude(char *);
1.5       cgd       298: #endif
1.123     dsl       299: static int ParseEOF(void);
1.84      wiz       300: static char *ParseReadLine(void);
1.95      enami     301: static char *ParseSkipLine(int, int);
1.84      wiz       302: static void ParseFinishLine(void);
                    303: static void ParseMark(GNode *);
1.5       cgd       304:
1.56      christos  305: extern int  maxJobs;
                    306:
1.77      christos  307:
                    308: /*-
                    309:  *----------------------------------------------------------------------
                    310:  * ParseIsEscaped --
                    311:  *     Check if the current character is escaped on the current line
                    312:  *
                    313:  * Results:
                    314:  *     0 if the character is not backslash escaped, 1 otherwise
                    315:  *
                    316:  * Side Effects:
                    317:  *     None
                    318:  *----------------------------------------------------------------------
                    319:  */
                    320: static int
1.84      wiz       321: ParseIsEscaped(const char *line, const char *c)
1.77      christos  322: {
                    323:     int active = 0;
                    324:     for (;;) {
                    325:        if (line == c)
                    326:            return active;
                    327:        if (*--c != '\\')
                    328:            return active;
                    329:        active = !active;
                    330:     }
                    331: }
                    332:
1.1       cgd       333: /*-
                    334:  *----------------------------------------------------------------------
                    335:  * ParseFindKeyword --
                    336:  *     Look in the table of keywords for one matching the given string.
                    337:  *
1.84      wiz       338:  * Input:
                    339:  *     str             String to find
                    340:  *
1.1       cgd       341:  * Results:
                    342:  *     The index of the keyword, or -1 if it isn't there.
                    343:  *
                    344:  * Side Effects:
                    345:  *     None
                    346:  *----------------------------------------------------------------------
                    347:  */
                    348: static int
1.120     dsl       349: ParseFindKeyword(const char *str)
1.1       cgd       350: {
1.84      wiz       351:     int    start, end, cur;
                    352:     int    diff;
1.27      christos  353:
1.1       cgd       354:     start = 0;
                    355:     end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1;
                    356:
                    357:     do {
                    358:        cur = start + ((end - start) / 2);
1.103     christos  359:        diff = strcmp(str, parseKeywords[cur].name);
1.1       cgd       360:
                    361:        if (diff == 0) {
                    362:            return (cur);
                    363:        } else if (diff < 0) {
                    364:            end = cur - 1;
                    365:        } else {
                    366:            start = cur + 1;
                    367:        }
                    368:     } while (start <= end);
                    369:     return (-1);
                    370: }
                    371:
                    372: /*-
1.38      christos  373:  * ParseVErrorInternal  --
1.1       cgd       374:  *     Error message abort function for parsing. Prints out the context
                    375:  *     of the error (line number and file) as well as the message with
                    376:  *     two optional arguments.
                    377:  *
                    378:  * Results:
                    379:  *     None
                    380:  *
                    381:  * Side Effects:
                    382:  *     "fatals" is incremented if the level is PARSE_FATAL.
                    383:  */
                    384: /* VARARGS */
1.38      christos  385: static void
1.122     dsl       386: ParseVErrorInternal(const char *cfname, size_t clineno, int type,
                    387:     const char *fmt, va_list ap)
1.38      christos  388: {
1.56      christos  389:        static Boolean fatal_warning_error_printed = FALSE;
                    390:
1.63      christos  391:        (void)fprintf(stderr, "%s: \"", progname);
                    392:
1.55      sjg       393:        if (*cfname != '/') {
1.93      christos  394:                char *cp;
                    395:                const char *dir;
1.55      sjg       396:
                    397:                /*
                    398:                 * Nothing is more anoying than not knowing which Makefile
                    399:                 * is the culprit.
                    400:                 */
                    401:                dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
1.63      christos  402:                if (dir == NULL || *dir == '\0' ||
1.55      sjg       403:                    (*dir == '.' && dir[1] == '\0'))
                    404:                        dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
1.63      christos  405:                if (dir == NULL)
                    406:                        dir = ".";
1.55      sjg       407:
1.63      christos  408:                (void)fprintf(stderr, "%s/%s", dir, cfname);
1.55      sjg       409:        } else
1.63      christos  410:                (void)fprintf(stderr, "%s", cfname);
                    411:
                    412:        (void)fprintf(stderr, "\" line %d: ", (int)clineno);
1.38      christos  413:        if (type == PARSE_WARNING)
                    414:                (void)fprintf(stderr, "warning: ");
                    415:        (void)vfprintf(stderr, fmt, ap);
                    416:        (void)fprintf(stderr, "\n");
                    417:        (void)fflush(stderr);
1.56      christos  418:        if (type == PARSE_FATAL || parseWarnFatal)
1.38      christos  419:                fatals += 1;
1.56      christos  420:        if (parseWarnFatal && !fatal_warning_error_printed) {
                    421:                Error("parsing warnings being treated as errors");
                    422:                fatal_warning_error_printed = TRUE;
                    423:        }
1.38      christos  424: }
                    425:
                    426: /*-
                    427:  * ParseErrorInternal  --
                    428:  *     Error function
                    429:  *
                    430:  * Results:
                    431:  *     None
                    432:  *
                    433:  * Side Effects:
                    434:  *     None
                    435:  */
                    436: /* VARARGS */
                    437: static void
1.122     dsl       438: ParseErrorInternal(const char *cfname, size_t clineno, int type,
                    439:     const char *fmt, ...)
1.38      christos  440: {
                    441:        va_list ap;
1.84      wiz       442:
1.38      christos  443:        va_start(ap, fmt);
                    444:        ParseVErrorInternal(cfname, clineno, type, fmt, ap);
                    445:        va_end(ap);
                    446: }
                    447:
                    448: /*-
                    449:  * Parse_Error  --
                    450:  *     External interface to ParseErrorInternal; uses the default filename
                    451:  *     Line number.
                    452:  *
                    453:  * Results:
                    454:  *     None
                    455:  *
                    456:  * Side Effects:
                    457:  *     None
                    458:  */
                    459: /* VARARGS */
1.1       cgd       460: void
1.93      christos  461: Parse_Error(int type, const char *fmt, ...)
1.1       cgd       462: {
                    463:        va_list ap;
1.84      wiz       464:
1.5       cgd       465:        va_start(ap, fmt);
1.82      reinoud   466:        ParseVErrorInternal(curFile.fname, curFile.lineno, type, fmt, ap);
1.1       cgd       467:        va_end(ap);
                    468: }
                    469:
                    470: /*-
                    471:  *---------------------------------------------------------------------
                    472:  * ParseLinkSrc  --
                    473:  *     Link the parent node to its new child. Used in a Lst_ForEach by
                    474:  *     ParseDoDependency. If the specType isn't 'Not', the parent
                    475:  *     isn't linked as a parent of the child.
                    476:  *
1.84      wiz       477:  * Input:
                    478:  *     pgnp            The parent node
                    479:  *     cgpn            The child node
                    480:  *
1.1       cgd       481:  * Results:
                    482:  *     Always = 0
                    483:  *
                    484:  * Side Effects:
                    485:  *     New elements are added to the parents list of cgn and the
                    486:  *     children list of cgn. the unmade field of pgn is updated
                    487:  *     to reflect the additional child.
                    488:  *---------------------------------------------------------------------
                    489:  */
                    490: static int
1.84      wiz       491: ParseLinkSrc(ClientData pgnp, ClientData cgnp)
1.1       cgd       492: {
1.105     christos  493:     GNode          *pgn = (GNode *)pgnp;
                    494:     GNode          *cgn = (GNode *)cgnp;
1.52      mycroft   495:
1.47      mycroft   496:     if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (pgn->cohorts))
1.103     christos  497:        pgn = (GNode *)Lst_Datum(Lst_Last(pgn->cohorts));
1.119     dsl       498:     (void)Lst_AtEnd(pgn->children, cgn);
1.52      mycroft   499:     if (specType == Not)
1.119     dsl       500:            (void)Lst_AtEnd(cgn->parents, pgn);
1.52      mycroft   501:     pgn->unmade += 1;
1.109     dsl       502:     if (DEBUG(PARSE)) {
1.116     dsl       503:        fprintf(debug_file, "# ParseLinkSrc: added child %s - %s\n", pgn->name, cgn->name);
1.109     dsl       504:        Targ_PrintNode(pgn, 0);
                    505:        Targ_PrintNode(cgn, 0);
                    506:     }
1.1       cgd       507:     return (0);
                    508: }
                    509:
                    510: /*-
                    511:  *---------------------------------------------------------------------
                    512:  * ParseDoOp  --
                    513:  *     Apply the parsed operator to the given target node. Used in a
                    514:  *     Lst_ForEach call by ParseDoDependency once all targets have
                    515:  *     been found and their operator parsed. If the previous and new
                    516:  *     operators are incompatible, a major error is taken.
                    517:  *
1.84      wiz       518:  * Input:
                    519:  *     gnp             The node to which the operator is to be applied
                    520:  *     opp             The operator to apply
                    521:  *
1.1       cgd       522:  * Results:
                    523:  *     Always 0
                    524:  *
                    525:  * Side Effects:
                    526:  *     The type field of the node is altered to reflect any new bits in
                    527:  *     the op.
                    528:  *---------------------------------------------------------------------
                    529:  */
                    530: static int
1.84      wiz       531: ParseDoOp(ClientData gnp, ClientData opp)
1.1       cgd       532: {
1.105     christos  533:     GNode          *gn = (GNode *)gnp;
                    534:     int             op = *(int *)opp;
1.1       cgd       535:     /*
                    536:      * If the dependency mask of the operator and the node don't match and
                    537:      * the node has actually had an operator applied to it before, and
1.27      christos  538:      * the operator actually has some dependency information in it, complain.
1.1       cgd       539:      */
                    540:     if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) &&
                    541:        !OP_NOP(gn->type) && !OP_NOP(op))
                    542:     {
1.97      christos  543:        Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name);
1.1       cgd       544:        return (1);
                    545:     }
                    546:
                    547:     if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) {
                    548:        /*
                    549:         * If the node was the object of a :: operator, we need to create a
                    550:         * new instance of it for the children and commands on this dependency
                    551:         * line. The new instance is placed on the 'cohorts' list of the
                    552:         * initial one (note the initial one is not on its own cohorts list)
                    553:         * and the new instance is linked to all parents of the initial
                    554:         * instance.
                    555:         */
1.84      wiz       556:        GNode   *cohort;
1.27      christos  557:
1.33      mycroft   558:        /*
1.46      mycroft   559:         * Propagate copied bits to the initial node.  They'll be propagated
                    560:         * back to the rest of the cohorts later.
1.33      mycroft   561:         */
1.46      mycroft   562:        gn->type |= op & ~OP_OPMASK;
1.33      mycroft   563:
1.120     dsl       564:        cohort = Targ_FindNode(gn->name, TARG_NOHASH);
1.1       cgd       565:        /*
                    566:         * Make the cohort invisible as well to avoid duplicating it into
                    567:         * other variables. True, parents of this target won't tend to do
                    568:         * anything with their local variables, but better safe than
1.46      mycroft   569:         * sorry. (I think this is pointless now, since the relevant list
                    570:         * traversals will no longer see this node anyway. -mycroft)
1.1       cgd       571:         */
1.46      mycroft   572:        cohort->type = op | OP_INVISIBLE;
1.119     dsl       573:        (void)Lst_AtEnd(gn->cohorts, cohort);
1.83      pk        574:        cohort->centurion = gn;
                    575:        gn->unmade_cohorts += 1;
1.120     dsl       576:        snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
                    577:                gn->unmade_cohorts);
1.46      mycroft   578:     } else {
1.1       cgd       579:        /*
1.46      mycroft   580:         * We don't want to nuke any previous flags (whatever they were) so we
                    581:         * just OR the new operator into the old
1.1       cgd       582:         */
1.46      mycroft   583:        gn->type |= op;
1.1       cgd       584:     }
1.33      mycroft   585:
1.1       cgd       586:     return (0);
                    587: }
                    588:
1.27      christos  589: /*-
1.18      christos  590:  *---------------------------------------------------------------------
1.1       cgd       591:  * ParseDoSrc  --
                    592:  *     Given the name of a source, figure out if it is an attribute
                    593:  *     and apply it to the targets if it is. Else decide if there is
                    594:  *     some attribute which should be applied *to* the source because
                    595:  *     of some special target and apply it if so. Otherwise, make the
                    596:  *     source be a child of the targets in the list 'targets'
                    597:  *
1.84      wiz       598:  * Input:
                    599:  *     tOp             operator (if any) from special targets
                    600:  *     src             name of the source to handle
                    601:  *
1.1       cgd       602:  * Results:
                    603:  *     None
                    604:  *
                    605:  * Side Effects:
                    606:  *     Operator bits may be added to the list of targets or to the source.
                    607:  *     The targets may have a new source added to their lists of children.
                    608:  *---------------------------------------------------------------------
                    609:  */
                    610: static void
1.120     dsl       611: ParseDoSrc(int tOp, const char *src)
1.1       cgd       612: {
1.18      christos  613:     GNode      *gn = NULL;
1.120     dsl       614:     static int wait_number = 0;
                    615:     char wait_src[16];
1.1       cgd       616:
1.40      christos  617:     if (*src == '.' && isupper ((unsigned char)src[1])) {
1.1       cgd       618:        int keywd = ParseFindKeyword(src);
                    619:        if (keywd != -1) {
1.18      christos  620:            int op = parseKeywords[keywd].op;
                    621:            if (op != 0) {
1.119     dsl       622:                Lst_ForEach(targets, ParseDoOp, &op);
1.18      christos  623:                return;
                    624:            }
                    625:            if (parseKeywords[keywd].spec == Wait) {
1.120     dsl       626:                /*
                    627:                 * We add a .WAIT node in the dependency list.
                    628:                 * After any dynamic dependencies (and filename globbing)
                    629:                 * have happened, it is given a dependency on the each
                    630:                 * previous child back to and previous .WAIT node.
                    631:                 * The next child won't be scheduled until the .WAIT node
                    632:                 * is built.
                    633:                 * We give each .WAIT node a unique name (mainly for diag).
                    634:                 */
                    635:                snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number);
                    636:                gn = Targ_FindNode(wait_src, TARG_NOHASH);
                    637:                gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
                    638:                Lst_ForEach(targets, ParseLinkSrc, gn);
1.18      christos  639:                return;
                    640:            }
1.1       cgd       641:        }
                    642:     }
1.18      christos  643:
                    644:     switch (specType) {
                    645:     case Main:
1.1       cgd       646:        /*
                    647:         * If we have noted the existence of a .MAIN, it means we need
                    648:         * to add the sources of said target to the list of things
                    649:         * to create. The string 'src' is likely to be free, so we
                    650:         * must make a new copy of it. Note that this will only be
                    651:         * invoked if the user didn't specify a target on the command
                    652:         * line. This is to allow #ifmake's to succeed, or something...
                    653:         */
1.119     dsl       654:        (void)Lst_AtEnd(create, estrdup(src));
1.1       cgd       655:        /*
1.118     dsl       656:         * Add the name to the .TARGETS variable as well, so the user can
1.1       cgd       657:         * employ that, if desired.
                    658:         */
                    659:        Var_Append(".TARGETS", src, VAR_GLOBAL);
1.18      christos  660:        return;
                    661:
                    662:     case Order:
1.1       cgd       663:        /*
                    664:         * Create proper predecessor/successor links between the previous
                    665:         * source and the current one.
                    666:         */
                    667:        gn = Targ_FindNode(src, TARG_CREATE);
                    668:        if (predecessor != NILGNODE) {
1.120     dsl       669:            (void)Lst_AtEnd(predecessor->order_succ, gn);
                    670:            (void)Lst_AtEnd(gn->order_pred, predecessor);
1.109     dsl       671:            if (DEBUG(PARSE)) {
1.116     dsl       672:                fprintf(debug_file, "# ParseDoSrc: added Order dependency %s - %s\n",
1.109     dsl       673:                        predecessor->name, gn->name);
                    674:                Targ_PrintNode(predecessor, 0);
                    675:                Targ_PrintNode(gn, 0);
                    676:            }
1.1       cgd       677:        }
                    678:        /*
                    679:         * The current source now becomes the predecessor for the next one.
                    680:         */
                    681:        predecessor = gn;
1.18      christos  682:        break;
                    683:
                    684:     default:
1.1       cgd       685:        /*
                    686:         * If the source is not an attribute, we need to find/create
                    687:         * a node for it. After that we can apply any operator to it
                    688:         * from a special target or link it to its parents, as
                    689:         * appropriate.
                    690:         *
                    691:         * In the case of a source that was the object of a :: operator,
                    692:         * the attribute is applied to all of its instances (as kept in
                    693:         * the 'cohorts' list of the node) or all the cohorts are linked
                    694:         * to all the targets.
                    695:         */
1.118     dsl       696:
                    697:        /* Find/create the 'src' node and attach to all targets */
1.97      christos  698:        gn = Targ_FindNode(src, TARG_CREATE);
1.1       cgd       699:        if (tOp) {
                    700:            gn->type |= tOp;
                    701:        } else {
1.119     dsl       702:            Lst_ForEach(targets, ParseLinkSrc, gn);
1.1       cgd       703:        }
1.18      christos  704:        break;
                    705:     }
1.1       cgd       706: }
                    707:
                    708: /*-
                    709:  *-----------------------------------------------------------------------
                    710:  * ParseFindMain --
                    711:  *     Find a real target in the list and set it to be the main one.
                    712:  *     Called by ParseDoDependency when a main target hasn't been found
                    713:  *     yet.
                    714:  *
1.84      wiz       715:  * Input:
                    716:  *     gnp             Node to examine
                    717:  *
1.1       cgd       718:  * Results:
                    719:  *     0 if main not found yet, 1 if it is.
                    720:  *
                    721:  * Side Effects:
                    722:  *     mainNode is changed and Targ_SetMain is called.
                    723:  *
                    724:  *-----------------------------------------------------------------------
                    725:  */
                    726: static int
1.84      wiz       727: ParseFindMain(ClientData gnp, ClientData dummy)
1.1       cgd       728: {
1.105     christos  729:     GNode        *gn = (GNode *)gnp;
1.30      christos  730:     if ((gn->type & OP_NOTARGET) == 0) {
1.1       cgd       731:        mainNode = gn;
                    732:        Targ_SetMain(gn);
1.9       jtc       733:        return (dummy ? 1 : 1);
1.1       cgd       734:     } else {
1.9       jtc       735:        return (dummy ? 0 : 0);
1.1       cgd       736:     }
                    737: }
                    738:
                    739: /*-
                    740:  *-----------------------------------------------------------------------
                    741:  * ParseAddDir --
                    742:  *     Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
                    743:  *
                    744:  * Results:
                    745:  *     === 0
                    746:  *
                    747:  * Side Effects:
                    748:  *     See Dir_AddDir.
                    749:  *
                    750:  *-----------------------------------------------------------------------
                    751:  */
                    752: static int
1.84      wiz       753: ParseAddDir(ClientData path, ClientData name)
1.1       cgd       754: {
1.105     christos  755:     (void)Dir_AddDir((Lst) path, (char *)name);
1.1       cgd       756:     return(0);
                    757: }
                    758:
                    759: /*-
                    760:  *-----------------------------------------------------------------------
                    761:  * ParseClearPath --
                    762:  *     Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
                    763:  *
                    764:  * Results:
                    765:  *     === 0
                    766:  *
                    767:  * Side Effects:
                    768:  *     See Dir_ClearPath
                    769:  *
                    770:  *-----------------------------------------------------------------------
                    771:  */
                    772: static int
1.84      wiz       773: ParseClearPath(ClientData path, ClientData dummy)
1.1       cgd       774: {
1.9       jtc       775:     Dir_ClearPath((Lst) path);
                    776:     return(dummy ? 0 : 0);
1.1       cgd       777: }
                    778:
                    779: /*-
                    780:  *---------------------------------------------------------------------
                    781:  * ParseDoDependency  --
                    782:  *     Parse the dependency line in line.
                    783:  *
1.84      wiz       784:  * Input:
                    785:  *     line            the line to parse
                    786:  *
1.1       cgd       787:  * Results:
                    788:  *     None
                    789:  *
                    790:  * Side Effects:
                    791:  *     The nodes of the sources are linked as children to the nodes of the
                    792:  *     targets. Some nodes may be created.
                    793:  *
                    794:  *     We parse a dependency line by first extracting words from the line and
                    795:  * finding nodes in the list of all targets with that name. This is done
                    796:  * until a character is encountered which is an operator character. Currently
                    797:  * these are only ! and :. At this point the operator is parsed and the
                    798:  * pointer into the line advanced until the first source is encountered.
                    799:  *     The parsed operator is applied to each node in the 'targets' list,
                    800:  * which is where the nodes found for the targets are kept, by means of
                    801:  * the ParseDoOp function.
                    802:  *     The sources are read in much the same way as the targets were except
                    803:  * that now they are expanded using the wildcarding scheme of the C-Shell
                    804:  * and all instances of the resulting words in the list of all targets
                    805:  * are found. Each of the resulting nodes is then linked to each of the
                    806:  * targets as one of its children.
                    807:  *     Certain targets are handled specially. These are the ones detailed
                    808:  * by the specType variable.
                    809:  *     The storing of transformation rules is also taken care of here.
                    810:  * A target is recognized as a transformation rule by calling
                    811:  * Suff_IsTransform. If it is a transformation rule, its node is gotten
                    812:  * from the suffix module via Suff_AddTransform rather than the standard
                    813:  * Targ_FindNode in the target module.
                    814:  *---------------------------------------------------------------------
                    815:  */
                    816: static void
1.84      wiz       817: ParseDoDependency(char *line)
1.1       cgd       818: {
1.9       jtc       819:     char          *cp;         /* our current position */
1.98      christos  820:     GNode         *gn = NULL;  /* a general purpose temporary node */
1.9       jtc       821:     int             op;                /* the operator on the line */
1.1       cgd       822:     char            savec;     /* a place to save a character */
                    823:     Lst            paths;      /* List of search paths to alter when parsing
                    824:                                 * a list of .PATH targets */
                    825:     int                    tOp;        /* operator from special target */
1.18      christos  826:     Lst                    sources;    /* list of archive source names after
                    827:                                 * expansion */
1.1       cgd       828:     Lst            curTargs;   /* list of target names to be found and added
                    829:                                 * to the targets list */
1.77      christos  830:     char          *lstart = line;
1.1       cgd       831:
1.120     dsl       832:     if (DEBUG(PARSE))
                    833:        fprintf(debug_file, "ParseDoDependency(%s)\n", line);
1.1       cgd       834:     tOp = 0;
                    835:
                    836:     specType = Not;
                    837:     paths = (Lst)NULL;
                    838:
                    839:     curTargs = Lst_Init(FALSE);
1.27      christos  840:
1.1       cgd       841:     do {
1.121     dsl       842:        for (cp = line; *cp && (ParseIsEscaped(lstart, cp) ||
                    843:                     !(isspace((unsigned char)*cp) ||
                    844:                         *cp == '!' || *cp == ':' || *cp == LPAREN));
                    845:                 cp++) {
1.1       cgd       846:            if (*cp == '$') {
                    847:                /*
                    848:                 * Must be a dynamic source (would have been expanded
                    849:                 * otherwise), so call the Var module to parse the puppy
                    850:                 * so we can safely advance beyond it...There should be
                    851:                 * no errors in this, as they would have been discovered
                    852:                 * in the initial Var_Subst and we wouldn't be here.
                    853:                 */
                    854:                int     length;
1.114     christos  855:                void    *freeIt;
1.1       cgd       856:                char    *result;
                    857:
1.114     christos  858:                result = Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt);
                    859:                if (freeIt)
                    860:                    free(freeIt);
1.1       cgd       861:                cp += length-1;
                    862:            }
                    863:        }
1.121     dsl       864:
1.77      christos  865:        if (!ParseIsEscaped(lstart, cp) && *cp == LPAREN) {
1.1       cgd       866:            /*
                    867:             * Archives must be handled specially to make sure the OP_ARCHV
                    868:             * flag is set in their 'type' field, for one thing, and because
                    869:             * things like "archive(file1.o file2.o file3.o)" are permissible.
                    870:             * Arch_ParseArchive will set 'line' to be the first non-blank
                    871:             * after the archive-spec. It creates/finds nodes for the members
                    872:             * and places them on the given list, returning SUCCESS if all
                    873:             * went well and FAILURE if there was an error in the
                    874:             * specification. On error, line should remain untouched.
                    875:             */
1.97      christos  876:            if (Arch_ParseArchive(&line, targets, VAR_CMD) != SUCCESS) {
                    877:                Parse_Error(PARSE_FATAL,
1.1       cgd       878:                             "Error in archive specification: \"%s\"", line);
1.112     christos  879:                goto out;
1.1       cgd       880:            } else {
                    881:                continue;
                    882:            }
                    883:        }
                    884:        savec = *cp;
1.27      christos  885:
1.1       cgd       886:        if (!*cp) {
                    887:            /*
                    888:             * Ending a dependency line without an operator is a Bozo
1.65      sommerfe  889:             * no-no.  As a heuristic, this is also often triggered by
                    890:             * undetected conflicts from cvs/rcs merges.
1.1       cgd       891:             */
1.65      sommerfe  892:            if ((strncmp(line, "<<<<<<", 6) == 0) ||
                    893:                (strncmp(line, "======", 6) == 0) ||
                    894:                (strncmp(line, ">>>>>>", 6) == 0))
1.97      christos  895:                Parse_Error(PARSE_FATAL,
1.67      sommerfe  896:                    "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
1.65      sommerfe  897:            else
1.97      christos  898:                Parse_Error(PARSE_FATAL, "Need an operator");
1.112     christos  899:            goto out;
1.1       cgd       900:        }
                    901:        *cp = '\0';
1.118     dsl       902:
1.1       cgd       903:        /*
                    904:         * Have a word in line. See if it's a special target and set
                    905:         * specType to match it.
                    906:         */
1.40      christos  907:        if (*line == '.' && isupper ((unsigned char)line[1])) {
1.1       cgd       908:            /*
                    909:             * See if the target is a special target that must have it
1.27      christos  910:             * or its sources handled specially.
1.1       cgd       911:             */
                    912:            int keywd = ParseFindKeyword(line);
                    913:            if (keywd != -1) {
1.5       cgd       914:                if (specType == ExPath && parseKeywords[keywd].spec != ExPath) {
1.1       cgd       915:                    Parse_Error(PARSE_FATAL, "Mismatched special targets");
1.112     christos  916:                    goto out;
1.1       cgd       917:                }
1.27      christos  918:
1.1       cgd       919:                specType = parseKeywords[keywd].spec;
                    920:                tOp = parseKeywords[keywd].op;
                    921:
                    922:                /*
                    923:                 * Certain special targets have special semantics:
                    924:                 *      .PATH           Have to set the dirSearchPath
                    925:                 *                      variable too
                    926:                 *      .MAIN           Its sources are only used if
                    927:                 *                      nothing has been specified to
                    928:                 *                      create.
                    929:                 *      .DEFAULT        Need to create a node to hang
                    930:                 *                      commands on, but we don't want
                    931:                 *                      it in the graph, nor do we want
                    932:                 *                      it to be the Main Target, so we
                    933:                 *                      create it, set OP_NOTMAIN and
                    934:                 *                      add it to the list, setting
                    935:                 *                      DEFAULT to the new node for
                    936:                 *                      later use. We claim the node is
                    937:                 *                      A transformation rule to make
                    938:                 *                      life easier later, when we'll
                    939:                 *                      use Make_HandleUse to actually
                    940:                 *                      apply the .DEFAULT commands.
1.22      christos  941:                 *      .PHONY          The list of targets
1.32      gwr       942:                 *      .NOPATH         Don't search for file in the path
1.1       cgd       943:                 *      .BEGIN
                    944:                 *      .END
                    945:                 *      .INTERRUPT      Are not to be considered the
                    946:                 *                      main target.
                    947:                 *      .NOTPARALLEL    Make only one target at a time.
                    948:                 *      .SINGLESHELL    Create a shell for each command.
                    949:                 *      .ORDER          Must set initial predecessor to NIL
                    950:                 */
                    951:                switch (specType) {
1.5       cgd       952:                    case ExPath:
1.1       cgd       953:                        if (paths == NULL) {
                    954:                            paths = Lst_Init(FALSE);
                    955:                        }
1.119     dsl       956:                        (void)Lst_AtEnd(paths, dirSearchPath);
1.1       cgd       957:                        break;
                    958:                    case Main:
                    959:                        if (!Lst_IsEmpty(create)) {
                    960:                            specType = Not;
                    961:                        }
                    962:                        break;
                    963:                    case Begin:
                    964:                    case End:
                    965:                    case Interrupt:
                    966:                        gn = Targ_FindNode(line, TARG_CREATE);
1.99      christos  967:                        gn->type |= OP_NOTMAIN|OP_SPECIAL;
1.119     dsl       968:                        (void)Lst_AtEnd(targets, gn);
1.1       cgd       969:                        break;
                    970:                    case Default:
                    971:                        gn = Targ_NewGN(".DEFAULT");
                    972:                        gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
1.119     dsl       973:                        (void)Lst_AtEnd(targets, gn);
1.1       cgd       974:                        DEFAULT = gn;
                    975:                        break;
                    976:                    case NotParallel:
1.113     dsl       977:                        maxJobs = 1;
1.1       cgd       978:                        break;
                    979:                    case SingleShell:
1.54      sommerfe  980:                        compatMake = TRUE;
1.1       cgd       981:                        break;
                    982:                    case Order:
                    983:                        predecessor = NILGNODE;
                    984:                        break;
1.5       cgd       985:                    default:
                    986:                        break;
1.1       cgd       987:                }
1.103     christos  988:            } else if (strncmp(line, ".PATH", 5) == 0) {
1.1       cgd       989:                /*
                    990:                 * .PATH<suffix> has to be handled specially.
                    991:                 * Call on the suffix module to give us a path to
                    992:                 * modify.
                    993:                 */
                    994:                Lst     path;
1.27      christos  995:
1.5       cgd       996:                specType = ExPath;
1.97      christos  997:                path = Suff_GetPath(&line[5]);
1.1       cgd       998:                if (path == NILLST) {
1.97      christos  999:                    Parse_Error(PARSE_FATAL,
1.1       cgd      1000:                                 "Suffix '%s' not defined (yet)",
                   1001:                                 &line[5]);
1.112     christos 1002:                    goto out;
1.1       cgd      1003:                } else {
                   1004:                    if (paths == (Lst)NULL) {
                   1005:                        paths = Lst_Init(FALSE);
                   1006:                    }
1.119     dsl      1007:                    (void)Lst_AtEnd(paths, path);
1.1       cgd      1008:                }
                   1009:            }
                   1010:        }
1.27      christos 1011:
1.1       cgd      1012:        /*
                   1013:         * Have word in line. Get or create its node and stick it at
1.27      christos 1014:         * the end of the targets list
1.1       cgd      1015:         */
                   1016:        if ((specType == Not) && (*line != '\0')) {
                   1017:            if (Dir_HasWildcards(line)) {
                   1018:                /*
                   1019:                 * Targets are to be sought only in the current directory,
                   1020:                 * so create an empty path for the thing. Note we need to
                   1021:                 * use Dir_Destroy in the destruction of the path as the
                   1022:                 * Dir module could have added a directory to the path...
                   1023:                 */
                   1024:                Lst         emptyPath = Lst_Init(FALSE);
1.27      christos 1025:
1.1       cgd      1026:                Dir_Expand(line, emptyPath, curTargs);
1.27      christos 1027:
1.1       cgd      1028:                Lst_Destroy(emptyPath, Dir_Destroy);
                   1029:            } else {
                   1030:                /*
                   1031:                 * No wildcards, but we want to avoid code duplication,
                   1032:                 * so create a list with the word on it.
                   1033:                 */
1.119     dsl      1034:                (void)Lst_AtEnd(curTargs, line);
1.1       cgd      1035:            }
1.27      christos 1036:
1.1       cgd      1037:            while(!Lst_IsEmpty(curTargs)) {
                   1038:                char    *targName = (char *)Lst_DeQueue(curTargs);
1.27      christos 1039:
1.1       cgd      1040:                if (!Suff_IsTransform (targName)) {
1.97      christos 1041:                    gn = Targ_FindNode(targName, TARG_CREATE);
1.1       cgd      1042:                } else {
1.97      christos 1043:                    gn = Suff_AddTransform(targName);
1.1       cgd      1044:                }
1.27      christos 1045:
1.119     dsl      1046:                (void)Lst_AtEnd(targets, gn);
1.1       cgd      1047:            }
1.5       cgd      1048:        } else if (specType == ExPath && *line != '.' && *line != '\0') {
1.1       cgd      1049:            Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
                   1050:        }
1.27      christos 1051:
1.1       cgd      1052:        *cp = savec;
                   1053:        /*
                   1054:         * If it is a special type and not .PATH, it's the only target we
                   1055:         * allow on this line...
                   1056:         */
1.5       cgd      1057:        if (specType != Not && specType != ExPath) {
1.115     christos 1058:            Boolean warning = FALSE;
1.27      christos 1059:
1.77      christos 1060:            while (*cp && (ParseIsEscaped(lstart, cp) ||
                   1061:                ((*cp != '!') && (*cp != ':')))) {
                   1062:                if (ParseIsEscaped(lstart, cp) ||
                   1063:                    (*cp != ' ' && *cp != '\t')) {
1.115     christos 1064:                    warning = TRUE;
1.1       cgd      1065:                }
                   1066:                cp++;
                   1067:            }
1.115     christos 1068:            if (warning) {
1.1       cgd      1069:                Parse_Error(PARSE_WARNING, "Extra target ignored");
                   1070:            }
                   1071:        } else {
1.40      christos 1072:            while (*cp && isspace ((unsigned char)*cp)) {
1.1       cgd      1073:                cp++;
                   1074:            }
                   1075:        }
                   1076:        line = cp;
1.77      christos 1077:     } while (*line && (ParseIsEscaped(lstart, line) ||
                   1078:        ((*line != '!') && (*line != ':'))));
1.1       cgd      1079:
                   1080:     /*
                   1081:      * Don't need the list of target names anymore...
                   1082:      */
                   1083:     Lst_Destroy(curTargs, NOFREE);
1.112     christos 1084:     curTargs = NULL;
1.1       cgd      1085:
                   1086:     if (!Lst_IsEmpty(targets)) {
                   1087:        switch(specType) {
                   1088:            default:
                   1089:                Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored");
                   1090:                break;
                   1091:            case Default:
                   1092:            case Begin:
                   1093:            case End:
                   1094:            case Interrupt:
                   1095:                /*
                   1096:                 * These four create nodes on which to hang commands, so
                   1097:                 * targets shouldn't be empty...
                   1098:                 */
                   1099:            case Not:
                   1100:                /*
                   1101:                 * Nothing special here -- targets can be empty if it wants.
                   1102:                 */
                   1103:                break;
                   1104:        }
                   1105:     }
                   1106:
                   1107:     /*
                   1108:      * Have now parsed all the target names. Must parse the operator next. The
                   1109:      * result is left in  op .
                   1110:      */
                   1111:     if (*cp == '!') {
                   1112:        op = OP_FORCE;
                   1113:     } else if (*cp == ':') {
                   1114:        if (cp[1] == ':') {
                   1115:            op = OP_DOUBLEDEP;
                   1116:            cp++;
                   1117:        } else {
                   1118:            op = OP_DEPENDS;
                   1119:        }
                   1120:     } else {
1.97      christos 1121:        Parse_Error(PARSE_FATAL, "Missing dependency operator");
1.112     christos 1122:        goto out;
1.1       cgd      1123:     }
                   1124:
                   1125:     cp++;                      /* Advance beyond operator */
                   1126:
1.119     dsl      1127:     Lst_ForEach(targets, ParseDoOp, &op);
1.1       cgd      1128:
                   1129:     /*
1.27      christos 1130:      * Get to the first source
1.1       cgd      1131:      */
1.40      christos 1132:     while (*cp && isspace ((unsigned char)*cp)) {
1.1       cgd      1133:        cp++;
                   1134:     }
                   1135:     line = cp;
                   1136:
                   1137:     /*
                   1138:      * Several special targets take different actions if present with no
                   1139:      * sources:
                   1140:      * a .SUFFIXES line with no sources clears out all old suffixes
                   1141:      * a .PRECIOUS line makes all targets precious
                   1142:      * a .IGNORE line ignores errors for all targets
                   1143:      * a .SILENT line creates silence when making all targets
                   1144:      * a .PATH removes all directories from the search path(s).
                   1145:      */
                   1146:     if (!*line) {
                   1147:        switch (specType) {
                   1148:            case Suffixes:
1.97      christos 1149:                Suff_ClearSuffixes();
1.1       cgd      1150:                break;
                   1151:            case Precious:
                   1152:                allPrecious = TRUE;
                   1153:                break;
                   1154:            case Ignore:
                   1155:                ignoreErrors = TRUE;
                   1156:                break;
                   1157:            case Silent:
                   1158:                beSilent = TRUE;
                   1159:                break;
1.5       cgd      1160:            case ExPath:
1.119     dsl      1161:                Lst_ForEach(paths, ParseClearPath, NULL);
1.85      sjg      1162:                Dir_SetPATH();
1.1       cgd      1163:                break;
1.48      sjg      1164: #ifdef POSIX
                   1165:             case Posix:
1.70      sjg      1166:                 Var_Set("%POSIX", "1003.2", VAR_GLOBAL, 0);
1.48      sjg      1167:                 break;
                   1168: #endif
1.5       cgd      1169:            default:
                   1170:                break;
1.1       cgd      1171:        }
                   1172:     } else if (specType == MFlags) {
                   1173:        /*
                   1174:         * Call on functions in main.c to deal with these arguments and
                   1175:         * set the initial character to a null-character so the loop to
                   1176:         * get sources won't get anything
                   1177:         */
1.97      christos 1178:        Main_ParseArgLine(line);
1.1       cgd      1179:        *line = '\0';
1.5       cgd      1180:     } else if (specType == ExShell) {
1.97      christos 1181:        if (Job_ParseShell(line) != SUCCESS) {
                   1182:            Parse_Error(PARSE_FATAL, "improper shell specification");
1.112     christos 1183:            goto out;
1.1       cgd      1184:        }
                   1185:        *line = '\0';
                   1186:     } else if ((specType == NotParallel) || (specType == SingleShell)) {
                   1187:        *line = '\0';
                   1188:     }
1.27      christos 1189:
1.1       cgd      1190:     /*
1.27      christos 1191:      * NOW GO FOR THE SOURCES
1.1       cgd      1192:      */
1.5       cgd      1193:     if ((specType == Suffixes) || (specType == ExPath) ||
1.1       cgd      1194:        (specType == Includes) || (specType == Libs) ||
1.75      tv       1195:        (specType == Null) || (specType == ExObjdir))
1.1       cgd      1196:     {
                   1197:        while (*line) {
                   1198:            /*
                   1199:             * If the target was one that doesn't take files as its sources
                   1200:             * but takes something like suffixes, we take each
                   1201:             * space-separated word on the line as a something and deal
                   1202:             * with it accordingly.
                   1203:             *
                   1204:             * If the target was .SUFFIXES, we take each source as a
                   1205:             * suffix and add it to the list of suffixes maintained by the
                   1206:             * Suff module.
                   1207:             *
                   1208:             * If the target was a .PATH, we add the source as a directory
                   1209:             * to search on the search path.
                   1210:             *
                   1211:             * If it was .INCLUDES, the source is taken to be the suffix of
                   1212:             * files which will be #included and whose search path should
                   1213:             * be present in the .INCLUDES variable.
                   1214:             *
                   1215:             * If it was .LIBS, the source is taken to be the suffix of
                   1216:             * files which are considered libraries and whose search path
                   1217:             * should be present in the .LIBS variable.
                   1218:             *
                   1219:             * If it was .NULL, the source is the suffix to use when a file
                   1220:             * has no valid suffix.
1.75      tv       1221:             *
                   1222:             * If it was .OBJDIR, the source is a new definition for .OBJDIR,
                   1223:             * and will cause make to do a new chdir to that path.
1.1       cgd      1224:             */
1.40      christos 1225:            while (*cp && !isspace ((unsigned char)*cp)) {
1.1       cgd      1226:                cp++;
                   1227:            }
                   1228:            savec = *cp;
                   1229:            *cp = '\0';
                   1230:            switch (specType) {
                   1231:                case Suffixes:
1.97      christos 1232:                    Suff_AddSuffix(line, &mainNode);
1.1       cgd      1233:                    break;
1.5       cgd      1234:                case ExPath:
1.119     dsl      1235:                    Lst_ForEach(paths, ParseAddDir, line);
1.1       cgd      1236:                    break;
                   1237:                case Includes:
1.97      christos 1238:                    Suff_AddInclude(line);
1.1       cgd      1239:                    break;
                   1240:                case Libs:
1.97      christos 1241:                    Suff_AddLib(line);
1.1       cgd      1242:                    break;
                   1243:                case Null:
1.97      christos 1244:                    Suff_SetNull(line);
1.75      tv       1245:                    break;
                   1246:                case ExObjdir:
                   1247:                    Main_SetObjdir(line);
1.1       cgd      1248:                    break;
1.5       cgd      1249:                default:
                   1250:                    break;
1.1       cgd      1251:            }
                   1252:            *cp = savec;
                   1253:            if (savec != '\0') {
                   1254:                cp++;
                   1255:            }
1.40      christos 1256:            while (*cp && isspace ((unsigned char)*cp)) {
1.1       cgd      1257:                cp++;
                   1258:            }
                   1259:            line = cp;
                   1260:        }
                   1261:        if (paths) {
                   1262:            Lst_Destroy(paths, NOFREE);
                   1263:        }
1.85      sjg      1264:        if (specType == ExPath)
                   1265:            Dir_SetPATH();
1.1       cgd      1266:     } else {
                   1267:        while (*line) {
                   1268:            /*
                   1269:             * The targets take real sources, so we must beware of archive
                   1270:             * specifications (i.e. things with left parentheses in them)
                   1271:             * and handle them accordingly.
                   1272:             */
1.118     dsl      1273:            for (; *cp && !isspace ((unsigned char)*cp); cp++) {
1.77      christos 1274:                if ((*cp == LPAREN) && (cp > line) && (cp[-1] != '$')) {
1.1       cgd      1275:                    /*
                   1276:                     * Only stop for a left parenthesis if it isn't at the
                   1277:                     * start of a word (that'll be for variable changes
                   1278:                     * later) and isn't preceded by a dollar sign (a dynamic
                   1279:                     * source).
                   1280:                     */
                   1281:                    break;
                   1282:                }
                   1283:            }
                   1284:
1.77      christos 1285:            if (*cp == LPAREN) {
1.97      christos 1286:                sources = Lst_Init(FALSE);
                   1287:                if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) {
                   1288:                    Parse_Error(PARSE_FATAL,
1.1       cgd      1289:                                 "Error in source archive spec \"%s\"", line);
1.112     christos 1290:                    goto out;
1.1       cgd      1291:                }
                   1292:
                   1293:                while (!Lst_IsEmpty (sources)) {
1.103     christos 1294:                    gn = (GNode *)Lst_DeQueue(sources);
1.120     dsl      1295:                    ParseDoSrc(tOp, gn->name);
1.1       cgd      1296:                }
1.97      christos 1297:                Lst_Destroy(sources, NOFREE);
1.1       cgd      1298:                cp = line;
                   1299:            } else {
                   1300:                if (*cp) {
                   1301:                    *cp = '\0';
                   1302:                    cp += 1;
                   1303:                }
                   1304:
1.120     dsl      1305:                ParseDoSrc(tOp, line);
1.1       cgd      1306:            }
1.40      christos 1307:            while (*cp && isspace ((unsigned char)*cp)) {
1.1       cgd      1308:                cp++;
                   1309:            }
                   1310:            line = cp;
                   1311:        }
                   1312:     }
1.27      christos 1313:
1.1       cgd      1314:     if (mainNode == NILGNODE) {
                   1315:        /*
                   1316:         * If we have yet to decide on a main target to make, in the
                   1317:         * absence of any user input, we want the first target on
                   1318:         * the first dependency line that is actually a real target
                   1319:         * (i.e. isn't a .USE or .EXEC rule) to be made.
                   1320:         */
1.119     dsl      1321:        Lst_ForEach(targets, ParseFindMain, NULL);
1.1       cgd      1322:     }
                   1323:
1.112     christos 1324: out:
                   1325:     if (curTargs)
                   1326:            Lst_Destroy(curTargs, NOFREE);
1.1       cgd      1327: }
                   1328:
                   1329: /*-
                   1330:  *---------------------------------------------------------------------
                   1331:  * Parse_IsVar  --
                   1332:  *     Return TRUE if the passed line is a variable assignment. A variable
                   1333:  *     assignment consists of a single word followed by optional whitespace
                   1334:  *     followed by either a += or an = operator.
                   1335:  *     This function is used both by the Parse_File function and main when
                   1336:  *     parsing the command-line arguments.
                   1337:  *
1.84      wiz      1338:  * Input:
                   1339:  *     line            the line to check
                   1340:  *
1.1       cgd      1341:  * Results:
                   1342:  *     TRUE if it is. FALSE if it ain't
                   1343:  *
                   1344:  * Side Effects:
                   1345:  *     none
                   1346:  *---------------------------------------------------------------------
                   1347:  */
                   1348: Boolean
1.84      wiz      1349: Parse_IsVar(char *line)
1.1       cgd      1350: {
1.84      wiz      1351:     Boolean wasSpace = FALSE;  /* set TRUE if found a space */
                   1352:     Boolean haveName = FALSE;  /* Set TRUE if have a variable name */
1.16      christos 1353:     int level = 0;
                   1354: #define ISEQOPERATOR(c) \
                   1355:        (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1.1       cgd      1356:
                   1357:     /*
                   1358:      * Skip to variable name
                   1359:      */
1.27      christos 1360:     for (;(*line == ' ') || (*line == '\t'); line++)
1.16      christos 1361:        continue;
1.1       cgd      1362:
1.16      christos 1363:     for (; *line != '=' || level != 0; line++)
                   1364:        switch (*line) {
                   1365:        case '\0':
1.1       cgd      1366:            /*
                   1367:             * end-of-line -- can't be a variable assignment.
                   1368:             */
1.16      christos 1369:            return FALSE;
                   1370:
                   1371:        case ' ':
                   1372:        case '\t':
1.1       cgd      1373:            /*
                   1374:             * there can be as much white space as desired so long as there is
1.27      christos 1375:             * only one word before the operator
1.1       cgd      1376:             */
                   1377:            wasSpace = TRUE;
1.16      christos 1378:            break;
                   1379:
1.77      christos 1380:        case LPAREN:
1.16      christos 1381:        case '{':
                   1382:            level++;
                   1383:            break;
                   1384:
                   1385:        case '}':
1.77      christos 1386:        case RPAREN:
1.16      christos 1387:            level--;
                   1388:            break;
1.27      christos 1389:
1.16      christos 1390:        default:
                   1391:            if (wasSpace && haveName) {
                   1392:                    if (ISEQOPERATOR(*line)) {
                   1393:                        /*
1.23      christos 1394:                         * We must have a finished word
                   1395:                         */
                   1396:                        if (level != 0)
                   1397:                            return FALSE;
                   1398:
                   1399:                        /*
1.16      christos 1400:                         * When an = operator [+?!:] is found, the next
1.23      christos 1401:                         * character must be an = or it ain't a valid
1.16      christos 1402:                         * assignment.
                   1403:                         */
1.23      christos 1404:                        if (line[1] == '=')
1.16      christos 1405:                            return haveName;
1.23      christos 1406: #ifdef SUNSHCMD
1.16      christos 1407:                        /*
1.23      christos 1408:                         * This is a shell command
1.16      christos 1409:                         */
1.23      christos 1410:                        if (strncmp(line, ":sh", 3) == 0)
                   1411:                            return haveName;
                   1412: #endif
1.16      christos 1413:                    }
1.23      christos 1414:                    /*
                   1415:                     * This is the start of another word, so not assignment.
                   1416:                     */
                   1417:                    return FALSE;
1.16      christos 1418:            }
                   1419:            else {
1.27      christos 1420:                haveName = TRUE;
1.16      christos 1421:                wasSpace = FALSE;
1.1       cgd      1422:            }
1.16      christos 1423:            break;
1.1       cgd      1424:        }
                   1425:
1.16      christos 1426:     return haveName;
1.1       cgd      1427: }
                   1428:
                   1429: /*-
                   1430:  *---------------------------------------------------------------------
                   1431:  * Parse_DoVar  --
                   1432:  *     Take the variable assignment in the passed line and do it in the
                   1433:  *     global context.
                   1434:  *
                   1435:  *     Note: There is a lexical ambiguity with assignment modifier characters
                   1436:  *     in variable names. This routine interprets the character before the =
                   1437:  *     as a modifier. Therefore, an assignment like
                   1438:  *         C++=/usr/bin/CC
                   1439:  *     is interpreted as "C+ +=" instead of "C++ =".
                   1440:  *
1.84      wiz      1441:  * Input:
                   1442:  *     line            a line guaranteed to be a variable assignment.
                   1443:  *                     This reduces error checks
                   1444:  *     ctxt            Context in which to do the assignment
                   1445:  *
1.1       cgd      1446:  * Results:
                   1447:  *     none
                   1448:  *
                   1449:  * Side Effects:
                   1450:  *     the variable structure of the given variable name is altered in the
                   1451:  *     global context.
                   1452:  *---------------------------------------------------------------------
                   1453:  */
                   1454: void
1.84      wiz      1455: Parse_DoVar(char *line, GNode *ctxt)
1.1       cgd      1456: {
1.7       cgd      1457:     char          *cp; /* pointer into line */
1.1       cgd      1458:     enum {
                   1459:        VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL
                   1460:     }              type;       /* Type of assignment */
1.27      christos 1461:     char            *opc;      /* ptr to operator character to
1.1       cgd      1462:                                 * null-terminate the variable name */
1.86      sjg      1463:     Boolean       freeCp = FALSE; /* TRUE if cp needs to be freed,
                   1464:                                    * i.e. if any variable expansion was
                   1465:                                    * performed */
1.27      christos 1466:     /*
1.7       cgd      1467:      * Avoid clobbered variable warnings by forcing the compiler
                   1468:      * to ``unregister'' variables
                   1469:      */
                   1470: #if __GNUC__
                   1471:     (void) &cp;
                   1472:     (void) &line;
                   1473: #endif
1.1       cgd      1474:
                   1475:     /*
                   1476:      * Skip to variable name
                   1477:      */
                   1478:     while ((*line == ' ') || (*line == '\t')) {
                   1479:        line++;
                   1480:     }
                   1481:
                   1482:     /*
                   1483:      * Skip to operator character, nulling out whitespace as we go
                   1484:      */
                   1485:     for (cp = line + 1; *cp != '='; cp++) {
1.40      christos 1486:        if (isspace ((unsigned char)*cp)) {
1.1       cgd      1487:            *cp = '\0';
                   1488:        }
                   1489:     }
                   1490:     opc = cp-1;                /* operator is the previous character */
                   1491:     *cp++ = '\0';      /* nuke the = */
                   1492:
                   1493:     /*
                   1494:      * Check operator type
                   1495:      */
                   1496:     switch (*opc) {
                   1497:        case '+':
                   1498:            type = VAR_APPEND;
                   1499:            *opc = '\0';
                   1500:            break;
                   1501:
                   1502:        case '?':
                   1503:            /*
                   1504:             * If the variable already has a value, we don't do anything.
                   1505:             */
                   1506:            *opc = '\0';
                   1507:            if (Var_Exists(line, ctxt)) {
                   1508:                return;
                   1509:            } else {
                   1510:                type = VAR_NORMAL;
                   1511:            }
                   1512:            break;
                   1513:
                   1514:        case ':':
                   1515:            type = VAR_SUBST;
                   1516:            *opc = '\0';
                   1517:            break;
                   1518:
                   1519:        case '!':
                   1520:            type = VAR_SHELL;
                   1521:            *opc = '\0';
                   1522:            break;
                   1523:
                   1524:        default:
1.23      christos 1525: #ifdef SUNSHCMD
1.39      christos 1526:            while (opc > line && *opc != ':')
                   1527:                opc--;
1.23      christos 1528:
                   1529:            if (strncmp(opc, ":sh", 3) == 0) {
                   1530:                type = VAR_SHELL;
                   1531:                *opc = '\0';
                   1532:                break;
                   1533:            }
                   1534: #endif
1.1       cgd      1535:            type = VAR_NORMAL;
                   1536:            break;
                   1537:     }
                   1538:
1.40      christos 1539:     while (isspace ((unsigned char)*cp)) {
1.1       cgd      1540:        cp++;
                   1541:     }
                   1542:
                   1543:     if (type == VAR_APPEND) {
1.97      christos 1544:        Var_Append(line, cp, ctxt);
1.1       cgd      1545:     } else if (type == VAR_SUBST) {
                   1546:        /*
                   1547:         * Allow variables in the old value to be undefined, but leave their
                   1548:         * invocation alone -- this is done by forcing oldVars to be false.
                   1549:         * XXX: This can cause recursive variables, but that's not hard to do,
                   1550:         * and this allows someone to do something like
                   1551:         *
                   1552:         *  CFLAGS = $(.INCLUDES)
                   1553:         *  CFLAGS := -I.. $(CFLAGS)
                   1554:         *
                   1555:         * And not get an error.
                   1556:         */
                   1557:        Boolean   oldOldVars = oldVars;
                   1558:
                   1559:        oldVars = FALSE;
1.42      christos 1560:
                   1561:        /*
                   1562:         * make sure that we set the variable the first time to nothing
                   1563:         * so that it gets substituted!
                   1564:         */
                   1565:        if (!Var_Exists(line, ctxt))
1.70      sjg      1566:            Var_Set(line, "", ctxt, 0);
1.42      christos 1567:
1.5       cgd      1568:        cp = Var_Subst(NULL, cp, ctxt, FALSE);
1.1       cgd      1569:        oldVars = oldOldVars;
1.86      sjg      1570:        freeCp = TRUE;
1.1       cgd      1571:
1.70      sjg      1572:        Var_Set(line, cp, ctxt, 0);
1.1       cgd      1573:     } else if (type == VAR_SHELL) {
1.93      christos 1574:        char *res;
1.115     christos 1575:        const char *error;
1.5       cgd      1576:
1.23      christos 1577:        if (strchr(cp, '$') != NULL) {
1.1       cgd      1578:            /*
                   1579:             * There's a dollar sign in the command, so perform variable
                   1580:             * expansion on the whole thing. The resulting string will need
                   1581:             * freeing when we're done, so set freeCmd to TRUE.
                   1582:             */
1.23      christos 1583:            cp = Var_Subst(NULL, cp, VAR_CMD, TRUE);
1.86      sjg      1584:            freeCp = TRUE;
1.1       cgd      1585:        }
                   1586:
1.115     christos 1587:        res = Cmd_Exec(cp, &error);
1.70      sjg      1588:        Var_Set(line, res, ctxt, 0);
1.23      christos 1589:        free(res);
1.1       cgd      1590:
1.115     christos 1591:        if (error)
                   1592:            Parse_Error(PARSE_WARNING, error, cp);
1.1       cgd      1593:     } else {
                   1594:        /*
                   1595:         * Normal assignment -- just do it.
                   1596:         */
1.70      sjg      1597:        Var_Set(line, cp, ctxt, 0);
1.1       cgd      1598:     }
1.69      sjg      1599:     if (strcmp(line, MAKEOVERRIDES) == 0)
1.74      tv       1600:        Main_ExportMAKEFLAGS(FALSE);    /* re-export MAKEFLAGS */
1.85      sjg      1601:     else if (strcmp(line, ".CURDIR") == 0) {
                   1602:        /*
                   1603:         * Somone is being (too?) clever...
                   1604:         * Let's pretend they know what they are doing and
                   1605:         * re-initialize the 'cur' Path.
                   1606:         */
                   1607:        Dir_InitCur(cp);
                   1608:        Dir_SetPATH();
                   1609:     }
1.86      sjg      1610:     if (freeCp)
                   1611:        free(cp);
1.1       cgd      1612: }
1.23      christos 1613:
1.1       cgd      1614:
                   1615: /*-
                   1616:  * ParseAddCmd  --
                   1617:  *     Lst_ForEach function to add a command line to all targets
                   1618:  *
1.84      wiz      1619:  * Input:
                   1620:  *     gnp             the node to which the command is to be added
                   1621:  *     cmd             the command to add
                   1622:  *
1.1       cgd      1623:  * Results:
                   1624:  *     Always 0
                   1625:  *
                   1626:  * Side Effects:
                   1627:  *     A new element is added to the commands list of the node.
                   1628:  */
1.5       cgd      1629: static int
1.84      wiz      1630: ParseAddCmd(ClientData gnp, ClientData cmd)
1.9       jtc      1631: {
1.105     christos 1632:     GNode *gn = (GNode *)gnp;
1.120     dsl      1633:
                   1634:     /* Add to last (ie current) cohort for :: targets */
1.47      mycroft  1635:     if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
1.103     christos 1636:        gn = (GNode *)Lst_Datum(Lst_Last(gn->cohorts));
1.120     dsl      1637:
                   1638:     /* if target already supplied, ignore commands */
1.59      christos 1639:     if (!(gn->type & OP_HAS_COMMANDS)) {
                   1640:        (void)Lst_AtEnd(gn->commands, cmd);
                   1641:        ParseMark(gn);
                   1642:     } else {
1.60      christos 1643: #ifdef notyet
                   1644:        /* XXX: We cannot do this until we fix the tree */
1.9       jtc      1645:        (void)Lst_AtEnd(gn->commands, cmd);
1.97      christos 1646:        Parse_Error(PARSE_WARNING,
1.61      christos 1647:                     "overriding commands for target \"%s\"; "
                   1648:                     "previous commands defined at %s: %d ignored",
1.59      christos 1649:                     gn->name, gn->fname, gn->lineno);
1.60      christos 1650: #else
1.97      christos 1651:        Parse_Error(PARSE_WARNING,
1.62      mycroft  1652:                     "duplicate script for target \"%s\" ignored",
                   1653:                     gn->name);
1.97      christos 1654:        ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING,
1.62      mycroft  1655:                            "using previous script for \"%s\" defined here",
                   1656:                            gn->name);
1.60      christos 1657: #endif
1.59      christos 1658:     }
1.9       jtc      1659:     return(0);
1.1       cgd      1660: }
                   1661:
                   1662: /*-
                   1663:  *-----------------------------------------------------------------------
                   1664:  * ParseHasCommands --
                   1665:  *     Callback procedure for Parse_File when destroying the list of
                   1666:  *     targets on the last dependency line. Marks a target as already
                   1667:  *     having commands if it does, to keep from having shell commands
                   1668:  *     on multiple dependency lines.
                   1669:  *
1.84      wiz      1670:  * Input:
                   1671:  *     gnp             Node to examine
                   1672:  *
1.1       cgd      1673:  * Results:
1.9       jtc      1674:  *     None
1.1       cgd      1675:  *
                   1676:  * Side Effects:
                   1677:  *     OP_HAS_COMMANDS may be set for the target.
                   1678:  *
                   1679:  *-----------------------------------------------------------------------
                   1680:  */
1.9       jtc      1681: static void
1.84      wiz      1682: ParseHasCommands(ClientData gnp)
1.1       cgd      1683: {
1.105     christos 1684:     GNode *gn = (GNode *)gnp;
1.1       cgd      1685:     if (!Lst_IsEmpty(gn->commands)) {
                   1686:        gn->type |= OP_HAS_COMMANDS;
                   1687:     }
                   1688: }
                   1689:
                   1690: /*-
                   1691:  *-----------------------------------------------------------------------
                   1692:  * Parse_AddIncludeDir --
                   1693:  *     Add a directory to the path searched for included makefiles
                   1694:  *     bracketed by double-quotes. Used by functions in main.c
                   1695:  *
1.84      wiz      1696:  * Input:
                   1697:  *     dir             The name of the directory to add
                   1698:  *
1.1       cgd      1699:  * Results:
                   1700:  *     None.
                   1701:  *
                   1702:  * Side Effects:
                   1703:  *     The directory is appended to the list.
                   1704:  *
                   1705:  *-----------------------------------------------------------------------
                   1706:  */
                   1707: void
1.84      wiz      1708: Parse_AddIncludeDir(char *dir)
1.1       cgd      1709: {
1.103     christos 1710:     (void)Dir_AddDir(parseIncPath, dir);
1.1       cgd      1711: }
                   1712:
                   1713: /*-
                   1714:  *---------------------------------------------------------------------
                   1715:  * ParseDoInclude  --
                   1716:  *     Push to another file.
1.27      christos 1717:  *
1.38      christos 1718:  *     The input is the line minus the `.'. A file spec is a string
1.1       cgd      1719:  *     enclosed in <> or "". The former is looked for only in sysIncPath.
                   1720:  *     The latter in . and the directories specified by -I command line
                   1721:  *     options
                   1722:  *
                   1723:  * Results:
                   1724:  *     None
                   1725:  *
                   1726:  * Side Effects:
                   1727:  *     A structure is added to the includes Lst and readProc, lineno,
                   1728:  *     fname and curFILE are altered for the new file
                   1729:  *---------------------------------------------------------------------
                   1730:  */
1.123     dsl      1731:
1.1       cgd      1732: static void
1.123     dsl      1733: Parse_include_file(char *file, Boolean isSystem, int silent)
1.1       cgd      1734: {
                   1735:     char          *fullname;   /* full pathname of file */
                   1736:     IFile         *oldFile;    /* state associated with current file */
                   1737:
                   1738:     /*
                   1739:      * Now we know the file's name and its search path, we attempt to
                   1740:      * find the durn thing. A return of NULL indicates the file don't
                   1741:      * exist.
                   1742:      */
1.105     christos 1743:     fullname = NULL;
1.76      reinoud  1744:
1.1       cgd      1745:     if (!isSystem) {
                   1746:        /*
                   1747:         * Include files contained in double-quotes are first searched for
                   1748:         * relative to the including file's location. We don't want to
                   1749:         * cd there, of course, so we just tack on the old file's
                   1750:         * leading path components and call Dir_FindFile to see if
                   1751:         * we can locate the beast.
                   1752:         */
1.19      thorpej  1753:        char      *prefEnd, *Fname;
1.1       cgd      1754:
1.19      thorpej  1755:        /* Make a temporary copy of this, to be safe. */
1.82      reinoud  1756:        Fname = estrdup(curFile.fname);
1.19      thorpej  1757:
1.103     christos 1758:        prefEnd = strrchr(Fname, '/');
1.105     christos 1759:        if (prefEnd != NULL) {
1.1       cgd      1760:            char        *newName;
1.27      christos 1761:
1.1       cgd      1762:            *prefEnd = '\0';
1.9       jtc      1763:            if (file[0] == '/')
1.24      christos 1764:                newName = estrdup(file);
1.9       jtc      1765:            else
1.97      christos 1766:                newName = str_concat(Fname, file, STR_ADDSLASH);
                   1767:            fullname = Dir_FindFile(newName, parseIncPath);
1.105     christos 1768:            if (fullname == NULL) {
1.1       cgd      1769:                fullname = Dir_FindFile(newName, dirSearchPath);
                   1770:            }
1.103     christos 1771:            free(newName);
1.1       cgd      1772:            *prefEnd = '/';
                   1773:        } else {
1.105     christos 1774:            fullname = NULL;
1.1       cgd      1775:        }
1.103     christos 1776:        free(Fname);
1.105     christos 1777:         if (fullname == NULL) {
1.76      reinoud  1778:            /*
                   1779:             * Makefile wasn't found in same directory as included makefile.
                   1780:             * Search for it first on the -I search path,
                   1781:             * then on the .PATH search path, if not found in a -I directory.
                   1782:             * XXX: Suffix specific?
                   1783:             */
1.97      christos 1784:            fullname = Dir_FindFile(file, parseIncPath);
1.105     christos 1785:            if (fullname == NULL) {
1.76      reinoud  1786:                fullname = Dir_FindFile(file, dirSearchPath);
                   1787:            }
                   1788:         }
1.1       cgd      1789:     }
                   1790:
1.76      reinoud  1791:     /* Looking for a system file or file still not found */
1.105     christos 1792:     if (fullname == NULL) {
1.1       cgd      1793:        /*
1.76      reinoud  1794:         * Look for it on the system path
1.1       cgd      1795:         */
1.123     dsl      1796:        fullname = Dir_FindFile(file,
                   1797:                    Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
1.1       cgd      1798:     }
                   1799:
1.105     christos 1800:     if (fullname == NULL) {
1.38      christos 1801:        if (!silent)
1.97      christos 1802:            Parse_Error(PARSE_FATAL, "Could not find %s", file);
1.1       cgd      1803:        return;
                   1804:     }
                   1805:
                   1806:     /*
                   1807:      * Once we find the absolute path to the file, we get to save all the
                   1808:      * state from the current file before we can start reading this
                   1809:      * include file. The state is stored in an IFile structure which
                   1810:      * is placed on a list with other IFile structures. The list makes
                   1811:      * a very nice stack to track how we got here...
                   1812:      */
1.97      christos 1813:     oldFile = emalloc(sizeof(IFile));
1.1       cgd      1814:
1.103     christos 1815:     memcpy(oldFile, &curFile, sizeof(IFile));
1.1       cgd      1816:
1.119     dsl      1817:     (void)Lst_AtFront(includes, oldFile);
1.1       cgd      1818:
                   1819:     /*
                   1820:      * Once the previous state has been saved, we can get down to reading
                   1821:      * the new file. We set up the name of the file to be the absolute
                   1822:      * name of the include file so error messages refer to the right
                   1823:      * place. Naturally enough, we start reading at line number 0.
                   1824:      */
1.82      reinoud  1825:     curFile.fname = fullname;
                   1826:     curFile.lineno = 0;
                   1827:
                   1828:     ParseSetParseFile(curFile.fname);
1.1       cgd      1829:
1.103     christos 1830:     curFile.F = fopen(fullname, "r");
1.123     dsl      1831:     curFile.P_str = curFile.P_ptr = NULL;
1.44      aidan    1832:
1.82      reinoud  1833:     if (curFile.F == (FILE * ) NULL) {
1.38      christos 1834:        if (!silent)
1.97      christos 1835:            Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
1.1       cgd      1836:        /*
                   1837:         * Pop to previous file
                   1838:         */
1.123     dsl      1839:        (void)ParseEOF();
                   1840:     }
                   1841: }
                   1842:
                   1843: static void
                   1844: ParseDoInclude(char *line)
                   1845: {
                   1846:     char          endc;                /* the character which ends the file spec */
                   1847:     char          *cp;         /* current position in file spec */
                   1848:     int                  silent = (*line != 'i') ? 1 : 0;
                   1849:     char         *file = &line[7 + silent];
                   1850:
                   1851:     /* Skip to delimiter character so we know where to look */
                   1852:     while (*file == ' ' || *file == '\t')
                   1853:        file++;
                   1854:
                   1855:     if (*file != '"' && *file != '<') {
                   1856:        Parse_Error(PARSE_FATAL,
                   1857:            ".include filename must be delimited by '\"' or '<'");
                   1858:        return;
                   1859:     }
                   1860:
                   1861:     /*
                   1862:      * Set the search path on which to find the include file based on the
                   1863:      * characters which bracket its name. Angle-brackets imply it's
                   1864:      * a system Makefile while double-quotes imply it's a user makefile
                   1865:      */
                   1866:     if (*file == '<') {
                   1867:        endc = '>';
                   1868:     } else {
                   1869:        endc = '"';
                   1870:     }
                   1871:
                   1872:     /* Skip to matching delimiter */
                   1873:     for (cp = ++file; *cp && *cp != endc; cp++)
                   1874:        continue;
                   1875:
                   1876:     if (*cp != endc) {
                   1877:        Parse_Error(PARSE_FATAL,
                   1878:                     "Unclosed %cinclude filename. '%c' expected",
                   1879:                     '.', endc);
                   1880:        return;
1.1       cgd      1881:     }
1.123     dsl      1882:     *cp = '\0';
                   1883:
                   1884:     /*
                   1885:      * Substitute for any variables in the file name before trying to
                   1886:      * find the thing.
                   1887:      */
                   1888:     file = Var_Subst(NULL, file, VAR_CMD, FALSE);
                   1889:
                   1890:     Parse_include_file(file, endc == '>', silent);
                   1891:     free(file);
1.1       cgd      1892: }
                   1893:
1.5       cgd      1894:
                   1895: /*-
                   1896:  *---------------------------------------------------------------------
1.44      aidan    1897:  * ParseSetParseFile  --
                   1898:  *     Set the .PARSEDIR and .PARSEFILE variables to the dirname and
                   1899:  *     basename of the given filename
                   1900:  *
                   1901:  * Results:
                   1902:  *     None
                   1903:  *
                   1904:  * Side Effects:
                   1905:  *     The .PARSEDIR and .PARSEFILE variables are overwritten by the
                   1906:  *     dirname and basename of the given filename.
                   1907:  *---------------------------------------------------------------------
                   1908:  */
                   1909: static void
1.122     dsl      1910: ParseSetParseFile(const char *filename)
1.44      aidan    1911: {
                   1912:     char *slash;
1.122     dsl      1913:     char *dirname;
                   1914:     int len;
1.44      aidan    1915:
1.78      reinoud  1916:     slash = strrchr(filename, '/');
1.122     dsl      1917:     if (slash == NULL) {
1.70      sjg      1918:        Var_Set(".PARSEDIR", ".", VAR_GLOBAL, 0);
1.78      reinoud  1919:        Var_Set(".PARSEFILE", filename, VAR_GLOBAL, 0);
1.44      aidan    1920:     } else {
1.122     dsl      1921:        len = slash - filename;
                   1922:        dirname = emalloc(len + 1);
                   1923:        memcpy(dirname, filename, len);
                   1924:        dirname[len] = 0;
                   1925:        Var_Set(".PARSEDIR", dirname, VAR_GLOBAL, 0);
1.70      sjg      1926:        Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL, 0);
1.122     dsl      1927:        free(dirname);
1.44      aidan    1928:     }
                   1929: }
                   1930:
                   1931:
                   1932: /*-
                   1933:  *---------------------------------------------------------------------
1.5       cgd      1934:  * Parse_FromString  --
                   1935:  *     Start Parsing from the given string
1.27      christos 1936:  *
1.5       cgd      1937:  * Results:
                   1938:  *     None
                   1939:  *
                   1940:  * Side Effects:
                   1941:  *     A structure is added to the includes Lst and readProc, lineno,
                   1942:  *     fname and curFILE are altered for the new file
                   1943:  *---------------------------------------------------------------------
                   1944:  */
                   1945: void
1.95      enami    1946: Parse_FromString(char *str, int lineno)
1.5       cgd      1947: {
                   1948:     IFile         *oldFile;    /* state associated with this file */
                   1949:
                   1950:     if (DEBUG(FOR))
1.116     dsl      1951:        (void)fprintf(debug_file, "%s\n---- at line %d\n", str, lineno);
1.5       cgd      1952:
1.97      christos 1953:     oldFile = emalloc(sizeof(IFile));
1.103     christos 1954:     memcpy(oldFile, &curFile, sizeof(IFile));
1.27      christos 1955:
1.119     dsl      1956:     (void)Lst_AtFront(includes, oldFile);
1.5       cgd      1957:
1.82      reinoud  1958:     curFile.F = NULL;
1.123     dsl      1959:     curFile.P_str = curFile.P_ptr = str;
1.95      enami    1960:     curFile.lineno = lineno;
1.122     dsl      1961:     curFile.fname = curFile.fname;
1.5       cgd      1962: }
                   1963:
                   1964:
                   1965: #ifdef SYSVINCLUDE
                   1966: /*-
                   1967:  *---------------------------------------------------------------------
                   1968:  * ParseTraditionalInclude  --
                   1969:  *     Push to another file.
1.27      christos 1970:  *
1.38      christos 1971:  *     The input is the current line. The file name(s) are
                   1972:  *     following the "include".
1.5       cgd      1973:  *
                   1974:  * Results:
                   1975:  *     None
                   1976:  *
                   1977:  * Side Effects:
                   1978:  *     A structure is added to the includes Lst and readProc, lineno,
                   1979:  *     fname and curFILE are altered for the new file
                   1980:  *---------------------------------------------------------------------
                   1981:  */
                   1982: static void
1.84      wiz      1983: ParseTraditionalInclude(char *line)
1.5       cgd      1984: {
                   1985:     char          *cp;         /* current position in file spec */
1.38      christos 1986:     int                   done = 0;
                   1987:     int                   silent = (line[0] != 'i') ? 1 : 0;
                   1988:     char         *file = &line[silent + 7];
1.123     dsl      1989:     char         *all_files;
1.5       cgd      1990:
1.111     ginsbach 1991:     if (DEBUG(PARSE)) {
1.116     dsl      1992:            fprintf(debug_file, "ParseTraditionalInclude: %s\n", file);
1.111     ginsbach 1993:     }
                   1994:
1.5       cgd      1995:     /*
                   1996:      * Skip over whitespace
                   1997:      */
1.38      christos 1998:     while (isspace((unsigned char)*file))
1.5       cgd      1999:        file++;
                   2000:
1.111     ginsbach 2001:     /*
                   2002:      * Substitute for any variables in the file name before trying to
                   2003:      * find the thing.
                   2004:      */
1.123     dsl      2005:     all_files = Var_Subst(NULL, file, VAR_CMD, FALSE);
1.111     ginsbach 2006:
1.5       cgd      2007:     if (*file == '\0') {
1.97      christos 2008:        Parse_Error(PARSE_FATAL,
1.5       cgd      2009:                     "Filename missing from \"include\"");
                   2010:        return;
                   2011:     }
                   2012:
1.123     dsl      2013:     for (file = all_files; !done; file = cp + 1) {
                   2014:        /* Skip to end of line or next whitespace */
1.38      christos 2015:        for (cp = file; *cp && !isspace((unsigned char) *cp); cp++)
                   2016:            continue;
                   2017:
                   2018:        if (*cp)
                   2019:            *cp = '\0';
                   2020:        else
                   2021:            done = 1;
                   2022:
1.123     dsl      2023:        Parse_include_file(file, FALSE, silent);
1.5       cgd      2024:     }
1.123     dsl      2025:     free(all_files);
1.5       cgd      2026: }
                   2027: #endif
                   2028:
1.1       cgd      2029: /*-
                   2030:  *---------------------------------------------------------------------
                   2031:  * ParseEOF  --
                   2032:  *     Called when EOF is reached in the current file. If we were reading
                   2033:  *     an include file, the includes stack is popped and things set up
                   2034:  *     to go back to reading the previous file at the previous location.
                   2035:  *
                   2036:  * Results:
                   2037:  *     CONTINUE if there's more to do. DONE if not.
                   2038:  *
                   2039:  * Side Effects:
                   2040:  *     The old curFILE, is closed. The includes list is shortened.
                   2041:  *     lineno, curFILE, and fname are changed if CONTINUE is returned.
                   2042:  *---------------------------------------------------------------------
                   2043:  */
                   2044: static int
1.123     dsl      2045: ParseEOF(void)
1.1       cgd      2046: {
                   2047:     IFile     *ifile;  /* the state on the top of the includes stack */
                   2048:
1.97      christos 2049:     if (Lst_IsEmpty(includes)) {
1.124   ! dsl      2050:        /* Don't close original file */
1.44      aidan    2051:        Var_Delete(".PARSEDIR", VAR_GLOBAL);
                   2052:        Var_Delete(".PARSEFILE", VAR_GLOBAL);
1.123     dsl      2053:        memset(&curFile, 0, sizeof curFile);
1.1       cgd      2054:        return (DONE);
                   2055:     }
                   2056:
1.124   ! dsl      2057:     /* XXX dispose of curFile info */
        !          2058:     /* Leak curFile.fname because all the gnodes have pointers to it */
        !          2059:     if (curFile.F)
        !          2060:        (void)fclose(curFile.F);
        !          2061:     free(curFile.P_str);
        !          2062:
1.103     christos 2063:     ifile = (IFile *)Lst_DeQueue(includes);
1.82      reinoud  2064:
1.103     christos 2065:     memcpy(&curFile, ifile, sizeof(IFile));
1.82      reinoud  2066:
1.104     christos 2067:     free(ifile);
1.44      aidan    2068:
                   2069:     /* pop the PARSEDIR/PARSEFILE variables */
1.82      reinoud  2070:     ParseSetParseFile(curFile.fname);
1.1       cgd      2071:     return (CONTINUE);
                   2072: }
                   2073:
                   2074: /*-
                   2075:  *---------------------------------------------------------------------
                   2076:  * ParseReadc  --
1.27      christos 2077:  *     Read a character from the current file
1.1       cgd      2078:  *
                   2079:  * Results:
                   2080:  *     The character that was read
                   2081:  *
                   2082:  * Side Effects:
                   2083:  *---------------------------------------------------------------------
                   2084:  */
1.107     perry    2085: static inline int
1.84      wiz      2086: ParseReadc(void)
1.5       cgd      2087: {
1.82      reinoud  2088:     if (curFile.F)
                   2089:        return fgetc(curFile.F);
1.27      christos 2090:
1.123     dsl      2091:     if (*curFile.P_ptr)
                   2092:        return *curFile.P_ptr++;
1.5       cgd      2093:     return EOF;
                   2094: }
                   2095:
                   2096:
                   2097: /*-
                   2098:  *---------------------------------------------------------------------
                   2099:  * ParseUnreadc  --
1.27      christos 2100:  *     Put back a character to the current file
1.5       cgd      2101:  *
                   2102:  * Results:
                   2103:  *     None.
                   2104:  *
                   2105:  * Side Effects:
                   2106:  *---------------------------------------------------------------------
                   2107:  */
                   2108: static void
1.84      wiz      2109: ParseUnreadc(int c)
1.5       cgd      2110: {
1.82      reinoud  2111:     if (curFile.F) {
                   2112:        ungetc(c, curFile.F);
1.5       cgd      2113:        return;
                   2114:     }
1.123     dsl      2115:     if (curFile.P_ptr) {
                   2116:        *--curFile.P_ptr = c;
1.5       cgd      2117:        return;
                   2118:     }
                   2119: }
                   2120:
                   2121:
                   2122: /* ParseSkipLine():
                   2123:  *     Grab the next line
1.84      wiz      2124:  *
                   2125:  * Input:
                   2126:  *     skip            Skip lines that don't start with .
1.95      enami    2127:  *     keep_newline    Keep newline character as is.
1.84      wiz      2128:  *
1.5       cgd      2129:  */
                   2130: static char *
1.95      enami    2131: ParseSkipLine(int skip, int keep_newline)
1.5       cgd      2132: {
                   2133:     char *line;
1.27      christos 2134:     int c, lastc, lineLength = 0;
1.5       cgd      2135:     Buffer buf;
                   2136:
1.27      christos 2137:     buf = Buf_Init(MAKE_BSIZE);
                   2138:
                   2139:     do {
                   2140:         Buf_Discard(buf, lineLength);
                   2141:         lastc = '\0';
                   2142:
                   2143:         while (((c = ParseReadc()) != '\n' || lastc == '\\')
                   2144:                && c != EOF) {
                   2145:             if (c == '\n') {
1.95      enami    2146:                 if (keep_newline)
                   2147:                     Buf_AddByte(buf, (Byte)c);
                   2148:                 else
                   2149:                     Buf_ReplaceLastByte(buf, (Byte)' ');
1.82      reinoud  2150:                 curFile.lineno++;
1.27      christos 2151:
                   2152:                 while ((c = ParseReadc()) == ' ' || c == '\t');
                   2153:
                   2154:                 if (c == EOF)
                   2155:                     break;
                   2156:             }
                   2157:
                   2158:             Buf_AddByte(buf, (Byte)c);
                   2159:             lastc = c;
                   2160:         }
                   2161:
                   2162:         if (c == EOF) {
                   2163:             Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop");
                   2164:             Buf_Destroy(buf, TRUE);
1.105     christos 2165:             return(NULL);
1.27      christos 2166:         }
                   2167:
1.82      reinoud  2168:         curFile.lineno++;
1.27      christos 2169:         Buf_AddByte(buf, (Byte)'\0');
                   2170:         line = (char *)Buf_GetAll(buf, &lineLength);
                   2171:     } while (skip == 1 && line[0] != '.');
1.1       cgd      2172:
1.27      christos 2173:     Buf_Destroy(buf, FALSE);
1.5       cgd      2174:     return line;
                   2175: }
1.1       cgd      2176:
                   2177:
                   2178: /*-
                   2179:  *---------------------------------------------------------------------
                   2180:  * ParseReadLine --
                   2181:  *     Read an entire line from the input file. Called only by Parse_File.
                   2182:  *     To facilitate escaped newlines and what have you, a character is
                   2183:  *     buffered in 'lastc', which is '\0' when no characters have been
                   2184:  *     read. When we break out of the loop, c holds the terminating
                   2185:  *     character and lastc holds a character that should be added to
                   2186:  *     the line (unless we don't read anything but a terminator).
                   2187:  *
                   2188:  * Results:
                   2189:  *     A line w/o its newline
                   2190:  *
                   2191:  * Side Effects:
                   2192:  *     Only those associated with reading a character
                   2193:  *---------------------------------------------------------------------
                   2194:  */
                   2195: static char *
1.84      wiz      2196: ParseReadLine(void)
1.1       cgd      2197: {
                   2198:     Buffer       buf;          /* Buffer for current line */
1.84      wiz      2199:     int                  c;            /* the current character */
                   2200:     int                  lastc;        /* The most-recent character */
1.1       cgd      2201:     Boolean      semiNL;       /* treat semi-colons as newlines */
                   2202:     Boolean      ignDepOp;     /* TRUE if should ignore dependency operators
                   2203:                                 * for the purposes of setting semiNL */
                   2204:     Boolean      ignComment;   /* TRUE if should ignore comments (in a
                   2205:                                 * shell command */
1.9       jtc      2206:     char         *line;        /* Result */
1.12      christos 2207:     char          *ep;         /* to strip trailing blanks */
1.1       cgd      2208:     int                  lineLength;   /* Length of result */
1.95      enami    2209:     int                  lineno;       /* Saved line # */
1.1       cgd      2210:
                   2211:     semiNL = FALSE;
                   2212:     ignDepOp = FALSE;
                   2213:     ignComment = FALSE;
                   2214:
                   2215:     /*
1.121     dsl      2216:      * Handle special-characters at the beginning of the line.
                   2217:      * A leading tab (shell command) forces us to ignore comments and
                   2218:      * dependency operators and treat semi-colons as semi-colons
                   2219:      * (by leaving semiNL FALSE).
                   2220:      * This also discards completely blank lines.
1.1       cgd      2221:      */
1.5       cgd      2222:     for (;;) {
1.1       cgd      2223:        c = ParseReadc();
1.121     dsl      2224:        if (c == '\n') {
                   2225:            curFile.lineno++;
                   2226:            continue;
                   2227:        }
1.1       cgd      2228:
1.121     dsl      2229:        if (c == '\t')
1.1       cgd      2230:            ignComment = ignDepOp = TRUE;
1.121     dsl      2231:        else if (c == '#')
                   2232:            ParseUnreadc(c);
                   2233:        break;
                   2234:     }
                   2235:
                   2236:     if (c == EOF)
                   2237:        /*
                   2238:         * Hit end-of-file, so return a NULL line to indicate this.
                   2239:         */
                   2240:        return(NULL);
                   2241:
                   2242:     lastc = c;
                   2243:     buf = Buf_Init(MAKE_BSIZE);
                   2244:
                   2245:     while (((c = ParseReadc()) != '\n' || (lastc == '\\')) && (c != EOF)) {
                   2246: test_char:
                   2247:        switch (c) {
                   2248:        case '\n':
                   2249:            /*
                   2250:             * Escaped newline: read characters until a non-space or an
                   2251:             * unescaped newline and replace them all by a single space.
                   2252:             * This is done by storing the space over the backslash and
                   2253:             * dropping through with the next nonspace. If it is a
                   2254:             * semi-colon and semiNL is TRUE, it will be recognized as a
                   2255:             * newline in the code below this...
                   2256:             */
1.82      reinoud  2257:            curFile.lineno++;
1.121     dsl      2258:            lastc = ' ';
                   2259:            while ((c = ParseReadc()) == ' ' || c == '\t')
                   2260:                continue;
                   2261:            if (c == EOF || c == '\n')
                   2262:                goto line_read;
1.1       cgd      2263:            /*
1.121     dsl      2264:             * Check for comments, semiNL's, etc. -- easier than
                   2265:             * ParseUnreadc(c); continue;
1.1       cgd      2266:             */
1.121     dsl      2267:            goto test_char;
1.27      christos 2268:
1.121     dsl      2269:        case ';':
                   2270:            /*
                   2271:             * Semi-colon: Need to see if it should be interpreted as a
                   2272:             * newline
                   2273:             */
                   2274:            if (!semiNL)
                   2275:                break;
                   2276:            /*
                   2277:             * To make sure the command that may be following this
                   2278:             * semi-colon begins with a tab, we push one back into the
                   2279:             * input stream. This will overwrite the semi-colon in the
                   2280:             * buffer. If there is no command following, this does no
                   2281:             * harm, since the newline remains in the buffer and the
                   2282:             * whole line is ignored.
                   2283:             */
                   2284:            ParseUnreadc('\t');
                   2285:            goto line_read;
1.27      christos 2286:
1.121     dsl      2287:        case '=':
                   2288:            if (!semiNL) {
1.1       cgd      2289:                /*
1.121     dsl      2290:                 * Haven't seen a dependency operator before this, so this
                   2291:                 * must be a variable assignment -- don't pay attention to
                   2292:                 * dependency operators after this.
1.1       cgd      2293:                 */
1.121     dsl      2294:                ignDepOp = TRUE;
                   2295:            } else if (lastc == ':' || lastc == '!') {
1.1       cgd      2296:                /*
1.121     dsl      2297:                 * Well, we've seen a dependency operator already, but it
                   2298:                 * was the previous character, so this is really just an
                   2299:                 * expanded variable assignment. Revert semi-colons to
                   2300:                 * being just semi-colons again and ignore any more
                   2301:                 * dependency operators.
                   2302:                 *
                   2303:                 * XXX: Note that a line like "foo : a:=b" will blow up,
                   2304:                 * but who'd write a line like that anyway?
1.1       cgd      2305:                 */
1.121     dsl      2306:                ignDepOp = TRUE;
                   2307:                semiNL = FALSE;
                   2308:            }
                   2309:            break;
                   2310:
                   2311:        case '#':
                   2312:            if (ignComment)
1.1       cgd      2313:                break;
1.121     dsl      2314:            if (
1.17      christos 2315: #if 0
1.121     dsl      2316:                    !compatMake ||
1.17      christos 2317: #endif
1.121     dsl      2318:                    (lastc == '\\')) {
                   2319:                /* Don't add the backslash. Just let the # get copied over. */
                   2320:                lastc = c;
                   2321:                continue;
1.1       cgd      2322:            }
                   2323:            /*
1.121     dsl      2324:             * If the character is a hash mark and it isn't escaped
                   2325:             * (or we're being compatible), the thing is a comment.
                   2326:             * Skip to the end of the line.
1.1       cgd      2327:             */
1.121     dsl      2328:            do {
                   2329:                c = ParseReadc();
                   2330:                /*
                   2331:                 * If we found a backslash not escaped itself it means
                   2332:                 * that the comment is going to continue in the next line.
                   2333:                 */
                   2334:                if (c == '\\')
                   2335:                    /* Discard the (escaped) character after the '\\' */
                   2336:                    ParseReadc();
                   2337:            } while ((c != '\n') && (c != EOF));
                   2338:            goto line_read;
1.27      christos 2339:
1.121     dsl      2340:        case ':':
                   2341:        case '!':
                   2342:            if (!ignDepOp) {
                   2343:                /*
                   2344:                 * A semi-colon is recognized as a newline only on
                   2345:                 * dependency lines. Dependency lines are lines with a
                   2346:                 * colon or an exclamation point. Ergo...
                   2347:                 */
                   2348:                semiNL = TRUE;
                   2349:            }
                   2350:            break;
1.1       cgd      2351:        }
1.27      christos 2352:
1.121     dsl      2353:        /* Copy in the previous character and save this one in lastc. */
                   2354:        Buf_AddByte(buf, (Byte)lastc);
                   2355:        lastc = c;
                   2356:     }
                   2357:
                   2358: line_read:
                   2359:     curFile.lineno++;
                   2360:
                   2361:     if (lastc != '\0') {
                   2362:        Buf_AddByte(buf, (Byte)lastc);
                   2363:     }
                   2364:     Buf_AddByte(buf, (Byte)'\0');
                   2365:     line = (char *)Buf_GetAll(buf, &lineLength);
                   2366:     Buf_Destroy(buf, FALSE);
                   2367:
                   2368:     /*
                   2369:      * Strip trailing blanks and tabs from the line.
                   2370:      * Do not strip a blank or tab that is preceded by a '\'
                   2371:      */
                   2372:     ep = line + lineLength - 1;
                   2373:     while (ep > line + 1 && (ep[-1] == ' ' || ep[-1] == '\t')) {
                   2374:        if (ep > line + 1 && ep[-2] == '\\')
                   2375:            break;
                   2376:        --ep;
                   2377:     }
                   2378:     *ep = 0;
                   2379:
                   2380:     if (line[0] != '.')
                   2381:        return line;
1.12      christos 2382:
1.121     dsl      2383:     /*
                   2384:      * The line might be a conditional. Ask the conditional module
                   2385:      * about it and act accordingly
                   2386:      */
                   2387:     switch (Cond_Eval(line)) {
                   2388:     case COND_SKIP:
1.12      christos 2389:        /*
1.121     dsl      2390:         * Skip to next conditional that evaluates to COND_PARSE.
1.12      christos 2391:         */
1.121     dsl      2392:        do {
                   2393:            free(line);
                   2394:            line = ParseSkipLine(1, 0);
                   2395:        } while (line && Cond_Eval(line) != COND_PARSE);
                   2396:        if (line == NULL)
                   2397:            break;
                   2398:        /*FALLTHRU*/
                   2399:     case COND_PARSE:
                   2400:        free(line);
                   2401:        line = ParseReadLine();
                   2402:        break;
                   2403:     case COND_INVALID:
                   2404:        lineno = curFile.lineno;
                   2405:        if (For_Eval(line)) {
                   2406:            int ok;
                   2407:            free(line);
                   2408:            do {
                   2409:                /* Skip after the matching end */
                   2410:                line = ParseSkipLine(0, 1);
                   2411:                if (line == NULL) {
                   2412:                    Parse_Error(PARSE_FATAL,
                   2413:                             "Unexpected end of file in for loop.\n");
1.5       cgd      2414:                    break;
1.121     dsl      2415:                }
                   2416:                ok = For_Eval(line);
1.104     christos 2417:                free(line);
1.1       cgd      2418:            }
1.121     dsl      2419:            while (ok);
                   2420:            if (line != NULL)
                   2421:                For_Run(lineno);
                   2422:            line = ParseReadLine();
1.1       cgd      2423:        }
1.121     dsl      2424:        break;
1.1       cgd      2425:     }
1.121     dsl      2426:     return (line);
1.1       cgd      2427: }
                   2428:
                   2429: /*-
                   2430:  *-----------------------------------------------------------------------
                   2431:  * ParseFinishLine --
                   2432:  *     Handle the end of a dependency group.
                   2433:  *
                   2434:  * Results:
                   2435:  *     Nothing.
                   2436:  *
                   2437:  * Side Effects:
                   2438:  *     inLine set FALSE. 'targets' list destroyed.
                   2439:  *
                   2440:  *-----------------------------------------------------------------------
                   2441:  */
                   2442: static void
1.84      wiz      2443: ParseFinishLine(void)
1.1       cgd      2444: {
                   2445:     if (inLine) {
1.119     dsl      2446:        Lst_ForEach(targets, Suff_EndTransform, NULL);
1.97      christos 2447:        Lst_Destroy(targets, ParseHasCommands);
1.9       jtc      2448:        targets = NULL;
1.1       cgd      2449:        inLine = FALSE;
                   2450:     }
                   2451: }
1.27      christos 2452:
1.1       cgd      2453:
                   2454: /*-
                   2455:  *---------------------------------------------------------------------
                   2456:  * Parse_File --
                   2457:  *     Parse a file into its component parts, incorporating it into the
                   2458:  *     current dependency graph. This is the main function and controls
                   2459:  *     almost every other function in this module
                   2460:  *
1.84      wiz      2461:  * Input:
                   2462:  *     name            the name of the file being read
                   2463:  *     stream          Stream open to makefile to parse
                   2464:  *
1.1       cgd      2465:  * Results:
                   2466:  *     None
                   2467:  *
                   2468:  * Side Effects:
                   2469:  *     Loads. Nodes are added to the list of all targets, nodes and links
                   2470:  *     are added to the dependency graph. etc. etc. etc.
                   2471:  *---------------------------------------------------------------------
                   2472:  */
                   2473: void
1.93      christos 2474: Parse_File(const char *name, FILE *stream)
1.1       cgd      2475: {
1.117     dsl      2476:     char         *cp;          /* pointer into the line */
                   2477:     char          *line;       /* the line we're working on */
                   2478: #ifndef POSIX
                   2479:     Boolean    nonSpace;
                   2480: #endif
1.1       cgd      2481:
                   2482:     inLine = FALSE;
                   2483:     fatals = 0;
1.44      aidan    2484:
1.122     dsl      2485:     curFile.fname = name;
1.82      reinoud  2486:     curFile.F = stream;
                   2487:     curFile.lineno = 0;
                   2488:
                   2489:     ParseSetParseFile(curFile.fname);
1.1       cgd      2490:
                   2491:     do {
1.117     dsl      2492:        for (; (line = ParseReadLine()) != NULL; free(line)) {
1.120     dsl      2493:            if (DEBUG(PARSE))
                   2494:                fprintf(debug_file, "ParseReadLine: %s\n", line);
1.1       cgd      2495:            if (*line == '.') {
                   2496:                /*
                   2497:                 * Lines that begin with the special character are either
                   2498:                 * include or undef directives.
                   2499:                 */
1.40      christos 2500:                for (cp = line + 1; isspace ((unsigned char)*cp); cp++) {
1.1       cgd      2501:                    continue;
                   2502:                }
1.38      christos 2503:                if (strncmp(cp, "include", 7) == 0 ||
                   2504:                    ((cp[0] == 's' || cp[0] == '-') &&
1.41      ross     2505:                    strncmp(&cp[1], "include", 7) == 0)) {
1.97      christos 2506:                    ParseDoInclude(cp);
1.117     dsl      2507:                    continue;
                   2508:                }
                   2509:                if (strncmp(cp, "undef", 5) == 0) {
1.1       cgd      2510:                    char *cp2;
1.9       jtc      2511:                    for (cp += 5; isspace((unsigned char) *cp); cp++) {
1.1       cgd      2512:                        continue;
                   2513:                    }
                   2514:
1.9       jtc      2515:                    for (cp2 = cp; !isspace((unsigned char) *cp2) &&
                   2516:                                   (*cp2 != '\0'); cp2++) {
1.1       cgd      2517:                        continue;
                   2518:                    }
                   2519:
                   2520:                    *cp2 = '\0';
                   2521:
                   2522:                    Var_Delete(cp, VAR_GLOBAL);
1.117     dsl      2523:                    continue;
1.1       cgd      2524:                }
                   2525:            }
1.27      christos 2526:            if (*line == '#') {
                   2527:                /* If we're this far, the line must be a comment. */
1.117     dsl      2528:                continue;
1.1       cgd      2529:            }
1.27      christos 2530:
1.6       jtc      2531:            if (*line == '\t') {
1.1       cgd      2532:                /*
1.6       jtc      2533:                 * If a line starts with a tab, it can only hope to be
                   2534:                 * a creation command.
1.1       cgd      2535:                 */
1.7       cgd      2536: #ifndef POSIX
1.1       cgd      2537:            shellCommand:
1.7       cgd      2538: #endif
1.40      christos 2539:                for (cp = line + 1; isspace ((unsigned char)*cp); cp++) {
1.1       cgd      2540:                    continue;
                   2541:                }
                   2542:                if (*cp) {
1.117     dsl      2543:                    if (!inLine)
1.97      christos 2544:                        Parse_Error(PARSE_FATAL,
1.25      christos 2545:                                     "Unassociated shell command \"%s\"",
1.1       cgd      2546:                                     cp);
1.117     dsl      2547:                    /*
                   2548:                     * So long as it's not a blank line and we're actually
                   2549:                     * in a dependency spec, add the command to the list of
                   2550:                     * commands of all targets in the dependency spec
                   2551:                     */
                   2552:                    Lst_ForEach(targets, ParseAddCmd, cp);
                   2553: #ifdef CLEANUP
1.119     dsl      2554:                    Lst_AtEnd(targCmds, line);
1.117     dsl      2555: #endif
                   2556:                    line = 0;
1.1       cgd      2557:                }
1.117     dsl      2558:                continue;
                   2559:            }
                   2560:
1.5       cgd      2561: #ifdef SYSVINCLUDE
1.117     dsl      2562:            if (((strncmp(line, "include", 7) == 0 &&
                   2563:                    isspace((unsigned char) line[7])) ||
                   2564:                        ((line[0] == 's' || line[0] == '-') &&
                   2565:                            strncmp(&line[1], "include", 7) == 0 &&
                   2566:                            isspace((unsigned char) line[8]))) &&
                   2567:                    strchr(line, ':') == NULL) {
1.5       cgd      2568:                /*
                   2569:                 * It's an S3/S5-style "include".
                   2570:                 */
1.97      christos 2571:                ParseTraditionalInclude(line);
1.117     dsl      2572:                continue;
                   2573:            }
1.5       cgd      2574: #endif
1.117     dsl      2575:            if (Parse_IsVar(line)) {
1.1       cgd      2576:                ParseFinishLine();
1.97      christos 2577:                Parse_DoVar(line, VAR_GLOBAL);
1.117     dsl      2578:                continue;
                   2579:            }
                   2580:
                   2581:            /*
                   2582:             * We now know it's a dependency line so it needs to have all
                   2583:             * variables expanded before being parsed. Tell the variable
                   2584:             * module to complain if some variable is undefined...
                   2585:             * To make life easier on novices, if the line is indented we
                   2586:             * first make sure the line has a dependency operator in it.
                   2587:             * If it doesn't have an operator and we're in a dependency
                   2588:             * line's script, we assume it's actually a shell command
                   2589:             * and add it to the current list of targets.
                   2590:             */
1.7       cgd      2591: #ifndef POSIX
1.117     dsl      2592:            nonSpace = FALSE;
1.7       cgd      2593: #endif
1.27      christos 2594:
1.117     dsl      2595:            cp = line;
                   2596:            if (isspace((unsigned char) line[0])) {
                   2597:                while ((*cp != '\0') && isspace((unsigned char) *cp)) {
                   2598:                    cp++;
                   2599:                }
                   2600:                if (*cp == '\0') {
                   2601:                    /* Ignore blank line in commands */
                   2602:                    continue;
                   2603:                }
1.1       cgd      2604: #ifndef POSIX
1.117     dsl      2605:                while (*cp && (ParseIsEscaped(line, cp) ||
1.77      christos 2606:                        (*cp != ':') && (*cp != '!'))) {
1.117     dsl      2607:                    nonSpace = TRUE;
                   2608:                    cp++;
                   2609:                }
1.11      mycroft  2610: #endif
1.117     dsl      2611:            }
1.27      christos 2612:
1.11      mycroft  2613: #ifndef POSIX
1.117     dsl      2614:            if (*cp == '\0') {
                   2615:                if (inLine) {
                   2616:                    Parse_Error(PARSE_WARNING,
                   2617:                                 "Shell command needs a leading tab");
                   2618:                    goto shellCommand;
                   2619:                } else if (nonSpace) {
                   2620:                    Parse_Error(PARSE_FATAL, "Missing operator");
                   2621:                }
                   2622:                continue;
                   2623:            }
1.1       cgd      2624: #endif
1.117     dsl      2625:            ParseFinishLine();
1.1       cgd      2626:
1.117     dsl      2627:            cp = Var_Subst(NULL, line, VAR_CMD, TRUE);
                   2628:            free(line);
                   2629:            line = cp;
1.27      christos 2630:
1.117     dsl      2631:            /*
                   2632:             * Need a non-circular list for the target nodes
                   2633:             */
                   2634:            if (targets)
                   2635:                Lst_Destroy(targets, NOFREE);
1.9       jtc      2636:
1.117     dsl      2637:            targets = Lst_Init(FALSE);
                   2638:            inLine = TRUE;
1.27      christos 2639:
1.117     dsl      2640:            ParseDoDependency(line);
1.1       cgd      2641:        }
                   2642:        /*
1.27      christos 2643:         * Reached EOF, but it may be just EOF of an include file...
1.1       cgd      2644:         */
1.123     dsl      2645:     } while (ParseEOF() == CONTINUE);
1.1       cgd      2646:
                   2647:     /*
                   2648:      * Make sure conditionals are clean
                   2649:      */
                   2650:     Cond_End();
                   2651:
                   2652:     if (fatals) {
1.63      christos 2653:        (void)fprintf(stderr,
                   2654:            "%s: Fatal errors encountered -- cannot continue\n",
                   2655:            progname);
1.64      sjg      2656:        PrintOnError(NULL);
1.103     christos 2657:        exit(1);
1.1       cgd      2658:     }
                   2659: }
                   2660:
                   2661: /*-
                   2662:  *---------------------------------------------------------------------
                   2663:  * Parse_Init --
                   2664:  *     initialize the parsing module
                   2665:  *
                   2666:  * Results:
                   2667:  *     none
                   2668:  *
                   2669:  * Side Effects:
                   2670:  *     the parseIncPath list is initialized...
                   2671:  *---------------------------------------------------------------------
                   2672:  */
1.5       cgd      2673: void
1.84      wiz      2674: Parse_Init(void)
1.1       cgd      2675: {
                   2676:     mainNode = NILGNODE;
1.97      christos 2677:     parseIncPath = Lst_Init(FALSE);
                   2678:     sysIncPath = Lst_Init(FALSE);
                   2679:     defIncPath = Lst_Init(FALSE);
                   2680:     includes = Lst_Init(FALSE);
1.45      mycroft  2681: #ifdef CLEANUP
1.97      christos 2682:     targCmds = Lst_Init(FALSE);
1.45      mycroft  2683: #endif
1.1       cgd      2684: }
1.9       jtc      2685:
                   2686: void
1.84      wiz      2687: Parse_End(void)
1.9       jtc      2688: {
1.45      mycroft  2689: #ifdef CLEANUP
1.106     christos 2690:     Lst_Destroy(targCmds, (FreeProc *)free);
1.9       jtc      2691:     if (targets)
                   2692:        Lst_Destroy(targets, NOFREE);
1.74      tv       2693:     Lst_Destroy(defIncPath, Dir_Destroy);
1.9       jtc      2694:     Lst_Destroy(sysIncPath, Dir_Destroy);
                   2695:     Lst_Destroy(parseIncPath, Dir_Destroy);
                   2696:     Lst_Destroy(includes, NOFREE);     /* Should be empty now */
1.45      mycroft  2697: #endif
1.9       jtc      2698: }
1.27      christos 2699:
1.1       cgd      2700:
                   2701: /*-
                   2702:  *-----------------------------------------------------------------------
                   2703:  * Parse_MainName --
                   2704:  *     Return a Lst of the main target to create for main()'s sake. If
                   2705:  *     no such target exists, we Punt with an obnoxious error message.
                   2706:  *
                   2707:  * Results:
                   2708:  *     A Lst of the single node to create.
                   2709:  *
                   2710:  * Side Effects:
                   2711:  *     None.
                   2712:  *
                   2713:  *-----------------------------------------------------------------------
                   2714:  */
                   2715: Lst
1.84      wiz      2716: Parse_MainName(void)
1.1       cgd      2717: {
1.37      fair     2718:     Lst           mainList;    /* result list */
1.1       cgd      2719:
1.97      christos 2720:     mainList = Lst_Init(FALSE);
1.1       cgd      2721:
                   2722:     if (mainNode == NILGNODE) {
1.97      christos 2723:        Punt("no target to make.");
1.1       cgd      2724:        /*NOTREACHED*/
                   2725:     } else if (mainNode->type & OP_DOUBLEDEP) {
1.119     dsl      2726:        (void)Lst_AtEnd(mainList, mainNode);
1.37      fair     2727:        Lst_Concat(mainList, mainNode->cohorts, LST_CONCNEW);
1.1       cgd      2728:     }
1.5       cgd      2729:     else
1.119     dsl      2730:        (void)Lst_AtEnd(mainList, mainNode);
1.81      pk       2731:     Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
1.37      fair     2732:     return (mainList);
1.59      christos 2733: }
                   2734:
                   2735: /*-
                   2736:  *-----------------------------------------------------------------------
                   2737:  * ParseMark --
                   2738:  *     Add the filename and lineno to the GNode so that we remember
                   2739:  *     where it was first defined.
                   2740:  *
                   2741:  * Side Effects:
                   2742:  *     None.
                   2743:  *
                   2744:  *-----------------------------------------------------------------------
                   2745:  */
                   2746: static void
1.84      wiz      2747: ParseMark(GNode *gn)
1.59      christos 2748: {
1.122     dsl      2749:     gn->fname = curFile.fname;
1.82      reinoud  2750:     gn->lineno = curFile.lineno;
1.1       cgd      2751: }

CVSweb <webmaster@jp.NetBSD.org>