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

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

CVSweb <webmaster@jp.NetBSD.org>