1 /* $NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $ */
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
36 * Copyright (c) 1989 by Berkeley Softworks
37 * All rights reserved.
39 * This code is derived from software contributed to Berkeley by
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
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.
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
72 static char rcsid[] = "$NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $";
74 #include <sys/cdefs.h>
77 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
79 __RCSID("$NetBSD: parse.c,v 1.206 2015/11/26 00:23:04 sjg Exp $");
86 * Functions to parse a makefile.
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
93 * Most important structures are kept in Lsts. Directories for
94 * the .include "..." function are kept in the 'parseIncPath' Lst, while
95 * those for the .include <...> are kept in the 'sysIncPath' Lst. The
96 * targets currently being defined are kept in the 'targets' Lst.
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.
103 * Parse_Init Initialization function which must be
104 * called before anything else in this module
107 * Parse_End Cleanup the module
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.
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...
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.
126 #include <sys/types.h>
127 #include <sys/stat.h>
140 #include "pathnames.h"
143 #include <sys/mman.h>
146 #define MAP_COPY MAP_PRIVATE
153 ////////////////////////////////////////////////////////////
154 // types and constants
157 * Structure for a file being read ("included file")
159 typedef struct IFile {
160 char *fname; /* name of file */
161 int lineno; /* current line number in file */
162 int first_lineno; /* line number of start of text */
163 int cond_depth; /* 'if' nesting when file opened */
164 char *P_str; /* point to base of string buffer */
165 char *P_ptr; /* point to next char of string buffer */
166 char *P_end; /* point to the end of string buffer */
167 char *(*nextbuf)(void *, size_t *); /* Function to get more data */
168 void *nextbuf_arg; /* Opaque arg for nextbuf() */
169 struct loadedfile *lf; /* loadedfile object, if any */
174 * These values are returned by ParseEOF to tell Parse_File whether to
175 * CONTINUE parsing, i.e. it had only reached the end of an include file,
182 * Tokens for target attributes
186 Default, /* .DEFAULT */
188 dotError, /* .ERROR */
189 Ignore, /* .IGNORE */
190 Includes, /* .INCLUDES */
191 Interrupt, /* .INTERRUPT */
194 MFlags, /* .MFLAGS or .MAKEFLAGS */
195 Main, /* .MAIN and we don't have anything user-specified to
197 NoExport, /* .NOEXPORT */
198 NoMeta, /* .NOMETA */
199 NoMetaCmp, /* .NOMETA_CMP */
200 NoPath, /* .NOPATH */
201 Not, /* Not special */
202 NotParallel, /* .NOTPARALLEL */
204 ExObjdir, /* .OBJDIR */
206 Parallel, /* .PARALLEL */
212 Precious, /* .PRECIOUS */
213 ExShell, /* .SHELL */
214 Silent, /* .SILENT */
215 SingleShell, /* .SINGLESHELL */
217 Suffixes, /* .SUFFIXES */
219 Attribute /* Generic attribute */
229 ////////////////////////////////////////////////////////////
233 * The main target to create. This is the first target on the first
234 * dependency line in the first makefile.
236 static GNode *mainNode;
238 ////////////////////////////////////////////////////////////
241 /* targets we're working on */
245 /* command lines for targets */
250 * specType contains the SPECial TYPE of the current target. It is
251 * Not if the target is unspecial. If it *is* special, however, the children
252 * are linked as children of the parent but not vice versa. This variable is
253 * set in ParseDoDependency
255 static ParseSpecial specType;
258 * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
259 * seen, then set to each successive source on the line.
261 static GNode *predecessor;
263 ////////////////////////////////////////////////////////////
266 /* true if currently in a dependency line or its commands */
267 static Boolean inLine;
269 /* number of fatal errors */
270 static int fatals = 0;
273 * Variables for doing includes
276 /* current file being read */
277 static IFile *curFile;
279 /* stack of IFiles generated by .includes */
282 /* include paths (lists of directories) */
283 Lst parseIncPath; /* dirs for "..." includes */
284 Lst sysIncPath; /* dirs for <...> includes */
285 Lst defIncPath; /* default for sysIncPath */
287 ////////////////////////////////////////////////////////////
291 * The parseKeywords table is searched using binary search when deciding
292 * if a target or source is special. The 'spec' field is the ParseSpecial
293 * type of the keyword ("Not" if the keyword isn't special as a target) while
294 * the 'op' field is the operator to apply to the list of targets if the
295 * keyword is used as a source ("0" if the keyword isn't special as a source)
297 static const struct {
298 const char *name; /* Name of keyword */
299 ParseSpecial spec; /* Type when used as a target */
300 int op; /* Operator when used as a source */
301 } parseKeywords[] = {
302 { ".BEGIN", Begin, 0 },
303 { ".DEFAULT", Default, 0 },
305 { ".ERROR", dotError, 0 },
306 { ".EXEC", Attribute, OP_EXEC },
307 { ".IGNORE", Ignore, OP_IGNORE },
308 { ".INCLUDES", Includes, 0 },
309 { ".INTERRUPT", Interrupt, 0 },
310 { ".INVISIBLE", Attribute, OP_INVISIBLE },
311 { ".JOIN", Attribute, OP_JOIN },
312 { ".LIBS", Libs, 0 },
313 { ".MADE", Attribute, OP_MADE },
314 { ".MAIN", Main, 0 },
315 { ".MAKE", Attribute, OP_MAKE },
316 { ".MAKEFLAGS", MFlags, 0 },
317 { ".META", Meta, OP_META },
318 { ".MFLAGS", MFlags, 0 },
319 { ".NOMETA", NoMeta, OP_NOMETA },
320 { ".NOMETA_CMP", NoMetaCmp, OP_NOMETA_CMP },
321 { ".NOPATH", NoPath, OP_NOPATH },
322 { ".NOTMAIN", Attribute, OP_NOTMAIN },
323 { ".NOTPARALLEL", NotParallel, 0 },
324 { ".NO_PARALLEL", NotParallel, 0 },
325 { ".NULL", Null, 0 },
326 { ".OBJDIR", ExObjdir, 0 },
327 { ".OPTIONAL", Attribute, OP_OPTIONAL },
328 { ".ORDER", Order, 0 },
329 { ".PARALLEL", Parallel, 0 },
330 { ".PATH", ExPath, 0 },
331 { ".PHONY", Phony, OP_PHONY },
333 { ".POSIX", Posix, 0 },
335 { ".PRECIOUS", Precious, OP_PRECIOUS },
336 { ".RECURSIVE", Attribute, OP_MAKE },
337 { ".SHELL", ExShell, 0 },
338 { ".SILENT", Silent, OP_SILENT },
339 { ".SINGLESHELL", SingleShell, 0 },
340 { ".STALE", Stale, 0 },
341 { ".SUFFIXES", Suffixes, 0 },
342 { ".USE", Attribute, OP_USE },
343 { ".USEBEFORE", Attribute, OP_USEBEFORE },
344 { ".WAIT", Wait, 0 },
347 ////////////////////////////////////////////////////////////
350 static int ParseIsEscaped(const char *, const char *);
351 static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
352 MAKE_ATTR_PRINTFLIKE(4,5);
353 static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list)
354 MAKE_ATTR_PRINTFLIKE(5, 0);
355 static int ParseFindKeyword(const char *);
356 static int ParseLinkSrc(void *, void *);
357 static int ParseDoOp(void *, void *);
358 static void ParseDoSrc(int, const char *);
359 static int ParseFindMain(void *, void *);
360 static int ParseAddDir(void *, void *);
361 static int ParseClearPath(void *, void *);
362 static void ParseDoDependency(char *);
363 static int ParseAddCmd(void *, void *);
364 static void ParseHasCommands(void *);
365 static void ParseDoInclude(char *);
366 static void ParseSetParseFile(const char *);
367 static void ParseSetIncludedFile(void);
369 static void ParseTraditionalInclude(char *);
372 static void ParseGmakeExport(char *);
374 static int ParseEOF(void);
375 static char *ParseReadLine(void);
376 static void ParseFinishLine(void);
377 static void ParseMark(GNode *);
379 ////////////////////////////////////////////////////////////
383 const char *path; /* name, for error reports */
384 char *buf; /* contents buffer */
385 size_t len; /* length of contents */
386 size_t maplen; /* length of mmap area, or 0 */
387 Boolean used; /* XXX: have we used the data yet */
391 * Constructor/destructor for loadedfile
393 static struct loadedfile *
394 loadedfile_create(const char *path)
396 struct loadedfile *lf;
398 lf = bmake_malloc(sizeof(*lf));
399 lf->path = (path == NULL ? "(stdin)" : path);
408 loadedfile_destroy(struct loadedfile *lf)
410 if (lf->buf != NULL) {
411 if (lf->maplen > 0) {
413 munmap(lf->buf, lf->maplen);
423 * nextbuf() operation for loadedfile, as needed by the weird and twisted
424 * logic below. Once that's cleaned up, we can get rid of lf->used...
427 loadedfile_nextbuf(void *x, size_t *len)
429 struct loadedfile *lf = x;
440 * Try to get the size of a file.
443 load_getsize(int fd, size_t *ret)
447 if (fstat(fd, &st) < 0) {
451 if (!S_ISREG(st.st_mode)) {
456 * st_size is an off_t, which is 64 bits signed; *ret is
457 * size_t, which might be 32 bits unsigned or 64 bits
458 * unsigned. Rather than being elaborate, just punt on
459 * files that are more than 2^31 bytes. We should never
460 * see a makefile that size in practice...
462 * While we're at it reject negative sizes too, just in case.
464 if (st.st_size < 0 || st.st_size > 0x7fffffff) {
468 *ret = (size_t) st.st_size;
475 * Until the path search logic can be moved under here instead of
476 * being in the caller in another source file, we need to have the fd
477 * passed in already open. Bleh.
479 * If the path is NULL use stdin and (to insure against fd leaks)
480 * assert that the caller passed in -1.
482 static struct loadedfile *
483 loadfile(const char *path, int fd)
485 struct loadedfile *lf;
492 lf = loadedfile_create(path);
499 fd = open(path, O_RDONLY);
502 Error("%s: %s", path, strerror(errno));
509 if (load_getsize(fd, &lf->len) == SUCCESS) {
510 /* found a size, try mmap */
512 pagesize = sysconf(_SC_PAGESIZE);
519 /* round size up to a page */
520 lf->maplen = pagesize * ((lf->len + pagesize - 1)/pagesize);
523 * XXX hack for dealing with empty files; remove when
524 * we're no longer limited by interfacing to the old
525 * logic elsewhere in this file.
527 if (lf->maplen == 0) {
528 lf->maplen = pagesize;
532 * FUTURE: remove PROT_WRITE when the parser no longer
533 * needs to scribble on the input.
535 lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
536 MAP_FILE|MAP_COPY, fd, 0);
537 if (lf->buf != MAP_FAILED) {
539 if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
540 char *b = malloc(lf->len + 1);
542 memcpy(b, lf->buf, lf->len++);
543 munmap(lf->buf, lf->maplen);
551 /* cannot mmap; load the traditional way */
555 lf->buf = bmake_malloc(lf->len);
559 assert(bufpos <= lf->len);
560 if (bufpos == lf->len) {
562 lf->buf = bmake_realloc(lf->buf, lf->len);
564 result = read(fd, lf->buf + bufpos, lf->len - bufpos);
566 Error("%s: read error: %s", path, strerror(errno));
574 assert(bufpos <= lf->len);
577 /* truncate malloc region to actual length (maybe not useful) */
579 lf->buf = bmake_realloc(lf->buf, lf->len);
591 ////////////////////////////////////////////////////////////
595 *----------------------------------------------------------------------
597 * Check if the current character is escaped on the current line
600 * 0 if the character is not backslash escaped, 1 otherwise
604 *----------------------------------------------------------------------
607 ParseIsEscaped(const char *line, const char *c)
620 *----------------------------------------------------------------------
621 * ParseFindKeyword --
622 * Look in the table of keywords for one matching the given string.
628 * The index of the keyword, or -1 if it isn't there.
632 *----------------------------------------------------------------------
635 ParseFindKeyword(const char *str)
641 end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1;
644 cur = start + ((end - start) / 2);
645 diff = strcmp(str, parseKeywords[cur].name);
649 } else if (diff < 0) {
654 } while (start <= end);
659 * ParseVErrorInternal --
660 * Error message abort function for parsing. Prints out the context
661 * of the error (line number and file) as well as the message with
662 * two optional arguments.
668 * "fatals" is incremented if the level is PARSE_FATAL.
672 ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type,
673 const char *fmt, va_list ap)
675 static Boolean fatal_warning_error_printed = FALSE;
677 (void)fprintf(f, "%s: ", progname);
679 if (cfname != NULL) {
680 (void)fprintf(f, "\"");
681 if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
686 * Nothing is more annoying than not knowing
687 * which Makefile is the culprit.
689 dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
690 if (dir == NULL || *dir == '\0' ||
691 (*dir == '.' && dir[1] == '\0'))
692 dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
696 (void)fprintf(f, "%s/%s", dir, cfname);
698 (void)fprintf(f, "%s", cfname);
700 (void)fprintf(f, "\" line %d: ", (int)clineno);
702 if (type == PARSE_WARNING)
703 (void)fprintf(f, "warning: ");
704 (void)vfprintf(f, fmt, ap);
705 (void)fprintf(f, "\n");
707 if (type == PARSE_FATAL || parseWarnFatal)
709 if (parseWarnFatal && !fatal_warning_error_printed) {
710 Error("parsing warnings being treated as errors");
711 fatal_warning_error_printed = TRUE;
716 * ParseErrorInternal --
727 ParseErrorInternal(const char *cfname, size_t clineno, int type,
728 const char *fmt, ...)
733 (void)fflush(stdout);
734 ParseVErrorInternal(stderr, cfname, clineno, type, fmt, ap);
737 if (debug_file != stderr && debug_file != stdout) {
739 ParseVErrorInternal(debug_file, cfname, clineno, type, fmt, ap);
746 * External interface to ParseErrorInternal; uses the default filename
757 Parse_Error(int type, const char *fmt, ...)
763 if (curFile == NULL) {
767 fname = curFile->fname;
768 lineno = curFile->lineno;
772 (void)fflush(stdout);
773 ParseVErrorInternal(stderr, fname, lineno, type, fmt, ap);
776 if (debug_file != stderr && debug_file != stdout) {
778 ParseVErrorInternal(debug_file, fname, lineno, type, fmt, ap);
786 * Parse a .info .warning or .error directive
788 * The input is the line minus the ".". We substitute
789 * variables, print the message and exit(1) (for .error) or just print
790 * a warning if the directive is malformed.
793 ParseMessage(char *line)
802 mtype = PARSE_WARNING;
808 Parse_Error(PARSE_WARNING, "invalid syntax: \".%s\"", line);
812 while (isalpha((u_char)*line))
814 if (!isspace((u_char)*line))
815 return FALSE; /* not for us */
816 while (isspace((u_char)*line))
819 line = Var_Subst(NULL, line, VAR_CMD, FALSE, TRUE);
820 Parse_Error(mtype, "%s", line);
823 if (mtype == PARSE_FATAL) {
824 /* Terminate immediately. */
831 *---------------------------------------------------------------------
833 * Link the parent node to its new child. Used in a Lst_ForEach by
834 * ParseDoDependency. If the specType isn't 'Not', the parent
835 * isn't linked as a parent of the child.
838 * pgnp The parent node
839 * cgpn The child node
845 * New elements are added to the parents list of cgn and the
846 * children list of cgn. the unmade field of pgn is updated
847 * to reflect the additional child.
848 *---------------------------------------------------------------------
851 ParseLinkSrc(void *pgnp, void *cgnp)
853 GNode *pgn = (GNode *)pgnp;
854 GNode *cgn = (GNode *)cgnp;
856 if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (pgn->cohorts))
857 pgn = (GNode *)Lst_Datum(Lst_Last(pgn->cohorts));
858 (void)Lst_AtEnd(pgn->children, cgn);
860 (void)Lst_AtEnd(cgn->parents, pgn);
863 fprintf(debug_file, "# %s: added child %s - %s\n", __func__,
864 pgn->name, cgn->name);
865 Targ_PrintNode(pgn, 0);
866 Targ_PrintNode(cgn, 0);
872 *---------------------------------------------------------------------
874 * Apply the parsed operator to the given target node. Used in a
875 * Lst_ForEach call by ParseDoDependency once all targets have
876 * been found and their operator parsed. If the previous and new
877 * operators are incompatible, a major error is taken.
880 * gnp The node to which the operator is to be applied
881 * opp The operator to apply
887 * The type field of the node is altered to reflect any new bits in
889 *---------------------------------------------------------------------
892 ParseDoOp(void *gnp, void *opp)
894 GNode *gn = (GNode *)gnp;
895 int op = *(int *)opp;
897 * If the dependency mask of the operator and the node don't match and
898 * the node has actually had an operator applied to it before, and
899 * the operator actually has some dependency information in it, complain.
901 if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) &&
902 !OP_NOP(gn->type) && !OP_NOP(op))
904 Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name);
908 if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) {
910 * If the node was the object of a :: operator, we need to create a
911 * new instance of it for the children and commands on this dependency
912 * line. The new instance is placed on the 'cohorts' list of the
913 * initial one (note the initial one is not on its own cohorts list)
914 * and the new instance is linked to all parents of the initial
920 * Propagate copied bits to the initial node. They'll be propagated
921 * back to the rest of the cohorts later.
923 gn->type |= op & ~OP_OPMASK;
925 cohort = Targ_FindNode(gn->name, TARG_NOHASH);
929 * Make the cohort invisible as well to avoid duplicating it into
930 * other variables. True, parents of this target won't tend to do
931 * anything with their local variables, but better safe than
932 * sorry. (I think this is pointless now, since the relevant list
933 * traversals will no longer see this node anyway. -mycroft)
935 cohort->type = op | OP_INVISIBLE;
936 (void)Lst_AtEnd(gn->cohorts, cohort);
937 cohort->centurion = gn;
938 gn->unmade_cohorts += 1;
939 snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
943 * We don't want to nuke any previous flags (whatever they were) so we
944 * just OR the new operator into the old
953 *---------------------------------------------------------------------
955 * Given the name of a source, figure out if it is an attribute
956 * and apply it to the targets if it is. Else decide if there is
957 * some attribute which should be applied *to* the source because
958 * of some special target and apply it if so. Otherwise, make the
959 * source be a child of the targets in the list 'targets'
962 * tOp operator (if any) from special targets
963 * src name of the source to handle
969 * Operator bits may be added to the list of targets or to the source.
970 * The targets may have a new source added to their lists of children.
971 *---------------------------------------------------------------------
974 ParseDoSrc(int tOp, const char *src)
977 static int wait_number = 0;
980 if (*src == '.' && isupper ((unsigned char)src[1])) {
981 int keywd = ParseFindKeyword(src);
983 int op = parseKeywords[keywd].op;
985 Lst_ForEach(targets, ParseDoOp, &op);
988 if (parseKeywords[keywd].spec == Wait) {
990 * We add a .WAIT node in the dependency list.
991 * After any dynamic dependencies (and filename globbing)
992 * have happened, it is given a dependency on the each
993 * previous child back to and previous .WAIT node.
994 * The next child won't be scheduled until the .WAIT node
996 * We give each .WAIT node a unique name (mainly for diag).
998 snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number);
999 gn = Targ_FindNode(wait_src, TARG_NOHASH);
1002 gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
1003 Lst_ForEach(targets, ParseLinkSrc, gn);
1012 * If we have noted the existence of a .MAIN, it means we need
1013 * to add the sources of said target to the list of things
1014 * to create. The string 'src' is likely to be free, so we
1015 * must make a new copy of it. Note that this will only be
1016 * invoked if the user didn't specify a target on the command
1017 * line. This is to allow #ifmake's to succeed, or something...
1019 (void)Lst_AtEnd(create, bmake_strdup(src));
1021 * Add the name to the .TARGETS variable as well, so the user can
1022 * employ that, if desired.
1024 Var_Append(".TARGETS", src, VAR_GLOBAL);
1029 * Create proper predecessor/successor links between the previous
1030 * source and the current one.
1032 gn = Targ_FindNode(src, TARG_CREATE);
1035 if (predecessor != NULL) {
1036 (void)Lst_AtEnd(predecessor->order_succ, gn);
1037 (void)Lst_AtEnd(gn->order_pred, predecessor);
1039 fprintf(debug_file, "# %s: added Order dependency %s - %s\n",
1040 __func__, predecessor->name, gn->name);
1041 Targ_PrintNode(predecessor, 0);
1042 Targ_PrintNode(gn, 0);
1046 * The current source now becomes the predecessor for the next one.
1053 * If the source is not an attribute, we need to find/create
1054 * a node for it. After that we can apply any operator to it
1055 * from a special target or link it to its parents, as
1058 * In the case of a source that was the object of a :: operator,
1059 * the attribute is applied to all of its instances (as kept in
1060 * the 'cohorts' list of the node) or all the cohorts are linked
1061 * to all the targets.
1064 /* Find/create the 'src' node and attach to all targets */
1065 gn = Targ_FindNode(src, TARG_CREATE);
1071 Lst_ForEach(targets, ParseLinkSrc, gn);
1078 *-----------------------------------------------------------------------
1080 * Find a real target in the list and set it to be the main one.
1081 * Called by ParseDoDependency when a main target hasn't been found
1085 * gnp Node to examine
1088 * 0 if main not found yet, 1 if it is.
1091 * mainNode is changed and Targ_SetMain is called.
1093 *-----------------------------------------------------------------------
1096 ParseFindMain(void *gnp, void *dummy)
1098 GNode *gn = (GNode *)gnp;
1099 if ((gn->type & OP_NOTARGET) == 0) {
1102 return (dummy ? 1 : 1);
1104 return (dummy ? 0 : 0);
1109 *-----------------------------------------------------------------------
1111 * Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
1119 *-----------------------------------------------------------------------
1122 ParseAddDir(void *path, void *name)
1124 (void)Dir_AddDir((Lst) path, (char *)name);
1129 *-----------------------------------------------------------------------
1131 * Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
1139 *-----------------------------------------------------------------------
1142 ParseClearPath(void *path, void *dummy)
1144 Dir_ClearPath((Lst) path);
1145 return(dummy ? 0 : 0);
1149 *---------------------------------------------------------------------
1150 * ParseDoDependency --
1151 * Parse the dependency line in line.
1154 * line the line to parse
1160 * The nodes of the sources are linked as children to the nodes of the
1161 * targets. Some nodes may be created.
1163 * We parse a dependency line by first extracting words from the line and
1164 * finding nodes in the list of all targets with that name. This is done
1165 * until a character is encountered which is an operator character. Currently
1166 * these are only ! and :. At this point the operator is parsed and the
1167 * pointer into the line advanced until the first source is encountered.
1168 * The parsed operator is applied to each node in the 'targets' list,
1169 * which is where the nodes found for the targets are kept, by means of
1170 * the ParseDoOp function.
1171 * The sources are read in much the same way as the targets were except
1172 * that now they are expanded using the wildcarding scheme of the C-Shell
1173 * and all instances of the resulting words in the list of all targets
1174 * are found. Each of the resulting nodes is then linked to each of the
1175 * targets as one of its children.
1176 * Certain targets are handled specially. These are the ones detailed
1177 * by the specType variable.
1178 * The storing of transformation rules is also taken care of here.
1179 * A target is recognized as a transformation rule by calling
1180 * Suff_IsTransform. If it is a transformation rule, its node is gotten
1181 * from the suffix module via Suff_AddTransform rather than the standard
1182 * Targ_FindNode in the target module.
1183 *---------------------------------------------------------------------
1186 ParseDoDependency(char *line)
1188 char *cp; /* our current position */
1189 GNode *gn = NULL; /* a general purpose temporary node */
1190 int op; /* the operator on the line */
1191 char savec; /* a place to save a character */
1192 Lst paths; /* List of search paths to alter when parsing
1193 * a list of .PATH targets */
1194 int tOp; /* operator from special target */
1195 Lst sources; /* list of archive source names after
1197 Lst curTargs; /* list of target names to be found and added
1198 * to the targets list */
1199 char *lstart = line;
1202 fprintf(debug_file, "ParseDoDependency(%s)\n", line);
1208 curTargs = Lst_Init(FALSE);
1211 * First, grind through the targets.
1216 * Here LINE points to the beginning of the next word, and
1217 * LSTART points to the actual beginning of the line.
1220 /* Find the end of the next word. */
1221 for (cp = line; *cp && (ParseIsEscaped(lstart, cp) ||
1222 !(isspace((unsigned char)*cp) ||
1223 *cp == '!' || *cp == ':' || *cp == LPAREN));
1227 * Must be a dynamic source (would have been expanded
1228 * otherwise), so call the Var module to parse the puppy
1229 * so we can safely advance beyond it...There should be
1230 * no errors in this, as they would have been discovered
1231 * in the initial Var_Subst and we wouldn't be here.
1236 (void)Var_Parse(cp, VAR_CMD, TRUE, TRUE, &length, &freeIt);
1244 * If the word is followed by a left parenthesis, it's the
1245 * name of an object file inside an archive (ar file).
1247 if (!ParseIsEscaped(lstart, cp) && *cp == LPAREN) {
1249 * Archives must be handled specially to make sure the OP_ARCHV
1250 * flag is set in their 'type' field, for one thing, and because
1251 * things like "archive(file1.o file2.o file3.o)" are permissible.
1252 * Arch_ParseArchive will set 'line' to be the first non-blank
1253 * after the archive-spec. It creates/finds nodes for the members
1254 * and places them on the given list, returning SUCCESS if all
1255 * went well and FAILURE if there was an error in the
1256 * specification. On error, line should remain untouched.
1258 if (Arch_ParseArchive(&line, targets, VAR_CMD) != SUCCESS) {
1259 Parse_Error(PARSE_FATAL,
1260 "Error in archive specification: \"%s\"", line);
1263 /* Done with this word; on to the next. */
1270 * We got to the end of the line while we were still
1271 * looking at targets.
1273 * Ending a dependency line without an operator is a Bozo
1274 * no-no. As a heuristic, this is also often triggered by
1275 * undetected conflicts from cvs/rcs merges.
1277 if ((strncmp(line, "<<<<<<", 6) == 0) ||
1278 (strncmp(line, "======", 6) == 0) ||
1279 (strncmp(line, ">>>>>>", 6) == 0))
1280 Parse_Error(PARSE_FATAL,
1281 "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
1283 Parse_Error(PARSE_FATAL, lstart[0] == '.' ? "Unknown directive"
1284 : "Need an operator");
1288 /* Insert a null terminator. */
1293 * Got the word. See if it's a special target and if so set
1294 * specType to match it.
1296 if (*line == '.' && isupper ((unsigned char)line[1])) {
1298 * See if the target is a special target that must have it
1299 * or its sources handled specially.
1301 int keywd = ParseFindKeyword(line);
1303 if (specType == ExPath && parseKeywords[keywd].spec != ExPath) {
1304 Parse_Error(PARSE_FATAL, "Mismatched special targets");
1308 specType = parseKeywords[keywd].spec;
1309 tOp = parseKeywords[keywd].op;
1312 * Certain special targets have special semantics:
1313 * .PATH Have to set the dirSearchPath
1315 * .MAIN Its sources are only used if
1316 * nothing has been specified to
1318 * .DEFAULT Need to create a node to hang
1319 * commands on, but we don't want
1320 * it in the graph, nor do we want
1321 * it to be the Main Target, so we
1322 * create it, set OP_NOTMAIN and
1323 * add it to the list, setting
1324 * DEFAULT to the new node for
1325 * later use. We claim the node is
1326 * A transformation rule to make
1327 * life easier later, when we'll
1328 * use Make_HandleUse to actually
1329 * apply the .DEFAULT commands.
1330 * .PHONY The list of targets
1331 * .NOPATH Don't search for file in the path
1336 * .INTERRUPT Are not to be considered the
1338 * .NOTPARALLEL Make only one target at a time.
1339 * .SINGLESHELL Create a shell for each command.
1340 * .ORDER Must set initial predecessor to NULL
1344 if (paths == NULL) {
1345 paths = Lst_Init(FALSE);
1347 (void)Lst_AtEnd(paths, dirSearchPath);
1350 if (!Lst_IsEmpty(create)) {
1359 gn = Targ_FindNode(line, TARG_CREATE);
1362 gn->type |= OP_NOTMAIN|OP_SPECIAL;
1363 (void)Lst_AtEnd(targets, gn);
1366 gn = Targ_NewGN(".DEFAULT");
1367 gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
1368 (void)Lst_AtEnd(targets, gn);
1383 } else if (strncmp(line, ".PATH", 5) == 0) {
1385 * .PATH<suffix> has to be handled specially.
1386 * Call on the suffix module to give us a path to
1392 path = Suff_GetPath(&line[5]);
1394 Parse_Error(PARSE_FATAL,
1395 "Suffix '%s' not defined (yet)",
1399 if (paths == NULL) {
1400 paths = Lst_Init(FALSE);
1402 (void)Lst_AtEnd(paths, path);
1408 * Have word in line. Get or create its node and stick it at
1409 * the end of the targets list
1411 if ((specType == Not) && (*line != '\0')) {
1412 if (Dir_HasWildcards(line)) {
1414 * Targets are to be sought only in the current directory,
1415 * so create an empty path for the thing. Note we need to
1416 * use Dir_Destroy in the destruction of the path as the
1417 * Dir module could have added a directory to the path...
1419 Lst emptyPath = Lst_Init(FALSE);
1421 Dir_Expand(line, emptyPath, curTargs);
1423 Lst_Destroy(emptyPath, Dir_Destroy);
1426 * No wildcards, but we want to avoid code duplication,
1427 * so create a list with the word on it.
1429 (void)Lst_AtEnd(curTargs, line);
1432 /* Apply the targets. */
1434 while(!Lst_IsEmpty(curTargs)) {
1435 char *targName = (char *)Lst_DeQueue(curTargs);
1437 if (!Suff_IsTransform (targName)) {
1438 gn = Targ_FindNode(targName, TARG_CREATE);
1440 gn = Suff_AddTransform(targName);
1445 (void)Lst_AtEnd(targets, gn);
1447 } else if (specType == ExPath && *line != '.' && *line != '\0') {
1448 Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
1451 /* Don't need the inserted null terminator any more. */
1455 * If it is a special type and not .PATH, it's the only target we
1456 * allow on this line...
1458 if (specType != Not && specType != ExPath) {
1459 Boolean warning = FALSE;
1461 while (*cp && (ParseIsEscaped(lstart, cp) ||
1462 ((*cp != '!') && (*cp != ':')))) {
1463 if (ParseIsEscaped(lstart, cp) ||
1464 (*cp != ' ' && *cp != '\t')) {
1470 Parse_Error(PARSE_WARNING, "Extra target ignored");
1473 while (*cp && isspace ((unsigned char)*cp)) {
1478 } while (*line && (ParseIsEscaped(lstart, line) ||
1479 ((*line != '!') && (*line != ':'))));
1482 * Don't need the list of target names anymore...
1484 Lst_Destroy(curTargs, NULL);
1487 if (!Lst_IsEmpty(targets)) {
1490 Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored");
1499 * These four create nodes on which to hang commands, so
1500 * targets shouldn't be empty...
1504 * Nothing special here -- targets can be empty if it wants.
1511 * Have now parsed all the target names. Must parse the operator next. The
1512 * result is left in op .
1516 } else if (*cp == ':') {
1524 Parse_Error(PARSE_FATAL, lstart[0] == '.' ? "Unknown directive"
1525 : "Missing dependency operator");
1529 /* Advance beyond the operator */
1533 * Apply the operator to the target. This is how we remember which
1534 * operator a target was defined with. It fails if the operator
1535 * used isn't consistent across all references.
1537 Lst_ForEach(targets, ParseDoOp, &op);
1540 * Onward to the sources.
1542 * LINE will now point to the first source word, if any, or the
1543 * end of the string if not.
1545 while (*cp && isspace ((unsigned char)*cp)) {
1551 * Several special targets take different actions if present with no
1553 * a .SUFFIXES line with no sources clears out all old suffixes
1554 * a .PRECIOUS line makes all targets precious
1555 * a .IGNORE line ignores errors for all targets
1556 * a .SILENT line creates silence when making all targets
1557 * a .PATH removes all directories from the search path(s).
1562 Suff_ClearSuffixes();
1568 ignoreErrors = TRUE;
1574 Lst_ForEach(paths, ParseClearPath, NULL);
1579 Var_Set("%POSIX", "1003.2", VAR_GLOBAL, 0);
1585 } else if (specType == MFlags) {
1587 * Call on functions in main.c to deal with these arguments and
1588 * set the initial character to a null-character so the loop to
1589 * get sources won't get anything
1591 Main_ParseArgLine(line);
1593 } else if (specType == ExShell) {
1594 if (Job_ParseShell(line) != SUCCESS) {
1595 Parse_Error(PARSE_FATAL, "improper shell specification");
1599 } else if ((specType == NotParallel) || (specType == SingleShell)) {
1604 * NOW GO FOR THE SOURCES
1606 if ((specType == Suffixes) || (specType == ExPath) ||
1607 (specType == Includes) || (specType == Libs) ||
1608 (specType == Null) || (specType == ExObjdir))
1612 * If the target was one that doesn't take files as its sources
1613 * but takes something like suffixes, we take each
1614 * space-separated word on the line as a something and deal
1615 * with it accordingly.
1617 * If the target was .SUFFIXES, we take each source as a
1618 * suffix and add it to the list of suffixes maintained by the
1621 * If the target was a .PATH, we add the source as a directory
1622 * to search on the search path.
1624 * If it was .INCLUDES, the source is taken to be the suffix of
1625 * files which will be #included and whose search path should
1626 * be present in the .INCLUDES variable.
1628 * If it was .LIBS, the source is taken to be the suffix of
1629 * files which are considered libraries and whose search path
1630 * should be present in the .LIBS variable.
1632 * If it was .NULL, the source is the suffix to use when a file
1633 * has no valid suffix.
1635 * If it was .OBJDIR, the source is a new definition for .OBJDIR,
1636 * and will cause make to do a new chdir to that path.
1638 while (*cp && !isspace ((unsigned char)*cp)) {
1645 Suff_AddSuffix(line, &mainNode);
1648 Lst_ForEach(paths, ParseAddDir, line);
1651 Suff_AddInclude(line);
1660 Main_SetObjdir(line);
1666 if (savec != '\0') {
1669 while (*cp && isspace ((unsigned char)*cp)) {
1675 Lst_Destroy(paths, NULL);
1677 if (specType == ExPath)
1682 * The targets take real sources, so we must beware of archive
1683 * specifications (i.e. things with left parentheses in them)
1684 * and handle them accordingly.
1686 for (; *cp && !isspace ((unsigned char)*cp); cp++) {
1687 if ((*cp == LPAREN) && (cp > line) && (cp[-1] != '$')) {
1689 * Only stop for a left parenthesis if it isn't at the
1690 * start of a word (that'll be for variable changes
1691 * later) and isn't preceded by a dollar sign (a dynamic
1698 if (*cp == LPAREN) {
1699 sources = Lst_Init(FALSE);
1700 if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) {
1701 Parse_Error(PARSE_FATAL,
1702 "Error in source archive spec \"%s\"", line);
1706 while (!Lst_IsEmpty (sources)) {
1707 gn = (GNode *)Lst_DeQueue(sources);
1708 ParseDoSrc(tOp, gn->name);
1710 Lst_Destroy(sources, NULL);
1718 ParseDoSrc(tOp, line);
1720 while (*cp && isspace ((unsigned char)*cp)) {
1727 if (mainNode == NULL) {
1729 * If we have yet to decide on a main target to make, in the
1730 * absence of any user input, we want the first target on
1731 * the first dependency line that is actually a real target
1732 * (i.e. isn't a .USE or .EXEC rule) to be made.
1734 Lst_ForEach(targets, ParseFindMain, NULL);
1739 Lst_Destroy(curTargs, NULL);
1743 *---------------------------------------------------------------------
1745 * Return TRUE if the passed line is a variable assignment. A variable
1746 * assignment consists of a single word followed by optional whitespace
1747 * followed by either a += or an = operator.
1748 * This function is used both by the Parse_File function and main when
1749 * parsing the command-line arguments.
1752 * line the line to check
1755 * TRUE if it is. FALSE if it ain't
1759 *---------------------------------------------------------------------
1762 Parse_IsVar(char *line)
1764 Boolean wasSpace = FALSE; /* set TRUE if found a space */
1767 #define ISEQOPERATOR(c) \
1768 (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1771 * Skip to variable name
1773 for (;(*line == ' ') || (*line == '\t'); line++)
1776 /* Scan for one of the assignment operators outside a variable expansion */
1777 while ((ch = *line++) != 0) {
1778 if (ch == '(' || ch == '{') {
1782 if (ch == ')' || ch == '}') {
1788 while (ch == ' ' || ch == '\t') {
1793 if (ch == ':' && strncmp(line, "sh", 2) == 0) {
1800 if (*line == '=' && ISEQOPERATOR(ch))
1810 *---------------------------------------------------------------------
1812 * Take the variable assignment in the passed line and do it in the
1815 * Note: There is a lexical ambiguity with assignment modifier characters
1816 * in variable names. This routine interprets the character before the =
1817 * as a modifier. Therefore, an assignment like
1819 * is interpreted as "C+ +=" instead of "C++ =".
1822 * line a line guaranteed to be a variable assignment.
1823 * This reduces error checks
1824 * ctxt Context in which to do the assignment
1830 * the variable structure of the given variable name is altered in the
1832 *---------------------------------------------------------------------
1835 Parse_DoVar(char *line, GNode *ctxt)
1837 char *cp; /* pointer into line */
1839 VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL
1840 } type; /* Type of assignment */
1841 char *opc; /* ptr to operator character to
1842 * null-terminate the variable name */
1843 Boolean freeCp = FALSE; /* TRUE if cp needs to be freed,
1844 * i.e. if any variable expansion was
1849 * Skip to variable name
1851 while ((*line == ' ') || (*line == '\t')) {
1856 * Skip to operator character, nulling out whitespace as we go
1857 * XXX Rather than counting () and {} we should look for $ and
1858 * then expand the variable.
1860 for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) {
1861 if (*cp == '(' || *cp == '{') {
1865 if (*cp == ')' || *cp == '}') {
1869 if (depth == 0 && isspace ((unsigned char)*cp)) {
1873 opc = cp-1; /* operator is the previous character */
1874 *cp++ = '\0'; /* nuke the = */
1877 * Check operator type
1887 * If the variable already has a value, we don't do anything.
1890 if (Var_Exists(line, ctxt)) {
1909 while (opc > line && *opc != ':')
1912 if (strncmp(opc, ":sh", 3) == 0) {
1922 while (isspace ((unsigned char)*cp)) {
1926 if (type == VAR_APPEND) {
1927 Var_Append(line, cp, ctxt);
1928 } else if (type == VAR_SUBST) {
1930 * Allow variables in the old value to be undefined, but leave their
1931 * invocation alone -- this is done by forcing oldVars to be false.
1932 * XXX: This can cause recursive variables, but that's not hard to do,
1933 * and this allows someone to do something like
1935 * CFLAGS = $(.INCLUDES)
1936 * CFLAGS := -I.. $(CFLAGS)
1938 * And not get an error.
1940 Boolean oldOldVars = oldVars;
1945 * make sure that we set the variable the first time to nothing
1946 * so that it gets substituted!
1948 if (!Var_Exists(line, ctxt))
1949 Var_Set(line, "", ctxt, 0);
1951 cp = Var_Subst(NULL, cp, ctxt, FALSE, TRUE);
1952 oldVars = oldOldVars;
1955 Var_Set(line, cp, ctxt, 0);
1956 } else if (type == VAR_SHELL) {
1960 if (strchr(cp, '$') != NULL) {
1962 * There's a dollar sign in the command, so perform variable
1963 * expansion on the whole thing. The resulting string will need
1964 * freeing when we're done, so set freeCmd to TRUE.
1966 cp = Var_Subst(NULL, cp, VAR_CMD, TRUE, TRUE);
1970 res = Cmd_Exec(cp, &error);
1971 Var_Set(line, res, ctxt, 0);
1975 Parse_Error(PARSE_WARNING, error, cp);
1978 * Normal assignment -- just do it.
1980 Var_Set(line, cp, ctxt, 0);
1982 if (strcmp(line, MAKEOVERRIDES) == 0)
1983 Main_ExportMAKEFLAGS(FALSE); /* re-export MAKEFLAGS */
1984 else if (strcmp(line, ".CURDIR") == 0) {
1986 * Somone is being (too?) clever...
1987 * Let's pretend they know what they are doing and
1988 * re-initialize the 'cur' Path.
1992 } else if (strcmp(line, MAKE_JOB_PREFIX) == 0) {
1994 } else if (strcmp(line, MAKE_EXPORTED) == 0) {
2003 * ParseMaybeSubMake --
2004 * Scan the command string to see if it a possible submake node
2006 * cmd the command to scan
2008 * TRUE if the command is possibly a submake, FALSE if not.
2011 ParseMaybeSubMake(const char *cmd)
2018 #define MKV(A) { A, sizeof(A) - 1 }
2025 for (i = 0; i < sizeof(vals)/sizeof(vals[0]); i++) {
2027 if ((ptr = strstr(cmd, vals[i].name)) == NULL)
2029 if ((ptr == cmd || !isalnum((unsigned char)ptr[-1]))
2030 && !isalnum((unsigned char)ptr[vals[i].len]))
2038 * Lst_ForEach function to add a command line to all targets
2041 * gnp the node to which the command is to be added
2042 * cmd the command to add
2048 * A new element is added to the commands list of the node,
2049 * and the node can be marked as a submake node if the command is
2050 * determined to be that.
2053 ParseAddCmd(void *gnp, void *cmd)
2055 GNode *gn = (GNode *)gnp;
2057 /* Add to last (ie current) cohort for :: targets */
2058 if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
2059 gn = (GNode *)Lst_Datum(Lst_Last(gn->cohorts));
2061 /* if target already supplied, ignore commands */
2062 if (!(gn->type & OP_HAS_COMMANDS)) {
2063 (void)Lst_AtEnd(gn->commands, cmd);
2064 if (ParseMaybeSubMake(cmd))
2065 gn->type |= OP_SUBMAKE;
2069 /* XXX: We cannot do this until we fix the tree */
2070 (void)Lst_AtEnd(gn->commands, cmd);
2071 Parse_Error(PARSE_WARNING,
2072 "overriding commands for target \"%s\"; "
2073 "previous commands defined at %s: %d ignored",
2074 gn->name, gn->fname, gn->lineno);
2076 Parse_Error(PARSE_WARNING,
2077 "duplicate script for target \"%s\" ignored",
2079 ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING,
2080 "using previous script for \"%s\" defined here",
2088 *-----------------------------------------------------------------------
2089 * ParseHasCommands --
2090 * Callback procedure for Parse_File when destroying the list of
2091 * targets on the last dependency line. Marks a target as already
2092 * having commands if it does, to keep from having shell commands
2093 * on multiple dependency lines.
2096 * gnp Node to examine
2102 * OP_HAS_COMMANDS may be set for the target.
2104 *-----------------------------------------------------------------------
2107 ParseHasCommands(void *gnp)
2109 GNode *gn = (GNode *)gnp;
2110 if (!Lst_IsEmpty(gn->commands)) {
2111 gn->type |= OP_HAS_COMMANDS;
2116 *-----------------------------------------------------------------------
2117 * Parse_AddIncludeDir --
2118 * Add a directory to the path searched for included makefiles
2119 * bracketed by double-quotes. Used by functions in main.c
2122 * dir The name of the directory to add
2128 * The directory is appended to the list.
2130 *-----------------------------------------------------------------------
2133 Parse_AddIncludeDir(char *dir)
2135 (void)Dir_AddDir(parseIncPath, dir);
2139 *---------------------------------------------------------------------
2141 * Push to another file.
2143 * The input is the line minus the `.'. A file spec is a string
2144 * enclosed in <> or "". The former is looked for only in sysIncPath.
2145 * The latter in . and the directories specified by -I command line
2152 * A structure is added to the includes Lst and readProc, lineno,
2153 * fname and curFILE are altered for the new file
2154 *---------------------------------------------------------------------
2158 Parse_include_file(char *file, Boolean isSystem, int silent)
2160 struct loadedfile *lf;
2161 char *fullname; /* full pathname of file */
2163 char *prefEnd, *incdir;
2168 * Now we know the file's name and its search path, we attempt to
2169 * find the durn thing. A return of NULL indicates the file don't
2172 fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
2174 if (fullname == NULL && !isSystem) {
2176 * Include files contained in double-quotes are first searched for
2177 * relative to the including file's location. We don't want to
2178 * cd there, of course, so we just tack on the old file's
2179 * leading path components and call Dir_FindFile to see if
2180 * we can locate the beast.
2183 incdir = bmake_strdup(curFile->fname);
2184 prefEnd = strrchr(incdir, '/');
2185 if (prefEnd != NULL) {
2187 /* Now do lexical processing of leading "../" on the filename */
2188 for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) {
2189 prefEnd = strrchr(incdir + 1, '/');
2190 if (prefEnd == NULL || strcmp(prefEnd, "/..") == 0)
2194 newName = str_concat(incdir, file + i, STR_ADDSLASH);
2195 fullname = Dir_FindFile(newName, parseIncPath);
2196 if (fullname == NULL)
2197 fullname = Dir_FindFile(newName, dirSearchPath);
2202 if (fullname == NULL) {
2204 * Makefile wasn't found in same directory as included makefile.
2205 * Search for it first on the -I search path,
2206 * then on the .PATH search path, if not found in a -I directory.
2207 * If we have a suffix specific path we should use that.
2210 Lst suffPath = NULL;
2212 if ((suff = strrchr(file, '.'))) {
2213 suffPath = Suff_GetPath(suff);
2214 if (suffPath != NULL) {
2215 fullname = Dir_FindFile(file, suffPath);
2218 if (fullname == NULL) {
2219 fullname = Dir_FindFile(file, parseIncPath);
2220 if (fullname == NULL) {
2221 fullname = Dir_FindFile(file, dirSearchPath);
2227 /* Looking for a system file or file still not found */
2228 if (fullname == NULL) {
2230 * Look for it on the system path
2232 fullname = Dir_FindFile(file,
2233 Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
2236 if (fullname == NULL) {
2238 Parse_Error(PARSE_FATAL, "Could not find %s", file);
2242 /* Actually open the file... */
2243 fd = open(fullname, O_RDONLY);
2246 Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
2252 lf = loadfile(fullname, fd);
2254 ParseSetIncludedFile();
2255 /* Start reading from this file next */
2256 Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf);
2261 ParseDoInclude(char *line)
2263 char endc; /* the character which ends the file spec */
2264 char *cp; /* current position in file spec */
2265 int silent = (*line != 'i') ? 1 : 0;
2266 char *file = &line[7 + silent];
2268 /* Skip to delimiter character so we know where to look */
2269 while (*file == ' ' || *file == '\t')
2272 if (*file != '"' && *file != '<') {
2273 Parse_Error(PARSE_FATAL,
2274 ".include filename must be delimited by '\"' or '<'");
2279 * Set the search path on which to find the include file based on the
2280 * characters which bracket its name. Angle-brackets imply it's
2281 * a system Makefile while double-quotes imply it's a user makefile
2289 /* Skip to matching delimiter */
2290 for (cp = ++file; *cp && *cp != endc; cp++)
2294 Parse_Error(PARSE_FATAL,
2295 "Unclosed %cinclude filename. '%c' expected",
2302 * Substitute for any variables in the file name before trying to
2305 file = Var_Subst(NULL, file, VAR_CMD, FALSE, TRUE);
2307 Parse_include_file(file, endc == '>', silent);
2313 *---------------------------------------------------------------------
2314 * ParseSetIncludedFile --
2315 * Set the .INCLUDEDFROMFILE variable to the contents of .PARSEFILE
2316 * and the .INCLUDEDFROMDIR variable to the contents of .PARSEDIR
2322 * The .INCLUDEDFROMFILE variable is overwritten by the contents
2323 * of .PARSEFILE and the .INCLUDEDFROMDIR variable is overwriten
2324 * by the contents of .PARSEDIR
2325 *---------------------------------------------------------------------
2328 ParseSetIncludedFile(void)
2330 char *pf, *fp = NULL;
2331 char *pd, *dp = NULL;
2333 pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &fp);
2334 Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL, 0);
2335 pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &dp);
2336 Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL, 0);
2339 fprintf(debug_file, "%s: ${.INCLUDEDFROMDIR} = `%s' "
2340 "${.INCLUDEDFROMFILE} = `%s'\n", __func__, pd, pf);
2348 *---------------------------------------------------------------------
2349 * ParseSetParseFile --
2350 * Set the .PARSEDIR and .PARSEFILE variables to the dirname and
2351 * basename of the given filename
2357 * The .PARSEDIR and .PARSEFILE variables are overwritten by the
2358 * dirname and basename of the given filename.
2359 *---------------------------------------------------------------------
2362 ParseSetParseFile(const char *filename)
2364 char *slash, *dirname;
2365 const char *pd, *pf;
2368 slash = strrchr(filename, '/');
2369 if (slash == NULL) {
2370 Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL, 0);
2371 Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL, 0);
2374 len = slash - filename;
2375 dirname = bmake_malloc(len + 1);
2376 memcpy(dirname, filename, len);
2377 dirname[len] = '\0';
2378 Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL, 0);
2379 Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL, 0);
2382 fprintf(debug_file, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n",
2388 * Track the makefiles we read - so makefiles can
2389 * set dependencies on them.
2390 * Avoid adding anything more than once.
2394 ParseTrackInput(const char *name)
2399 size_t name_len = strlen(name);
2401 old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
2403 ep = old + strlen(old) - name_len;
2404 /* does it contain name? */
2405 for (; old != NULL; old = strchr(old, ' ')) {
2409 break; /* cannot contain name */
2410 if (memcmp(old, name, name_len) == 0
2411 && (old[name_len] == 0 || old[name_len] == ' '))
2415 Var_Append (MAKE_MAKEFILES, name, VAR_GLOBAL);
2424 *---------------------------------------------------------------------
2426 * Start Parsing from the given source
2432 * A structure is added to the includes Lst and readProc, lineno,
2433 * fname and curFile are altered for the new file
2434 *---------------------------------------------------------------------
2437 Parse_SetInput(const char *name, int line, int fd,
2438 char *(*nextbuf)(void *, size_t *), void *arg)
2444 name = curFile->fname;
2446 ParseTrackInput(name);
2449 fprintf(debug_file, "%s: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
2450 __func__, name, line, fd, nextbuf, arg);
2452 if (fd == -1 && nextbuf == NULL)
2456 if (curFile != NULL)
2457 /* Save exiting file info */
2458 Lst_AtFront(includes, curFile);
2460 /* Allocate and fill in new structure */
2461 curFile = bmake_malloc(sizeof *curFile);
2464 * Once the previous state has been saved, we can get down to reading
2465 * the new file. We set up the name of the file to be the absolute
2466 * name of the include file so error messages refer to the right
2469 curFile->fname = bmake_strdup(name);
2470 curFile->lineno = line;
2471 curFile->first_lineno = line;
2472 curFile->nextbuf = nextbuf;
2473 curFile->nextbuf_arg = arg;
2476 assert(nextbuf != NULL);
2478 /* Get first block of input data */
2479 buf = curFile->nextbuf(curFile->nextbuf_arg, &len);
2481 /* Was all a waste of time ... */
2483 free(curFile->fname);
2487 curFile->P_str = buf;
2488 curFile->P_ptr = buf;
2489 curFile->P_end = buf+len;
2491 curFile->cond_depth = Cond_save_depth();
2492 ParseSetParseFile(name);
2497 *---------------------------------------------------------------------
2498 * ParseTraditionalInclude --
2499 * Push to another file.
2501 * The input is the current line. The file name(s) are
2502 * following the "include".
2508 * A structure is added to the includes Lst and readProc, lineno,
2509 * fname and curFILE are altered for the new file
2510 *---------------------------------------------------------------------
2513 ParseTraditionalInclude(char *line)
2515 char *cp; /* current position in file spec */
2517 int silent = (line[0] != 'i') ? 1 : 0;
2518 char *file = &line[silent + 7];
2522 fprintf(debug_file, "%s: %s\n", __func__, file);
2526 * Skip over whitespace
2528 while (isspace((unsigned char)*file))
2532 * Substitute for any variables in the file name before trying to
2535 all_files = Var_Subst(NULL, file, VAR_CMD, FALSE, TRUE);
2537 if (*file == '\0') {
2538 Parse_Error(PARSE_FATAL,
2539 "Filename missing from \"include\"");
2543 for (file = all_files; !done; file = cp + 1) {
2544 /* Skip to end of line or next whitespace */
2545 for (cp = file; *cp && !isspace((unsigned char) *cp); cp++)
2553 Parse_include_file(file, FALSE, silent);
2561 *---------------------------------------------------------------------
2562 * ParseGmakeExport --
2563 * Parse export <variable>=<value>
2565 * And set the environment with it.
2572 *---------------------------------------------------------------------
2575 ParseGmakeExport(char *line)
2577 char *variable = &line[6];
2581 fprintf(debug_file, "%s: %s\n", __func__, variable);
2585 * Skip over whitespace
2587 while (isspace((unsigned char)*variable))
2590 for (value = variable; *value && *value != '='; value++)
2593 if (*value != '=') {
2594 Parse_Error(PARSE_FATAL,
2595 "Variable/Value missing from \"export\"");
2598 *value++ = '\0'; /* terminate variable */
2601 * Expand the value before putting it in the environment.
2603 value = Var_Subst(NULL, value, VAR_CMD, FALSE, TRUE);
2604 setenv(variable, value, 1);
2609 *---------------------------------------------------------------------
2611 * Called when EOF is reached in the current file. If we were reading
2612 * an include file, the includes stack is popped and things set up
2613 * to go back to reading the previous file at the previous location.
2616 * CONTINUE if there's more to do. DONE if not.
2619 * The old curFILE, is closed. The includes list is shortened.
2620 * lineno, curFILE, and fname are changed if CONTINUE is returned.
2621 *---------------------------------------------------------------------
2629 assert(curFile->nextbuf != NULL);
2631 /* get next input buffer, if any */
2632 ptr = curFile->nextbuf(curFile->nextbuf_arg, &len);
2633 curFile->P_ptr = ptr;
2634 curFile->P_str = ptr;
2635 curFile->P_end = ptr + len;
2636 curFile->lineno = curFile->first_lineno;
2642 /* Ensure the makefile (or loop) didn't have mismatched conditionals */
2643 Cond_restore_depth(curFile->cond_depth);
2645 if (curFile->lf != NULL) {
2646 loadedfile_destroy(curFile->lf);
2650 /* Dispose of curFile info */
2651 /* Leak curFile->fname because all the gnodes have pointers to it */
2652 free(curFile->P_str);
2655 curFile = Lst_DeQueue(includes);
2657 if (curFile == NULL) {
2658 /* We've run out of input */
2659 Var_Delete(".PARSEDIR", VAR_GLOBAL);
2660 Var_Delete(".PARSEFILE", VAR_GLOBAL);
2661 Var_Delete(".INCLUDEDFROMDIR", VAR_GLOBAL);
2662 Var_Delete(".INCLUDEDFROMFILE", VAR_GLOBAL);
2667 fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
2668 curFile->fname, curFile->lineno);
2670 /* Restore the PARSEDIR/PARSEFILE variables */
2671 ParseSetParseFile(curFile->fname);
2676 #define PARSE_SKIP 2
2679 ParseGetLine(int flags, int *length)
2681 IFile *cf = curFile;
2690 /* Loop through blank lines and comment lines */
2699 if (cf->P_end != NULL && ptr == cf->P_end) {
2705 if (ch == 0 || (ch == '\\' && ptr[1] == 0)) {
2706 if (cf->P_end == NULL)
2707 /* End of string (aka for loop) data */
2709 /* see if there is more we can parse */
2710 while (ptr++ < cf->P_end) {
2711 if ((ch = *ptr) == '\n') {
2712 if (ptr > line && ptr[-1] == '\\')
2714 Parse_Error(PARSE_WARNING,
2715 "Zero byte read from file, skipping rest of line.");
2719 if (cf->nextbuf != NULL) {
2721 * End of this buffer; return EOF and outer logic
2722 * will get the next one. (eww)
2726 Parse_Error(PARSE_FATAL, "Zero byte read from file");
2731 /* Don't treat next character as special, remember first one */
2732 if (escaped == NULL)
2740 if (ch == '#' && comment == NULL) {
2741 /* Remember first '#' for comment stripping */
2742 /* Unless previous char was '[', as in modifier :[#] */
2743 if (!(ptr > line && ptr[-1] == '['))
2749 if (!isspace((unsigned char)ch))
2750 /* We are not interested in trailing whitespace */
2754 /* Save next 'to be processed' location */
2757 /* Check we have a non-comment, non-blank line */
2758 if (line_end == line || comment == line) {
2760 /* At end of file */
2762 /* Parse another line */
2766 /* We now have a line of data */
2769 if (flags & PARSE_RAW) {
2770 /* Leave '\' (etc) in line buffer (eg 'for' lines) */
2771 *length = line_end - line;
2775 if (flags & PARSE_SKIP) {
2776 /* Completely ignore non-directives */
2779 /* We could do more of the .else/.elif/.endif checks here */
2784 /* Brutally ignore anything after a non-escaped '#' in non-commands */
2785 if (comment != NULL && line[0] != '\t') {
2790 /* If we didn't see a '\\' then the in-situ data is fine */
2791 if (escaped == NULL) {
2792 *length = line_end - line;
2796 /* Remove escapes from '\n' and '#' */
2799 for (; ; *tp++ = ch) {
2809 /* Delete '\\' at end of buffer */
2814 if (ch == '#' && line[0] != '\t')
2815 /* Delete '\\' from before '#' on non-command lines */
2819 /* Leave '\\' in buffer for later */
2821 /* Make sure we don't delete an escaped ' ' from the line end */
2826 /* Escaped '\n' replace following whitespace with a single ' ' */
2827 while (ptr[0] == ' ' || ptr[0] == '\t')
2832 /* Delete any trailing spaces - eg from empty continuations */
2833 while (tp > escaped && isspace((unsigned char)tp[-1]))
2837 *length = tp - line;
2842 *---------------------------------------------------------------------
2844 * Read an entire line from the input file. Called only by Parse_File.
2847 * A line w/o its newline
2850 * Only those associated with reading a character
2851 *---------------------------------------------------------------------
2856 char *line; /* Result */
2857 int lineLength; /* Length of result */
2858 int lineno; /* Saved line # */
2862 line = ParseGetLine(0, &lineLength);
2870 * The line might be a conditional. Ask the conditional module
2871 * about it and act accordingly
2873 switch (Cond_Eval(line)) {
2875 /* Skip to next conditional that evaluates to COND_PARSE. */
2877 line = ParseGetLine(PARSE_SKIP, &lineLength);
2878 } while (line && Cond_Eval(line) != COND_PARSE);
2884 case COND_INVALID: /* Not a conditional line */
2885 /* Check for .for loops */
2886 rval = For_Eval(line);
2888 /* Not a .for line */
2891 /* Syntax error - error printed, ignore line */
2893 /* Start of a .for loop */
2894 lineno = curFile->lineno;
2895 /* Accumulate loop lines until matching .endfor */
2897 line = ParseGetLine(PARSE_RAW, &lineLength);
2899 Parse_Error(PARSE_FATAL,
2900 "Unexpected end of file in for loop.");
2903 } while (For_Accum(line));
2904 /* Stash each iteration as a new 'input file' */
2906 /* Read next line from for-loop buffer */
2914 *-----------------------------------------------------------------------
2915 * ParseFinishLine --
2916 * Handle the end of a dependency group.
2922 * inLine set FALSE. 'targets' list destroyed.
2924 *-----------------------------------------------------------------------
2927 ParseFinishLine(void)
2930 Lst_ForEach(targets, Suff_EndTransform, NULL);
2931 Lst_Destroy(targets, ParseHasCommands);
2939 *---------------------------------------------------------------------
2941 * Parse a file into its component parts, incorporating it into the
2942 * current dependency graph. This is the main function and controls
2943 * almost every other function in this module
2946 * name the name of the file being read
2947 * fd Open file to makefile to parse
2954 * Loads. Nodes are added to the list of all targets, nodes and links
2955 * are added to the dependency graph. etc. etc. etc.
2956 *---------------------------------------------------------------------
2959 Parse_File(const char *name, int fd)
2961 char *cp; /* pointer into the line */
2962 char *line; /* the line we're working on */
2963 struct loadedfile *lf;
2965 lf = loadfile(name, fd);
2974 Parse_SetInput(name, 0, -1, loadedfile_nextbuf, lf);
2978 for (; (line = ParseReadLine()) != NULL; ) {
2980 fprintf(debug_file, "ParseReadLine (%d): '%s'\n",
2981 curFile->lineno, line);
2984 * Lines that begin with the special character may be
2985 * include or undef directives.
2986 * On the other hand they can be suffix rules (.c.o: ...)
2987 * or just dependencies for filenames that start '.'.
2989 for (cp = line + 1; isspace((unsigned char)*cp); cp++) {
2992 if (strncmp(cp, "include", 7) == 0 ||
2993 ((cp[0] == 's' || cp[0] == '-') &&
2994 strncmp(&cp[1], "include", 7) == 0)) {
2998 if (strncmp(cp, "undef", 5) == 0) {
3000 for (cp += 5; isspace((unsigned char) *cp); cp++)
3002 for (cp2 = cp; !isspace((unsigned char) *cp2) &&
3003 (*cp2 != '\0'); cp2++)
3006 Var_Delete(cp, VAR_GLOBAL);
3008 } else if (strncmp(cp, "export", 6) == 0) {
3009 for (cp += 6; isspace((unsigned char) *cp); cp++)
3013 } else if (strncmp(cp, "unexport", 8) == 0) {
3016 } else if (strncmp(cp, "info", 4) == 0 ||
3017 strncmp(cp, "error", 5) == 0 ||
3018 strncmp(cp, "warning", 7) == 0) {
3019 if (ParseMessage(cp))
3024 if (*line == '\t') {
3026 * If a line starts with a tab, it can only hope to be
3027 * a creation command.
3031 for (; isspace ((unsigned char)*cp); cp++) {
3036 Parse_Error(PARSE_FATAL,
3037 "Unassociated shell command \"%s\"",
3040 * So long as it's not a blank line and we're actually
3041 * in a dependency spec, add the command to the list of
3042 * commands of all targets in the dependency spec
3045 cp = bmake_strdup(cp);
3046 Lst_ForEach(targets, ParseAddCmd, cp);
3048 Lst_AtEnd(targCmds, cp);
3056 if (((strncmp(line, "include", 7) == 0 &&
3057 isspace((unsigned char) line[7])) ||
3058 ((line[0] == 's' || line[0] == '-') &&
3059 strncmp(&line[1], "include", 7) == 0 &&
3060 isspace((unsigned char) line[8]))) &&
3061 strchr(line, ':') == NULL) {
3063 * It's an S3/S5-style "include".
3065 ParseTraditionalInclude(line);
3070 if (strncmp(line, "export", 6) == 0 &&
3071 isspace((unsigned char) line[6]) &&
3072 strchr(line, ':') == NULL) {
3074 * It's a Gmake "export".
3076 ParseGmakeExport(line);
3080 if (Parse_IsVar(line)) {
3082 Parse_DoVar(line, VAR_GLOBAL);
3088 * To make life easier on novices, if the line is indented we
3089 * first make sure the line has a dependency operator in it.
3090 * If it doesn't have an operator and we're in a dependency
3091 * line's script, we assume it's actually a shell command
3092 * and add it to the current list of targets.
3095 if (isspace((unsigned char) line[0])) {
3096 while ((*cp != '\0') && isspace((unsigned char) *cp))
3098 while (*cp && (ParseIsEscaped(line, cp) ||
3099 (*cp != ':') && (*cp != '!'))) {
3104 Parse_Error(PARSE_WARNING,
3105 "Shell command needs a leading tab");
3114 * For some reason - probably to make the parser impossible -
3115 * a ';' can be used to separate commands from dependencies.
3116 * Attempt to avoid ';' inside substitution patterns.
3121 for (cp = line; *cp != 0; cp++) {
3122 if (*cp == '\\' && cp[1] != 0) {
3127 (cp[1] == '(' || cp[1] == '{')) {
3132 if (*cp == ')' || *cp == '}') {
3136 } else if (*cp == ';') {
3142 /* Terminate the dependency list at the ';' */
3148 * We now know it's a dependency line so it needs to have all
3149 * variables expanded before being parsed. Tell the variable
3150 * module to complain if some variable is undefined...
3152 line = Var_Subst(NULL, line, VAR_CMD, TRUE, TRUE);
3155 * Need a non-circular list for the target nodes
3158 Lst_Destroy(targets, NULL);
3160 targets = Lst_Init(FALSE);
3163 ParseDoDependency(line);
3166 /* If there were commands after a ';', add them now */
3172 * Reached EOF, but it may be just EOF of an include file...
3174 } while (ParseEOF() == CONTINUE);
3177 (void)fflush(stdout);
3178 (void)fprintf(stderr,
3179 "%s: Fatal errors encountered -- cannot continue",
3181 PrintOnError(NULL, NULL);
3187 *---------------------------------------------------------------------
3189 * initialize the parsing module
3195 * the parseIncPath list is initialized...
3196 *---------------------------------------------------------------------
3202 parseIncPath = Lst_Init(FALSE);
3203 sysIncPath = Lst_Init(FALSE);
3204 defIncPath = Lst_Init(FALSE);
3205 includes = Lst_Init(FALSE);
3207 targCmds = Lst_Init(FALSE);
3215 Lst_Destroy(targCmds, (FreeProc *)free);
3217 Lst_Destroy(targets, NULL);
3218 Lst_Destroy(defIncPath, Dir_Destroy);
3219 Lst_Destroy(sysIncPath, Dir_Destroy);
3220 Lst_Destroy(parseIncPath, Dir_Destroy);
3221 Lst_Destroy(includes, NULL); /* Should be empty now */
3227 *-----------------------------------------------------------------------
3229 * Return a Lst of the main target to create for main()'s sake. If
3230 * no such target exists, we Punt with an obnoxious error message.
3233 * A Lst of the single node to create.
3238 *-----------------------------------------------------------------------
3241 Parse_MainName(void)
3243 Lst mainList; /* result list */
3245 mainList = Lst_Init(FALSE);
3247 if (mainNode == NULL) {
3248 Punt("no target to make.");
3250 } else if (mainNode->type & OP_DOUBLEDEP) {
3251 (void)Lst_AtEnd(mainList, mainNode);
3252 Lst_Concat(mainList, mainNode->cohorts, LST_CONCNEW);
3255 (void)Lst_AtEnd(mainList, mainNode);
3256 Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
3261 *-----------------------------------------------------------------------
3263 * Add the filename and lineno to the GNode so that we remember
3264 * where it was first defined.
3269 *-----------------------------------------------------------------------
3272 ParseMark(GNode *gn)
3274 gn->fname = curFile->fname;
3275 gn->lineno = curFile->lineno;