1 /* $NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg 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
73 #define mmap minix_mmap
74 #define munmap minix_munmap
76 #define MAP_COPY MAP_PRIVATE
81 static char rcsid
[] = "$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $";
83 #include <sys/cdefs.h>
86 static char sccsid
[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
88 __RCSID("$NetBSD: parse.c,v 1.185 2012/06/12 19:21:51 joerg Exp $");
95 * Functions to parse a makefile.
97 * One function, Parse_Init, must be called before any functions
98 * in this module are used. After that, the function Parse_File is the
99 * main entry point and controls most of the other functions in this
102 * Most important structures are kept in Lsts. Directories for
103 * the .include "..." function are kept in the 'parseIncPath' Lst, while
104 * those for the .include <...> are kept in the 'sysIncPath' Lst. The
105 * targets currently being defined are kept in the 'targets' Lst.
107 * The variables 'fname' and 'lineno' are used to track the name
108 * of the current file and the line number in that file so that error
109 * messages can be more meaningful.
112 * Parse_Init Initialization function which must be
113 * called before anything else in this module
116 * Parse_End Cleanup the module
118 * Parse_File Function used to parse a makefile. It must
119 * be given the name of the file, which should
120 * already have been opened, and a function
121 * to call to read a character from the file.
123 * Parse_IsVar Returns TRUE if the given line is a
124 * variable assignment. Used by MainParseArgs
125 * to determine if an argument is a target
126 * or a variable assignment. Used internally
127 * for pretty much the same thing...
129 * Parse_Error Function called when an error occurs in
130 * parsing. Used by the variable and
131 * conditional modules.
132 * Parse_MainName Returns a Lst of the main target to create.
135 #include <sys/types.h>
136 #include <sys/mman.h>
137 #include <sys/stat.h>
146 #define MAP_COPY MAP_PRIVATE
154 #include "pathnames.h"
156 ////////////////////////////////////////////////////////////
157 // types and constants
160 * Structure for a file being read ("included file")
162 typedef struct IFile
{
163 const char *fname
; /* name of file */
164 int lineno
; /* current line number in file */
165 int first_lineno
; /* line number of start of text */
166 int cond_depth
; /* 'if' nesting when file opened */
167 char *P_str
; /* point to base of string buffer */
168 char *P_ptr
; /* point to next char of string buffer */
169 char *P_end
; /* point to the end of string buffer */
170 char *(*nextbuf
)(void *, size_t *); /* Function to get more data */
171 void *nextbuf_arg
; /* Opaque arg for nextbuf() */
172 struct loadedfile
*lf
; /* loadedfile object, if any */
177 * These values are returned by ParseEOF to tell Parse_File whether to
178 * CONTINUE parsing, i.e. it had only reached the end of an include file,
185 * Tokens for target attributes
189 Default
, /* .DEFAULT */
191 dotError
, /* .ERROR */
192 Ignore
, /* .IGNORE */
193 Includes
, /* .INCLUDES */
194 Interrupt
, /* .INTERRUPT */
197 MFlags
, /* .MFLAGS or .MAKEFLAGS */
198 Main
, /* .MAIN and we don't have anything user-specified to
200 NoExport
, /* .NOEXPORT */
201 NoMeta
, /* .NOMETA */
202 NoMetaCmp
, /* .NOMETA_CMP */
203 NoPath
, /* .NOPATH */
204 Not
, /* Not special */
205 NotParallel
, /* .NOTPARALLEL */
207 ExObjdir
, /* .OBJDIR */
209 Parallel
, /* .PARALLEL */
215 Precious
, /* .PRECIOUS */
216 ExShell
, /* .SHELL */
217 Silent
, /* .SILENT */
218 SingleShell
, /* .SINGLESHELL */
219 Suffixes
, /* .SUFFIXES */
221 Attribute
/* Generic attribute */
231 ////////////////////////////////////////////////////////////
235 * The main target to create. This is the first target on the first
236 * dependency line in the first makefile.
238 static GNode
*mainNode
;
240 ////////////////////////////////////////////////////////////
243 /* targets we're working on */
247 /* command lines for targets */
252 * specType contains the SPECial TYPE of the current target. It is
253 * Not if the target is unspecial. If it *is* special, however, the children
254 * are linked as children of the parent but not vice versa. This variable is
255 * set in ParseDoDependency
257 static ParseSpecial specType
;
260 * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
261 * seen, then set to each successive source on the line.
263 static GNode
*predecessor
;
265 ////////////////////////////////////////////////////////////
268 /* true if currently in a dependency line or its commands */
269 static Boolean inLine
;
271 /* number of fatal errors */
272 static int fatals
= 0;
275 * Variables for doing includes
278 /* current file being read */
279 static IFile
*curFile
;
281 /* stack of IFiles generated by .includes */
284 /* include paths (lists of directories) */
285 Lst parseIncPath
; /* dirs for "..." includes */
286 Lst sysIncPath
; /* dirs for <...> includes */
287 Lst defIncPath
; /* default for sysIncPath */
289 ////////////////////////////////////////////////////////////
293 * The parseKeywords table is searched using binary search when deciding
294 * if a target or source is special. The 'spec' field is the ParseSpecial
295 * type of the keyword ("Not" if the keyword isn't special as a target) while
296 * the 'op' field is the operator to apply to the list of targets if the
297 * keyword is used as a source ("0" if the keyword isn't special as a source)
299 static const struct {
300 const char *name
; /* Name of keyword */
301 ParseSpecial spec
; /* Type when used as a target */
302 int op
; /* Operator when used as a source */
303 } parseKeywords
[] = {
304 { ".BEGIN", Begin
, 0 },
305 { ".DEFAULT", Default
, 0 },
307 { ".ERROR", dotError
, 0 },
308 { ".EXEC", Attribute
, OP_EXEC
},
309 { ".IGNORE", Ignore
, OP_IGNORE
},
310 { ".INCLUDES", Includes
, 0 },
311 { ".INTERRUPT", Interrupt
, 0 },
312 { ".INVISIBLE", Attribute
, OP_INVISIBLE
},
313 { ".JOIN", Attribute
, OP_JOIN
},
314 { ".LIBS", Libs
, 0 },
315 { ".MADE", Attribute
, OP_MADE
},
316 { ".MAIN", Main
, 0 },
317 { ".MAKE", Attribute
, OP_MAKE
},
318 { ".MAKEFLAGS", MFlags
, 0 },
319 { ".META", Meta
, OP_META
},
320 { ".MFLAGS", MFlags
, 0 },
321 { ".NOMETA", NoMeta
, OP_NOMETA
},
322 { ".NOMETA_CMP", NoMetaCmp
, OP_NOMETA_CMP
},
323 { ".NOPATH", NoPath
, OP_NOPATH
},
324 { ".NOTMAIN", Attribute
, OP_NOTMAIN
},
325 { ".NOTPARALLEL", NotParallel
, 0 },
326 { ".NO_PARALLEL", NotParallel
, 0 },
327 { ".NULL", Null
, 0 },
328 { ".OBJDIR", ExObjdir
, 0 },
329 { ".OPTIONAL", Attribute
, OP_OPTIONAL
},
330 { ".ORDER", Order
, 0 },
331 { ".PARALLEL", Parallel
, 0 },
332 { ".PATH", ExPath
, 0 },
333 { ".PHONY", Phony
, OP_PHONY
},
335 { ".POSIX", Posix
, 0 },
337 { ".PRECIOUS", Precious
, OP_PRECIOUS
},
338 { ".RECURSIVE", Attribute
, OP_MAKE
},
339 { ".SHELL", ExShell
, 0 },
340 { ".SILENT", Silent
, OP_SILENT
},
341 { ".SINGLESHELL", SingleShell
, 0 },
342 { ".SUFFIXES", Suffixes
, 0 },
343 { ".USE", Attribute
, OP_USE
},
344 { ".USEBEFORE", Attribute
, OP_USEBEFORE
},
345 { ".WAIT", Wait
, 0 },
348 ////////////////////////////////////////////////////////////
351 static int ParseIsEscaped(const char *, const char *);
352 static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
353 MAKE_ATTR_PRINTFLIKE(4,5);
354 static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list)
355 MAKE_ATTR_PRINTFLIKE(5, 0);
356 static int ParseFindKeyword(const char *);
357 static int ParseLinkSrc(void *, void *);
358 static int ParseDoOp(void *, void *);
359 static void ParseDoSrc(int, const char *);
360 static int ParseFindMain(void *, void *);
361 static int ParseAddDir(void *, void *);
362 static int ParseClearPath(void *, void *);
363 static void ParseDoDependency(char *);
364 static int ParseAddCmd(void *, void *);
365 static void ParseHasCommands(void *);
366 static void ParseDoInclude(char *);
367 static void ParseSetParseFile(const char *);
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) {
412 munmap(lf
->buf
, lf
->maplen
);
421 * nextbuf() operation for loadedfile, as needed by the weird and twisted
422 * logic below. Once that's cleaned up, we can get rid of lf->used...
425 loadedfile_nextbuf(void *x
, size_t *len
)
427 struct loadedfile
*lf
= x
;
438 * Try to get the size of a file.
441 load_getsize(int fd
, size_t *ret
)
445 if (fstat(fd
, &st
) < 0) {
449 if (!S_ISREG(st
.st_mode
)) {
454 * st_size is an off_t, which is 64 bits signed; *ret is
455 * size_t, which might be 32 bits unsigned or 64 bits
456 * unsigned. Rather than being elaborate, just punt on
457 * files that are more than 2^31 bytes. We should never
458 * see a makefile that size in practice...
460 * While we're at it reject negative sizes too, just in case.
462 if (st
.st_size
< 0 || st
.st_size
> 0x7fffffff) {
466 *ret
= (size_t) st
.st_size
;
473 * Until the path search logic can be moved under here instead of
474 * being in the caller in another source file, we need to have the fd
475 * passed in already open. Bleh.
477 * If the path is NULL use stdin and (to insure against fd leaks)
478 * assert that the caller passed in -1.
480 static struct loadedfile
*
481 loadfile(const char *path
, int fd
)
483 struct loadedfile
*lf
;
488 lf
= loadedfile_create(path
);
495 fd
= open(path
, O_RDONLY
);
498 Error("%s: %s", path
, strerror(errno
));
504 if (load_getsize(fd
, &lf
->len
) == SUCCESS
) {
505 /* found a size, try mmap */
506 pagesize
= sysconf(_SC_PAGESIZE
);
510 /* round size up to a page */
511 lf
->maplen
= pagesize
* ((lf
->len
+ pagesize
- 1)/pagesize
);
514 * XXX hack for dealing with empty files; remove when
515 * we're no longer limited by interfacing to the old
516 * logic elsewhere in this file.
518 if (lf
->maplen
== 0) {
519 lf
->maplen
= pagesize
;
523 * FUTURE: remove PROT_WRITE when the parser no longer
524 * needs to scribble on the input.
527 lf
->buf
= mmap(NULL
, lf
->maplen
, PROT_READ
|PROT_WRITE
,
528 MAP_FILE
|MAP_COPY
, fd
, 0);
529 if (lf
->buf
!= MAP_FAILED
) {
531 if (lf
->len
== lf
->maplen
&& lf
->buf
[lf
->len
- 1] != '\n') {
532 char *b
= malloc(lf
->len
+ 1);
534 memcpy(b
, lf
->buf
, lf
->len
++);
535 munmap(lf
->buf
, lf
->maplen
);
543 /* cannot mmap; load the traditional way */
547 lf
->buf
= bmake_malloc(lf
->len
);
551 assert(bufpos
<= lf
->len
);
552 if (bufpos
== lf
->len
) {
554 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
556 result
= read(fd
, lf
->buf
+ bufpos
, lf
->len
- bufpos
);
558 Error("%s: read error: %s", path
, strerror(errno
));
566 assert(bufpos
<= lf
->len
);
569 /* truncate malloc region to actual length (maybe not useful) */
571 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
581 ////////////////////////////////////////////////////////////
585 *----------------------------------------------------------------------
587 * Check if the current character is escaped on the current line
590 * 0 if the character is not backslash escaped, 1 otherwise
594 *----------------------------------------------------------------------
597 ParseIsEscaped(const char *line
, const char *c
)
610 *----------------------------------------------------------------------
611 * ParseFindKeyword --
612 * Look in the table of keywords for one matching the given string.
618 * The index of the keyword, or -1 if it isn't there.
622 *----------------------------------------------------------------------
625 ParseFindKeyword(const char *str
)
631 end
= (sizeof(parseKeywords
)/sizeof(parseKeywords
[0])) - 1;
634 cur
= start
+ ((end
- start
) / 2);
635 diff
= strcmp(str
, parseKeywords
[cur
].name
);
639 } else if (diff
< 0) {
644 } while (start
<= end
);
649 * ParseVErrorInternal --
650 * Error message abort function for parsing. Prints out the context
651 * of the error (line number and file) as well as the message with
652 * two optional arguments.
658 * "fatals" is incremented if the level is PARSE_FATAL.
662 ParseVErrorInternal(FILE *f
, const char *cfname
, size_t clineno
, int type
,
663 const char *fmt
, va_list ap
)
665 static Boolean fatal_warning_error_printed
= FALSE
;
667 (void)fprintf(f
, "%s: ", progname
);
669 if (cfname
!= NULL
) {
670 (void)fprintf(f
, "\"");
671 if (*cfname
!= '/' && strcmp(cfname
, "(stdin)") != 0) {
676 * Nothing is more annoying than not knowing
677 * which Makefile is the culprit.
679 dir
= Var_Value(".PARSEDIR", VAR_GLOBAL
, &cp
);
680 if (dir
== NULL
|| *dir
== '\0' ||
681 (*dir
== '.' && dir
[1] == '\0'))
682 dir
= Var_Value(".CURDIR", VAR_GLOBAL
, &cp
);
686 (void)fprintf(f
, "%s/%s", dir
, cfname
);
688 (void)fprintf(f
, "%s", cfname
);
690 (void)fprintf(f
, "\" line %d: ", (int)clineno
);
692 if (type
== PARSE_WARNING
)
693 (void)fprintf(f
, "warning: ");
694 (void)vfprintf(f
, fmt
, ap
);
695 (void)fprintf(f
, "\n");
697 if (type
== PARSE_FATAL
|| parseWarnFatal
)
699 if (parseWarnFatal
&& !fatal_warning_error_printed
) {
700 Error("parsing warnings being treated as errors");
701 fatal_warning_error_printed
= TRUE
;
706 * ParseErrorInternal --
717 ParseErrorInternal(const char *cfname
, size_t clineno
, int type
,
718 const char *fmt
, ...)
723 (void)fflush(stdout
);
724 ParseVErrorInternal(stderr
, cfname
, clineno
, type
, fmt
, ap
);
727 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
729 ParseVErrorInternal(debug_file
, cfname
, clineno
, type
, fmt
, ap
);
736 * External interface to ParseErrorInternal; uses the default filename
747 Parse_Error(int type
, const char *fmt
, ...)
753 if (curFile
== NULL
) {
757 fname
= curFile
->fname
;
758 lineno
= curFile
->lineno
;
762 (void)fflush(stdout
);
763 ParseVErrorInternal(stderr
, fname
, lineno
, type
, fmt
, ap
);
766 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
768 ParseVErrorInternal(debug_file
, fname
, lineno
, type
, fmt
, ap
);
776 * Parse a .info .warning or .error directive
778 * The input is the line minus the ".". We substitute
779 * variables, print the message and exit(1) (for .error) or just print
780 * a warning if the directive is malformed.
783 ParseMessage(char *line
)
792 mtype
= PARSE_WARNING
;
798 Parse_Error(PARSE_WARNING
, "invalid syntax: \".%s\"", line
);
802 while (isalpha((u_char
)*line
))
804 if (!isspace((u_char
)*line
))
805 return FALSE
; /* not for us */
806 while (isspace((u_char
)*line
))
809 line
= Var_Subst(NULL
, line
, VAR_CMD
, 0);
810 Parse_Error(mtype
, "%s", line
);
813 if (mtype
== PARSE_FATAL
) {
814 /* Terminate immediately. */
821 *---------------------------------------------------------------------
823 * Link the parent node to its new child. Used in a Lst_ForEach by
824 * ParseDoDependency. If the specType isn't 'Not', the parent
825 * isn't linked as a parent of the child.
828 * pgnp The parent node
829 * cgpn The child node
835 * New elements are added to the parents list of cgn and the
836 * children list of cgn. the unmade field of pgn is updated
837 * to reflect the additional child.
838 *---------------------------------------------------------------------
841 ParseLinkSrc(void *pgnp
, void *cgnp
)
843 GNode
*pgn
= (GNode
*)pgnp
;
844 GNode
*cgn
= (GNode
*)cgnp
;
846 if ((pgn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (pgn
->cohorts
))
847 pgn
= (GNode
*)Lst_Datum(Lst_Last(pgn
->cohorts
));
848 (void)Lst_AtEnd(pgn
->children
, cgn
);
850 (void)Lst_AtEnd(cgn
->parents
, pgn
);
853 fprintf(debug_file
, "# ParseLinkSrc: added child %s - %s\n", pgn
->name
, cgn
->name
);
854 Targ_PrintNode(pgn
, 0);
855 Targ_PrintNode(cgn
, 0);
861 *---------------------------------------------------------------------
863 * Apply the parsed operator to the given target node. Used in a
864 * Lst_ForEach call by ParseDoDependency once all targets have
865 * been found and their operator parsed. If the previous and new
866 * operators are incompatible, a major error is taken.
869 * gnp The node to which the operator is to be applied
870 * opp The operator to apply
876 * The type field of the node is altered to reflect any new bits in
878 *---------------------------------------------------------------------
881 ParseDoOp(void *gnp
, void *opp
)
883 GNode
*gn
= (GNode
*)gnp
;
884 int op
= *(int *)opp
;
886 * If the dependency mask of the operator and the node don't match and
887 * the node has actually had an operator applied to it before, and
888 * the operator actually has some dependency information in it, complain.
890 if (((op
& OP_OPMASK
) != (gn
->type
& OP_OPMASK
)) &&
891 !OP_NOP(gn
->type
) && !OP_NOP(op
))
893 Parse_Error(PARSE_FATAL
, "Inconsistent operator for %s", gn
->name
);
897 if ((op
== OP_DOUBLEDEP
) && ((gn
->type
& OP_OPMASK
) == OP_DOUBLEDEP
)) {
899 * If the node was the object of a :: operator, we need to create a
900 * new instance of it for the children and commands on this dependency
901 * line. The new instance is placed on the 'cohorts' list of the
902 * initial one (note the initial one is not on its own cohorts list)
903 * and the new instance is linked to all parents of the initial
909 * Propagate copied bits to the initial node. They'll be propagated
910 * back to the rest of the cohorts later.
912 gn
->type
|= op
& ~OP_OPMASK
;
914 cohort
= Targ_FindNode(gn
->name
, TARG_NOHASH
);
916 * Make the cohort invisible as well to avoid duplicating it into
917 * other variables. True, parents of this target won't tend to do
918 * anything with their local variables, but better safe than
919 * sorry. (I think this is pointless now, since the relevant list
920 * traversals will no longer see this node anyway. -mycroft)
922 cohort
->type
= op
| OP_INVISIBLE
;
923 (void)Lst_AtEnd(gn
->cohorts
, cohort
);
924 cohort
->centurion
= gn
;
925 gn
->unmade_cohorts
+= 1;
926 snprintf(cohort
->cohort_num
, sizeof cohort
->cohort_num
, "#%d",
930 * We don't want to nuke any previous flags (whatever they were) so we
931 * just OR the new operator into the old
940 *---------------------------------------------------------------------
942 * Given the name of a source, figure out if it is an attribute
943 * and apply it to the targets if it is. Else decide if there is
944 * some attribute which should be applied *to* the source because
945 * of some special target and apply it if so. Otherwise, make the
946 * source be a child of the targets in the list 'targets'
949 * tOp operator (if any) from special targets
950 * src name of the source to handle
956 * Operator bits may be added to the list of targets or to the source.
957 * The targets may have a new source added to their lists of children.
958 *---------------------------------------------------------------------
961 ParseDoSrc(int tOp
, const char *src
)
964 static int wait_number
= 0;
967 if (*src
== '.' && isupper ((unsigned char)src
[1])) {
968 int keywd
= ParseFindKeyword(src
);
970 int op
= parseKeywords
[keywd
].op
;
972 Lst_ForEach(targets
, ParseDoOp
, &op
);
975 if (parseKeywords
[keywd
].spec
== Wait
) {
977 * We add a .WAIT node in the dependency list.
978 * After any dynamic dependencies (and filename globbing)
979 * have happened, it is given a dependency on the each
980 * previous child back to and previous .WAIT node.
981 * The next child won't be scheduled until the .WAIT node
983 * We give each .WAIT node a unique name (mainly for diag).
985 snprintf(wait_src
, sizeof wait_src
, ".WAIT_%u", ++wait_number
);
986 gn
= Targ_FindNode(wait_src
, TARG_NOHASH
);
987 gn
->type
= OP_WAIT
| OP_PHONY
| OP_DEPENDS
| OP_NOTMAIN
;
988 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
997 * If we have noted the existence of a .MAIN, it means we need
998 * to add the sources of said target to the list of things
999 * to create. The string 'src' is likely to be free, so we
1000 * must make a new copy of it. Note that this will only be
1001 * invoked if the user didn't specify a target on the command
1002 * line. This is to allow #ifmake's to succeed, or something...
1004 (void)Lst_AtEnd(create
, bmake_strdup(src
));
1006 * Add the name to the .TARGETS variable as well, so the user can
1007 * employ that, if desired.
1009 Var_Append(".TARGETS", src
, VAR_GLOBAL
);
1014 * Create proper predecessor/successor links between the previous
1015 * source and the current one.
1017 gn
= Targ_FindNode(src
, TARG_CREATE
);
1018 if (predecessor
!= NULL
) {
1019 (void)Lst_AtEnd(predecessor
->order_succ
, gn
);
1020 (void)Lst_AtEnd(gn
->order_pred
, predecessor
);
1022 fprintf(debug_file
, "# ParseDoSrc: added Order dependency %s - %s\n",
1023 predecessor
->name
, gn
->name
);
1024 Targ_PrintNode(predecessor
, 0);
1025 Targ_PrintNode(gn
, 0);
1029 * The current source now becomes the predecessor for the next one.
1036 * If the source is not an attribute, we need to find/create
1037 * a node for it. After that we can apply any operator to it
1038 * from a special target or link it to its parents, as
1041 * In the case of a source that was the object of a :: operator,
1042 * the attribute is applied to all of its instances (as kept in
1043 * the 'cohorts' list of the node) or all the cohorts are linked
1044 * to all the targets.
1047 /* Find/create the 'src' node and attach to all targets */
1048 gn
= Targ_FindNode(src
, TARG_CREATE
);
1052 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
1059 *-----------------------------------------------------------------------
1061 * Find a real target in the list and set it to be the main one.
1062 * Called by ParseDoDependency when a main target hasn't been found
1066 * gnp Node to examine
1069 * 0 if main not found yet, 1 if it is.
1072 * mainNode is changed and Targ_SetMain is called.
1074 *-----------------------------------------------------------------------
1077 ParseFindMain(void *gnp
, void *dummy
)
1079 GNode
*gn
= (GNode
*)gnp
;
1080 if ((gn
->type
& OP_NOTARGET
) == 0) {
1083 return (dummy
? 1 : 1);
1085 return (dummy
? 0 : 0);
1090 *-----------------------------------------------------------------------
1092 * Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
1100 *-----------------------------------------------------------------------
1103 ParseAddDir(void *path
, void *name
)
1105 (void)Dir_AddDir((Lst
) path
, (char *)name
);
1110 *-----------------------------------------------------------------------
1112 * Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
1120 *-----------------------------------------------------------------------
1123 ParseClearPath(void *path
, void *dummy
)
1125 Dir_ClearPath((Lst
) path
);
1126 return(dummy
? 0 : 0);
1130 *---------------------------------------------------------------------
1131 * ParseDoDependency --
1132 * Parse the dependency line in line.
1135 * line the line to parse
1141 * The nodes of the sources are linked as children to the nodes of the
1142 * targets. Some nodes may be created.
1144 * We parse a dependency line by first extracting words from the line and
1145 * finding nodes in the list of all targets with that name. This is done
1146 * until a character is encountered which is an operator character. Currently
1147 * these are only ! and :. At this point the operator is parsed and the
1148 * pointer into the line advanced until the first source is encountered.
1149 * The parsed operator is applied to each node in the 'targets' list,
1150 * which is where the nodes found for the targets are kept, by means of
1151 * the ParseDoOp function.
1152 * The sources are read in much the same way as the targets were except
1153 * that now they are expanded using the wildcarding scheme of the C-Shell
1154 * and all instances of the resulting words in the list of all targets
1155 * are found. Each of the resulting nodes is then linked to each of the
1156 * targets as one of its children.
1157 * Certain targets are handled specially. These are the ones detailed
1158 * by the specType variable.
1159 * The storing of transformation rules is also taken care of here.
1160 * A target is recognized as a transformation rule by calling
1161 * Suff_IsTransform. If it is a transformation rule, its node is gotten
1162 * from the suffix module via Suff_AddTransform rather than the standard
1163 * Targ_FindNode in the target module.
1164 *---------------------------------------------------------------------
1167 ParseDoDependency(char *line
)
1169 char *cp
; /* our current position */
1170 GNode
*gn
= NULL
; /* a general purpose temporary node */
1171 int op
; /* the operator on the line */
1172 char savec
; /* a place to save a character */
1173 Lst paths
; /* List of search paths to alter when parsing
1174 * a list of .PATH targets */
1175 int tOp
; /* operator from special target */
1176 Lst sources
; /* list of archive source names after
1178 Lst curTargs
; /* list of target names to be found and added
1179 * to the targets list */
1180 char *lstart
= line
;
1183 fprintf(debug_file
, "ParseDoDependency(%s)\n", line
);
1189 curTargs
= Lst_Init(FALSE
);
1192 for (cp
= line
; *cp
&& (ParseIsEscaped(lstart
, cp
) ||
1193 !(isspace((unsigned char)*cp
) ||
1194 *cp
== '!' || *cp
== ':' || *cp
== LPAREN
));
1198 * Must be a dynamic source (would have been expanded
1199 * otherwise), so call the Var module to parse the puppy
1200 * so we can safely advance beyond it...There should be
1201 * no errors in this, as they would have been discovered
1202 * in the initial Var_Subst and we wouldn't be here.
1208 result
= Var_Parse(cp
, VAR_CMD
, TRUE
, &length
, &freeIt
);
1215 if (!ParseIsEscaped(lstart
, cp
) && *cp
== LPAREN
) {
1217 * Archives must be handled specially to make sure the OP_ARCHV
1218 * flag is set in their 'type' field, for one thing, and because
1219 * things like "archive(file1.o file2.o file3.o)" are permissible.
1220 * Arch_ParseArchive will set 'line' to be the first non-blank
1221 * after the archive-spec. It creates/finds nodes for the members
1222 * and places them on the given list, returning SUCCESS if all
1223 * went well and FAILURE if there was an error in the
1224 * specification. On error, line should remain untouched.
1226 if (Arch_ParseArchive(&line
, targets
, VAR_CMD
) != SUCCESS
) {
1227 Parse_Error(PARSE_FATAL
,
1228 "Error in archive specification: \"%s\"", line
);
1238 * Ending a dependency line without an operator is a Bozo
1239 * no-no. As a heuristic, this is also often triggered by
1240 * undetected conflicts from cvs/rcs merges.
1242 if ((strncmp(line
, "<<<<<<", 6) == 0) ||
1243 (strncmp(line
, "======", 6) == 0) ||
1244 (strncmp(line
, ">>>>>>", 6) == 0))
1245 Parse_Error(PARSE_FATAL
,
1246 "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
1248 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1249 : "Need an operator");
1255 * Have a word in line. See if it's a special target and set
1256 * specType to match it.
1258 if (*line
== '.' && isupper ((unsigned char)line
[1])) {
1260 * See if the target is a special target that must have it
1261 * or its sources handled specially.
1263 int keywd
= ParseFindKeyword(line
);
1265 if (specType
== ExPath
&& parseKeywords
[keywd
].spec
!= ExPath
) {
1266 Parse_Error(PARSE_FATAL
, "Mismatched special targets");
1270 specType
= parseKeywords
[keywd
].spec
;
1271 tOp
= parseKeywords
[keywd
].op
;
1274 * Certain special targets have special semantics:
1275 * .PATH Have to set the dirSearchPath
1277 * .MAIN Its sources are only used if
1278 * nothing has been specified to
1280 * .DEFAULT Need to create a node to hang
1281 * commands on, but we don't want
1282 * it in the graph, nor do we want
1283 * it to be the Main Target, so we
1284 * create it, set OP_NOTMAIN and
1285 * add it to the list, setting
1286 * DEFAULT to the new node for
1287 * later use. We claim the node is
1288 * A transformation rule to make
1289 * life easier later, when we'll
1290 * use Make_HandleUse to actually
1291 * apply the .DEFAULT commands.
1292 * .PHONY The list of targets
1293 * .NOPATH Don't search for file in the path
1297 * .INTERRUPT Are not to be considered the
1299 * .NOTPARALLEL Make only one target at a time.
1300 * .SINGLESHELL Create a shell for each command.
1301 * .ORDER Must set initial predecessor to NULL
1305 if (paths
== NULL
) {
1306 paths
= Lst_Init(FALSE
);
1308 (void)Lst_AtEnd(paths
, dirSearchPath
);
1311 if (!Lst_IsEmpty(create
)) {
1319 gn
= Targ_FindNode(line
, TARG_CREATE
);
1320 gn
->type
|= OP_NOTMAIN
|OP_SPECIAL
;
1321 (void)Lst_AtEnd(targets
, gn
);
1324 gn
= Targ_NewGN(".DEFAULT");
1325 gn
->type
|= (OP_NOTMAIN
|OP_TRANSFORM
);
1326 (void)Lst_AtEnd(targets
, gn
);
1341 } else if (strncmp(line
, ".PATH", 5) == 0) {
1343 * .PATH<suffix> has to be handled specially.
1344 * Call on the suffix module to give us a path to
1350 path
= Suff_GetPath(&line
[5]);
1352 Parse_Error(PARSE_FATAL
,
1353 "Suffix '%s' not defined (yet)",
1357 if (paths
== NULL
) {
1358 paths
= Lst_Init(FALSE
);
1360 (void)Lst_AtEnd(paths
, path
);
1366 * Have word in line. Get or create its node and stick it at
1367 * the end of the targets list
1369 if ((specType
== Not
) && (*line
!= '\0')) {
1370 if (Dir_HasWildcards(line
)) {
1372 * Targets are to be sought only in the current directory,
1373 * so create an empty path for the thing. Note we need to
1374 * use Dir_Destroy in the destruction of the path as the
1375 * Dir module could have added a directory to the path...
1377 Lst emptyPath
= Lst_Init(FALSE
);
1379 Dir_Expand(line
, emptyPath
, curTargs
);
1381 Lst_Destroy(emptyPath
, Dir_Destroy
);
1384 * No wildcards, but we want to avoid code duplication,
1385 * so create a list with the word on it.
1387 (void)Lst_AtEnd(curTargs
, line
);
1390 while(!Lst_IsEmpty(curTargs
)) {
1391 char *targName
= (char *)Lst_DeQueue(curTargs
);
1393 if (!Suff_IsTransform (targName
)) {
1394 gn
= Targ_FindNode(targName
, TARG_CREATE
);
1396 gn
= Suff_AddTransform(targName
);
1399 (void)Lst_AtEnd(targets
, gn
);
1401 } else if (specType
== ExPath
&& *line
!= '.' && *line
!= '\0') {
1402 Parse_Error(PARSE_WARNING
, "Extra target (%s) ignored", line
);
1407 * If it is a special type and not .PATH, it's the only target we
1408 * allow on this line...
1410 if (specType
!= Not
&& specType
!= ExPath
) {
1411 Boolean warning
= FALSE
;
1413 while (*cp
&& (ParseIsEscaped(lstart
, cp
) ||
1414 ((*cp
!= '!') && (*cp
!= ':')))) {
1415 if (ParseIsEscaped(lstart
, cp
) ||
1416 (*cp
!= ' ' && *cp
!= '\t')) {
1422 Parse_Error(PARSE_WARNING
, "Extra target ignored");
1425 while (*cp
&& isspace ((unsigned char)*cp
)) {
1430 } while (*line
&& (ParseIsEscaped(lstart
, line
) ||
1431 ((*line
!= '!') && (*line
!= ':'))));
1434 * Don't need the list of target names anymore...
1436 Lst_Destroy(curTargs
, NULL
);
1439 if (!Lst_IsEmpty(targets
)) {
1442 Parse_Error(PARSE_WARNING
, "Special and mundane targets don't mix. Mundane ones ignored");
1450 * These four create nodes on which to hang commands, so
1451 * targets shouldn't be empty...
1455 * Nothing special here -- targets can be empty if it wants.
1462 * Have now parsed all the target names. Must parse the operator next. The
1463 * result is left in op .
1467 } else if (*cp
== ':') {
1475 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1476 : "Missing dependency operator");
1480 cp
++; /* Advance beyond operator */
1482 Lst_ForEach(targets
, ParseDoOp
, &op
);
1485 * Get to the first source
1487 while (*cp
&& isspace ((unsigned char)*cp
)) {
1493 * Several special targets take different actions if present with no
1495 * a .SUFFIXES line with no sources clears out all old suffixes
1496 * a .PRECIOUS line makes all targets precious
1497 * a .IGNORE line ignores errors for all targets
1498 * a .SILENT line creates silence when making all targets
1499 * a .PATH removes all directories from the search path(s).
1504 Suff_ClearSuffixes();
1510 ignoreErrors
= TRUE
;
1516 Lst_ForEach(paths
, ParseClearPath
, NULL
);
1521 Var_Set("%POSIX", "1003.2", VAR_GLOBAL
, 0);
1527 } else if (specType
== MFlags
) {
1529 * Call on functions in main.c to deal with these arguments and
1530 * set the initial character to a null-character so the loop to
1531 * get sources won't get anything
1533 Main_ParseArgLine(line
);
1535 } else if (specType
== ExShell
) {
1536 if (Job_ParseShell(line
) != SUCCESS
) {
1537 Parse_Error(PARSE_FATAL
, "improper shell specification");
1541 } else if ((specType
== NotParallel
) || (specType
== SingleShell
)) {
1546 * NOW GO FOR THE SOURCES
1548 if ((specType
== Suffixes
) || (specType
== ExPath
) ||
1549 (specType
== Includes
) || (specType
== Libs
) ||
1550 (specType
== Null
) || (specType
== ExObjdir
))
1554 * If the target was one that doesn't take files as its sources
1555 * but takes something like suffixes, we take each
1556 * space-separated word on the line as a something and deal
1557 * with it accordingly.
1559 * If the target was .SUFFIXES, we take each source as a
1560 * suffix and add it to the list of suffixes maintained by the
1563 * If the target was a .PATH, we add the source as a directory
1564 * to search on the search path.
1566 * If it was .INCLUDES, the source is taken to be the suffix of
1567 * files which will be #included and whose search path should
1568 * be present in the .INCLUDES variable.
1570 * If it was .LIBS, the source is taken to be the suffix of
1571 * files which are considered libraries and whose search path
1572 * should be present in the .LIBS variable.
1574 * If it was .NULL, the source is the suffix to use when a file
1575 * has no valid suffix.
1577 * If it was .OBJDIR, the source is a new definition for .OBJDIR,
1578 * and will cause make to do a new chdir to that path.
1580 while (*cp
&& !isspace ((unsigned char)*cp
)) {
1587 Suff_AddSuffix(line
, &mainNode
);
1590 Lst_ForEach(paths
, ParseAddDir
, line
);
1593 Suff_AddInclude(line
);
1602 Main_SetObjdir(line
);
1608 if (savec
!= '\0') {
1611 while (*cp
&& isspace ((unsigned char)*cp
)) {
1617 Lst_Destroy(paths
, NULL
);
1619 if (specType
== ExPath
)
1624 * The targets take real sources, so we must beware of archive
1625 * specifications (i.e. things with left parentheses in them)
1626 * and handle them accordingly.
1628 for (; *cp
&& !isspace ((unsigned char)*cp
); cp
++) {
1629 if ((*cp
== LPAREN
) && (cp
> line
) && (cp
[-1] != '$')) {
1631 * Only stop for a left parenthesis if it isn't at the
1632 * start of a word (that'll be for variable changes
1633 * later) and isn't preceded by a dollar sign (a dynamic
1640 if (*cp
== LPAREN
) {
1641 sources
= Lst_Init(FALSE
);
1642 if (Arch_ParseArchive(&line
, sources
, VAR_CMD
) != SUCCESS
) {
1643 Parse_Error(PARSE_FATAL
,
1644 "Error in source archive spec \"%s\"", line
);
1648 while (!Lst_IsEmpty (sources
)) {
1649 gn
= (GNode
*)Lst_DeQueue(sources
);
1650 ParseDoSrc(tOp
, gn
->name
);
1652 Lst_Destroy(sources
, NULL
);
1660 ParseDoSrc(tOp
, line
);
1662 while (*cp
&& isspace ((unsigned char)*cp
)) {
1669 if (mainNode
== NULL
) {
1671 * If we have yet to decide on a main target to make, in the
1672 * absence of any user input, we want the first target on
1673 * the first dependency line that is actually a real target
1674 * (i.e. isn't a .USE or .EXEC rule) to be made.
1676 Lst_ForEach(targets
, ParseFindMain
, NULL
);
1681 Lst_Destroy(curTargs
, NULL
);
1685 *---------------------------------------------------------------------
1687 * Return TRUE if the passed line is a variable assignment. A variable
1688 * assignment consists of a single word followed by optional whitespace
1689 * followed by either a += or an = operator.
1690 * This function is used both by the Parse_File function and main when
1691 * parsing the command-line arguments.
1694 * line the line to check
1697 * TRUE if it is. FALSE if it ain't
1701 *---------------------------------------------------------------------
1704 Parse_IsVar(char *line
)
1706 Boolean wasSpace
= FALSE
; /* set TRUE if found a space */
1709 #define ISEQOPERATOR(c) \
1710 (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1713 * Skip to variable name
1715 for (;(*line
== ' ') || (*line
== '\t'); line
++)
1718 /* Scan for one of the assignment operators outside a variable expansion */
1719 while ((ch
= *line
++) != 0) {
1720 if (ch
== '(' || ch
== '{') {
1724 if (ch
== ')' || ch
== '}') {
1730 while (ch
== ' ' || ch
== '\t') {
1736 if (*line
== '=' && ISEQOPERATOR(ch
))
1746 *---------------------------------------------------------------------
1748 * Take the variable assignment in the passed line and do it in the
1751 * Note: There is a lexical ambiguity with assignment modifier characters
1752 * in variable names. This routine interprets the character before the =
1753 * as a modifier. Therefore, an assignment like
1755 * is interpreted as "C+ +=" instead of "C++ =".
1758 * line a line guaranteed to be a variable assignment.
1759 * This reduces error checks
1760 * ctxt Context in which to do the assignment
1766 * the variable structure of the given variable name is altered in the
1768 *---------------------------------------------------------------------
1771 Parse_DoVar(char *line
, GNode
*ctxt
)
1773 char *cp
; /* pointer into line */
1775 VAR_SUBST
, VAR_APPEND
, VAR_SHELL
, VAR_NORMAL
1776 } type
; /* Type of assignment */
1777 char *opc
; /* ptr to operator character to
1778 * null-terminate the variable name */
1779 Boolean freeCp
= FALSE
; /* TRUE if cp needs to be freed,
1780 * i.e. if any variable expansion was
1785 * Skip to variable name
1787 while ((*line
== ' ') || (*line
== '\t')) {
1792 * Skip to operator character, nulling out whitespace as we go
1793 * XXX Rather than counting () and {} we should look for $ and
1794 * then expand the variable.
1796 for (depth
= 0, cp
= line
+ 1; depth
!= 0 || *cp
!= '='; cp
++) {
1797 if (*cp
== '(' || *cp
== '{') {
1801 if (*cp
== ')' || *cp
== '}') {
1805 if (depth
== 0 && isspace ((unsigned char)*cp
)) {
1809 opc
= cp
-1; /* operator is the previous character */
1810 *cp
++ = '\0'; /* nuke the = */
1813 * Check operator type
1823 * If the variable already has a value, we don't do anything.
1826 if (Var_Exists(line
, ctxt
)) {
1845 while (opc
> line
&& *opc
!= ':')
1848 if (strncmp(opc
, ":sh", 3) == 0) {
1858 while (isspace ((unsigned char)*cp
)) {
1862 if (type
== VAR_APPEND
) {
1863 Var_Append(line
, cp
, ctxt
);
1864 } else if (type
== VAR_SUBST
) {
1866 * Allow variables in the old value to be undefined, but leave their
1867 * invocation alone -- this is done by forcing oldVars to be false.
1868 * XXX: This can cause recursive variables, but that's not hard to do,
1869 * and this allows someone to do something like
1871 * CFLAGS = $(.INCLUDES)
1872 * CFLAGS := -I.. $(CFLAGS)
1874 * And not get an error.
1876 Boolean oldOldVars
= oldVars
;
1881 * make sure that we set the variable the first time to nothing
1882 * so that it gets substituted!
1884 if (!Var_Exists(line
, ctxt
))
1885 Var_Set(line
, "", ctxt
, 0);
1887 cp
= Var_Subst(NULL
, cp
, ctxt
, FALSE
);
1888 oldVars
= oldOldVars
;
1891 Var_Set(line
, cp
, ctxt
, 0);
1892 } else if (type
== VAR_SHELL
) {
1896 if (strchr(cp
, '$') != NULL
) {
1898 * There's a dollar sign in the command, so perform variable
1899 * expansion on the whole thing. The resulting string will need
1900 * freeing when we're done, so set freeCmd to TRUE.
1902 cp
= Var_Subst(NULL
, cp
, VAR_CMD
, TRUE
);
1906 res
= Cmd_Exec(cp
, &error
);
1907 Var_Set(line
, res
, ctxt
, 0);
1911 Parse_Error(PARSE_WARNING
, error
, cp
);
1914 * Normal assignment -- just do it.
1916 Var_Set(line
, cp
, ctxt
, 0);
1918 if (strcmp(line
, MAKEOVERRIDES
) == 0)
1919 Main_ExportMAKEFLAGS(FALSE
); /* re-export MAKEFLAGS */
1920 else if (strcmp(line
, ".CURDIR") == 0) {
1922 * Somone is being (too?) clever...
1923 * Let's pretend they know what they are doing and
1924 * re-initialize the 'cur' Path.
1928 } else if (strcmp(line
, MAKE_JOB_PREFIX
) == 0) {
1930 } else if (strcmp(line
, MAKE_EXPORTED
) == 0) {
1940 * Lst_ForEach function to add a command line to all targets
1943 * gnp the node to which the command is to be added
1944 * cmd the command to add
1950 * A new element is added to the commands list of the node.
1953 ParseAddCmd(void *gnp
, void *cmd
)
1955 GNode
*gn
= (GNode
*)gnp
;
1957 /* Add to last (ie current) cohort for :: targets */
1958 if ((gn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (gn
->cohorts
))
1959 gn
= (GNode
*)Lst_Datum(Lst_Last(gn
->cohorts
));
1961 /* if target already supplied, ignore commands */
1962 if (!(gn
->type
& OP_HAS_COMMANDS
)) {
1963 (void)Lst_AtEnd(gn
->commands
, cmd
);
1967 /* XXX: We cannot do this until we fix the tree */
1968 (void)Lst_AtEnd(gn
->commands
, cmd
);
1969 Parse_Error(PARSE_WARNING
,
1970 "overriding commands for target \"%s\"; "
1971 "previous commands defined at %s: %d ignored",
1972 gn
->name
, gn
->fname
, gn
->lineno
);
1974 Parse_Error(PARSE_WARNING
,
1975 "duplicate script for target \"%s\" ignored",
1977 ParseErrorInternal(gn
->fname
, gn
->lineno
, PARSE_WARNING
,
1978 "using previous script for \"%s\" defined here",
1986 *-----------------------------------------------------------------------
1987 * ParseHasCommands --
1988 * Callback procedure for Parse_File when destroying the list of
1989 * targets on the last dependency line. Marks a target as already
1990 * having commands if it does, to keep from having shell commands
1991 * on multiple dependency lines.
1994 * gnp Node to examine
2000 * OP_HAS_COMMANDS may be set for the target.
2002 *-----------------------------------------------------------------------
2005 ParseHasCommands(void *gnp
)
2007 GNode
*gn
= (GNode
*)gnp
;
2008 if (!Lst_IsEmpty(gn
->commands
)) {
2009 gn
->type
|= OP_HAS_COMMANDS
;
2014 *-----------------------------------------------------------------------
2015 * Parse_AddIncludeDir --
2016 * Add a directory to the path searched for included makefiles
2017 * bracketed by double-quotes. Used by functions in main.c
2020 * dir The name of the directory to add
2026 * The directory is appended to the list.
2028 *-----------------------------------------------------------------------
2031 Parse_AddIncludeDir(char *dir
)
2033 (void)Dir_AddDir(parseIncPath
, dir
);
2037 *---------------------------------------------------------------------
2039 * Push to another file.
2041 * The input is the line minus the `.'. A file spec is a string
2042 * enclosed in <> or "". The former is looked for only in sysIncPath.
2043 * The latter in . and the directories specified by -I command line
2050 * A structure is added to the includes Lst and readProc, lineno,
2051 * fname and curFILE are altered for the new file
2052 *---------------------------------------------------------------------
2056 Parse_include_file(char *file
, Boolean isSystem
, int silent
)
2058 struct loadedfile
*lf
;
2059 char *fullname
; /* full pathname of file */
2061 char *prefEnd
, *incdir
;
2066 * Now we know the file's name and its search path, we attempt to
2067 * find the durn thing. A return of NULL indicates the file don't
2070 fullname
= file
[0] == '/' ? bmake_strdup(file
) : NULL
;
2072 if (fullname
== NULL
&& !isSystem
) {
2074 * Include files contained in double-quotes are first searched for
2075 * relative to the including file's location. We don't want to
2076 * cd there, of course, so we just tack on the old file's
2077 * leading path components and call Dir_FindFile to see if
2078 * we can locate the beast.
2081 incdir
= bmake_strdup(curFile
->fname
);
2082 prefEnd
= strrchr(incdir
, '/');
2083 if (prefEnd
!= NULL
) {
2085 /* Now do lexical processing of leading "../" on the filename */
2086 for (i
= 0; strncmp(file
+ i
, "../", 3) == 0; i
+= 3) {
2087 prefEnd
= strrchr(incdir
+ 1, '/');
2088 if (prefEnd
== NULL
|| strcmp(prefEnd
, "/..") == 0)
2092 newName
= str_concat(incdir
, file
+ i
, STR_ADDSLASH
);
2093 fullname
= Dir_FindFile(newName
, parseIncPath
);
2094 if (fullname
== NULL
)
2095 fullname
= Dir_FindFile(newName
, dirSearchPath
);
2100 if (fullname
== NULL
) {
2102 * Makefile wasn't found in same directory as included makefile.
2103 * Search for it first on the -I search path,
2104 * then on the .PATH search path, if not found in a -I directory.
2105 * If we have a suffix specific path we should use that.
2108 Lst suffPath
= NULL
;
2110 if ((suff
= strrchr(file
, '.'))) {
2111 suffPath
= Suff_GetPath(suff
);
2112 if (suffPath
!= NULL
) {
2113 fullname
= Dir_FindFile(file
, suffPath
);
2116 if (fullname
== NULL
) {
2117 fullname
= Dir_FindFile(file
, parseIncPath
);
2118 if (fullname
== NULL
) {
2119 fullname
= Dir_FindFile(file
, dirSearchPath
);
2125 /* Looking for a system file or file still not found */
2126 if (fullname
== NULL
) {
2128 * Look for it on the system path
2130 fullname
= Dir_FindFile(file
,
2131 Lst_IsEmpty(sysIncPath
) ? defIncPath
: sysIncPath
);
2134 if (fullname
== NULL
) {
2136 Parse_Error(PARSE_FATAL
, "Could not find %s", file
);
2140 /* Actually open the file... */
2141 fd
= open(fullname
, O_RDONLY
);
2144 Parse_Error(PARSE_FATAL
, "Cannot open %s", fullname
);
2150 lf
= loadfile(fullname
, fd
);
2152 /* Start reading from this file next */
2153 Parse_SetInput(fullname
, 0, -1, loadedfile_nextbuf
, lf
);
2158 ParseDoInclude(char *line
)
2160 char endc
; /* the character which ends the file spec */
2161 char *cp
; /* current position in file spec */
2162 int silent
= (*line
!= 'i') ? 1 : 0;
2163 char *file
= &line
[7 + silent
];
2165 /* Skip to delimiter character so we know where to look */
2166 while (*file
== ' ' || *file
== '\t')
2169 if (*file
!= '"' && *file
!= '<') {
2170 Parse_Error(PARSE_FATAL
,
2171 ".include filename must be delimited by '\"' or '<'");
2176 * Set the search path on which to find the include file based on the
2177 * characters which bracket its name. Angle-brackets imply it's
2178 * a system Makefile while double-quotes imply it's a user makefile
2186 /* Skip to matching delimiter */
2187 for (cp
= ++file
; *cp
&& *cp
!= endc
; cp
++)
2191 Parse_Error(PARSE_FATAL
,
2192 "Unclosed %cinclude filename. '%c' expected",
2199 * Substitute for any variables in the file name before trying to
2202 file
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2204 Parse_include_file(file
, endc
== '>', silent
);
2210 *---------------------------------------------------------------------
2211 * ParseSetParseFile --
2212 * Set the .PARSEDIR and .PARSEFILE variables to the dirname and
2213 * basename of the given filename
2219 * The .PARSEDIR and .PARSEFILE variables are overwritten by the
2220 * dirname and basename of the given filename.
2221 *---------------------------------------------------------------------
2224 ParseSetParseFile(const char *filename
)
2226 char *slash
, *dirname
;
2227 const char *pd
, *pf
;
2230 slash
= strrchr(filename
, '/');
2231 if (slash
== NULL
) {
2232 Var_Set(".PARSEDIR", pd
= curdir
, VAR_GLOBAL
, 0);
2233 Var_Set(".PARSEFILE", pf
= filename
, VAR_GLOBAL
, 0);
2236 len
= slash
- filename
;
2237 dirname
= bmake_malloc(len
+ 1);
2238 memcpy(dirname
, filename
, len
);
2239 dirname
[len
] = '\0';
2240 Var_Set(".PARSEDIR", pd
= dirname
, VAR_GLOBAL
, 0);
2241 Var_Set(".PARSEFILE", pf
= slash
+ 1, VAR_GLOBAL
, 0);
2244 fprintf(debug_file
, "ParseSetParseFile: ${.PARSEDIR} = `%s' "
2245 "${.PARSEFILE} = `%s'\n", pd
, pf
);
2250 * Track the makefiles we read - so makefiles can
2251 * set dependencies on them.
2252 * Avoid adding anything more than once.
2256 ParseTrackInput(const char *name
)
2260 size_t name_len
= strlen(name
);
2262 old
= Var_Value(MAKE_MAKEFILES
, VAR_GLOBAL
, &fp
);
2264 /* does it contain name? */
2265 for (; old
!= NULL
; old
= strchr(old
, ' ')) {
2268 if (memcmp(old
, name
, name_len
) == 0
2269 && (old
[name_len
] == 0 || old
[name_len
] == ' '))
2273 Var_Append (MAKE_MAKEFILES
, name
, VAR_GLOBAL
);
2282 *---------------------------------------------------------------------
2284 * Start Parsing from the given source
2290 * A structure is added to the includes Lst and readProc, lineno,
2291 * fname and curFile are altered for the new file
2292 *---------------------------------------------------------------------
2295 Parse_SetInput(const char *name
, int line
, int fd
,
2296 char *(*nextbuf
)(void *, size_t *), void *arg
)
2302 name
= curFile
->fname
;
2304 ParseTrackInput(name
);
2307 fprintf(debug_file
, "Parse_SetInput: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
2308 name
, line
, fd
, nextbuf
, arg
);
2310 if (fd
== -1 && nextbuf
== NULL
)
2314 if (curFile
!= NULL
)
2315 /* Save exiting file info */
2316 Lst_AtFront(includes
, curFile
);
2318 /* Allocate and fill in new structure */
2319 curFile
= bmake_malloc(sizeof *curFile
);
2322 * Once the previous state has been saved, we can get down to reading
2323 * the new file. We set up the name of the file to be the absolute
2324 * name of the include file so error messages refer to the right
2327 curFile
->fname
= name
;
2328 curFile
->lineno
= line
;
2329 curFile
->first_lineno
= line
;
2330 curFile
->nextbuf
= nextbuf
;
2331 curFile
->nextbuf_arg
= arg
;
2334 assert(nextbuf
!= NULL
);
2336 /* Get first block of input data */
2337 buf
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2339 /* Was all a waste of time ... */
2343 curFile
->P_str
= buf
;
2344 curFile
->P_ptr
= buf
;
2345 curFile
->P_end
= buf
+len
;
2347 curFile
->cond_depth
= Cond_save_depth();
2348 ParseSetParseFile(name
);
2353 *---------------------------------------------------------------------
2354 * ParseTraditionalInclude --
2355 * Push to another file.
2357 * The input is the current line. The file name(s) are
2358 * following the "include".
2364 * A structure is added to the includes Lst and readProc, lineno,
2365 * fname and curFILE are altered for the new file
2366 *---------------------------------------------------------------------
2369 ParseTraditionalInclude(char *line
)
2371 char *cp
; /* current position in file spec */
2373 int silent
= (line
[0] != 'i') ? 1 : 0;
2374 char *file
= &line
[silent
+ 7];
2378 fprintf(debug_file
, "ParseTraditionalInclude: %s\n", file
);
2382 * Skip over whitespace
2384 while (isspace((unsigned char)*file
))
2388 * Substitute for any variables in the file name before trying to
2391 all_files
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2393 if (*file
== '\0') {
2394 Parse_Error(PARSE_FATAL
,
2395 "Filename missing from \"include\"");
2399 for (file
= all_files
; !done
; file
= cp
+ 1) {
2400 /* Skip to end of line or next whitespace */
2401 for (cp
= file
; *cp
&& !isspace((unsigned char) *cp
); cp
++)
2409 Parse_include_file(file
, FALSE
, silent
);
2417 *---------------------------------------------------------------------
2418 * ParseGmakeExport --
2419 * Parse export <variable>=<value>
2421 * And set the environment with it.
2428 *---------------------------------------------------------------------
2431 ParseGmakeExport(char *line
)
2433 char *variable
= &line
[6];
2437 fprintf(debug_file
, "ParseGmakeExport: %s\n", variable
);
2441 * Skip over whitespace
2443 while (isspace((unsigned char)*variable
))
2446 for (value
= variable
; *value
&& *value
!= '='; value
++)
2449 if (*value
!= '=') {
2450 Parse_Error(PARSE_FATAL
,
2451 "Variable/Value missing from \"export\"");
2456 * Expand the value before putting it in the environment.
2458 value
= Var_Subst(NULL
, value
, VAR_CMD
, FALSE
);
2459 setenv(variable
, value
, 1);
2464 *---------------------------------------------------------------------
2466 * Called when EOF is reached in the current file. If we were reading
2467 * an include file, the includes stack is popped and things set up
2468 * to go back to reading the previous file at the previous location.
2471 * CONTINUE if there's more to do. DONE if not.
2474 * The old curFILE, is closed. The includes list is shortened.
2475 * lineno, curFILE, and fname are changed if CONTINUE is returned.
2476 *---------------------------------------------------------------------
2484 assert(curFile
->nextbuf
!= NULL
);
2486 /* get next input buffer, if any */
2487 ptr
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2488 curFile
->P_ptr
= ptr
;
2489 curFile
->P_str
= ptr
;
2490 curFile
->P_end
= ptr
+ len
;
2491 curFile
->lineno
= curFile
->first_lineno
;
2497 /* Ensure the makefile (or loop) didn't have mismatched conditionals */
2498 Cond_restore_depth(curFile
->cond_depth
);
2500 if (curFile
->lf
!= NULL
) {
2501 loadedfile_destroy(curFile
->lf
);
2505 /* Dispose of curFile info */
2506 /* Leak curFile->fname because all the gnodes have pointers to it */
2507 free(curFile
->P_str
);
2510 curFile
= Lst_DeQueue(includes
);
2512 if (curFile
== NULL
) {
2513 /* We've run out of input */
2514 Var_Delete(".PARSEDIR", VAR_GLOBAL
);
2515 Var_Delete(".PARSEFILE", VAR_GLOBAL
);
2520 fprintf(debug_file
, "ParseEOF: returning to file %s, line %d\n",
2521 curFile
->fname
, curFile
->lineno
);
2523 /* Restore the PARSEDIR/PARSEFILE variables */
2524 ParseSetParseFile(curFile
->fname
);
2529 #define PARSE_SKIP 2
2532 ParseGetLine(int flags
, int *length
)
2534 IFile
*cf
= curFile
;
2543 /* Loop through blank lines and comment lines */
2552 if (cf
->P_end
!= NULL
&& ptr
== cf
->P_end
) {
2558 if (ch
== 0 || (ch
== '\\' && ptr
[1] == 0)) {
2559 if (cf
->P_end
== NULL
)
2560 /* End of string (aka for loop) data */
2562 if (cf
->nextbuf
!= NULL
) {
2564 * End of this buffer; return EOF and outer logic
2565 * will get the next one. (eww)
2569 Parse_Error(PARSE_FATAL
, "Zero byte read from file");
2574 /* Don't treat next character as special, remember first one */
2575 if (escaped
== NULL
)
2583 if (ch
== '#' && comment
== NULL
) {
2584 /* Remember first '#' for comment stripping */
2585 /* Unless previous char was '[', as in modifier :[#] */
2586 if (!(ptr
> line
&& ptr
[-1] == '['))
2592 if (!isspace((unsigned char)ch
))
2593 /* We are not interested in trailing whitespace */
2597 /* Save next 'to be processed' location */
2600 /* Check we have a non-comment, non-blank line */
2601 if (line_end
== line
|| comment
== line
) {
2603 /* At end of file */
2605 /* Parse another line */
2609 /* We now have a line of data */
2612 if (flags
& PARSE_RAW
) {
2613 /* Leave '\' (etc) in line buffer (eg 'for' lines) */
2614 *length
= line_end
- line
;
2618 if (flags
& PARSE_SKIP
) {
2619 /* Completely ignore non-directives */
2622 /* We could do more of the .else/.elif/.endif checks here */
2627 /* Brutally ignore anything after a non-escaped '#' in non-commands */
2628 if (comment
!= NULL
&& line
[0] != '\t') {
2633 /* If we didn't see a '\\' then the in-situ data is fine */
2634 if (escaped
== NULL
) {
2635 *length
= line_end
- line
;
2639 /* Remove escapes from '\n' and '#' */
2642 for (; ; *tp
++ = ch
) {
2652 /* Delete '\\' at end of buffer */
2657 if (ch
== '#' && line
[0] != '\t')
2658 /* Delete '\\' from before '#' on non-command lines */
2662 /* Leave '\\' in buffer for later */
2664 /* Make sure we don't delete an escaped ' ' from the line end */
2669 /* Escaped '\n' replace following whitespace with a single ' ' */
2670 while (ptr
[0] == ' ' || ptr
[0] == '\t')
2675 /* Delete any trailing spaces - eg from empty continuations */
2676 while (tp
> escaped
&& isspace((unsigned char)tp
[-1]))
2680 *length
= tp
- line
;
2685 *---------------------------------------------------------------------
2687 * Read an entire line from the input file. Called only by Parse_File.
2690 * A line w/o its newline
2693 * Only those associated with reading a character
2694 *---------------------------------------------------------------------
2699 char *line
; /* Result */
2700 int lineLength
; /* Length of result */
2701 int lineno
; /* Saved line # */
2705 line
= ParseGetLine(0, &lineLength
);
2713 * The line might be a conditional. Ask the conditional module
2714 * about it and act accordingly
2716 switch (Cond_Eval(line
)) {
2718 /* Skip to next conditional that evaluates to COND_PARSE. */
2720 line
= ParseGetLine(PARSE_SKIP
, &lineLength
);
2721 } while (line
&& Cond_Eval(line
) != COND_PARSE
);
2727 case COND_INVALID
: /* Not a conditional line */
2728 /* Check for .for loops */
2729 rval
= For_Eval(line
);
2731 /* Not a .for line */
2734 /* Syntax error - error printed, ignore line */
2736 /* Start of a .for loop */
2737 lineno
= curFile
->lineno
;
2738 /* Accumulate loop lines until matching .endfor */
2740 line
= ParseGetLine(PARSE_RAW
, &lineLength
);
2742 Parse_Error(PARSE_FATAL
,
2743 "Unexpected end of file in for loop.");
2746 } while (For_Accum(line
));
2747 /* Stash each iteration as a new 'input file' */
2749 /* Read next line from for-loop buffer */
2757 *-----------------------------------------------------------------------
2758 * ParseFinishLine --
2759 * Handle the end of a dependency group.
2765 * inLine set FALSE. 'targets' list destroyed.
2767 *-----------------------------------------------------------------------
2770 ParseFinishLine(void)
2773 Lst_ForEach(targets
, Suff_EndTransform
, NULL
);
2774 Lst_Destroy(targets
, ParseHasCommands
);
2782 *---------------------------------------------------------------------
2784 * Parse a file into its component parts, incorporating it into the
2785 * current dependency graph. This is the main function and controls
2786 * almost every other function in this module
2789 * name the name of the file being read
2790 * fd Open file to makefile to parse
2797 * Loads. Nodes are added to the list of all targets, nodes and links
2798 * are added to the dependency graph. etc. etc. etc.
2799 *---------------------------------------------------------------------
2802 Parse_File(const char *name
, int fd
)
2804 char *cp
; /* pointer into the line */
2805 char *line
; /* the line we're working on */
2806 struct loadedfile
*lf
;
2808 lf
= loadfile(name
, fd
);
2817 Parse_SetInput(name
, 0, -1, loadedfile_nextbuf
, lf
);
2821 for (; (line
= ParseReadLine()) != NULL
; ) {
2823 fprintf(debug_file
, "ParseReadLine (%d): '%s'\n",
2824 curFile
->lineno
, line
);
2827 * Lines that begin with the special character may be
2828 * include or undef directives.
2829 * On the other hand they can be suffix rules (.c.o: ...)
2830 * or just dependencies for filenames that start '.'.
2832 for (cp
= line
+ 1; isspace((unsigned char)*cp
); cp
++) {
2835 if (strncmp(cp
, "include", 7) == 0 ||
2836 ((cp
[0] == 's' || cp
[0] == '-') &&
2837 strncmp(&cp
[1], "include", 7) == 0)) {
2841 if (strncmp(cp
, "undef", 5) == 0) {
2843 for (cp
+= 5; isspace((unsigned char) *cp
); cp
++)
2845 for (cp2
= cp
; !isspace((unsigned char) *cp2
) &&
2846 (*cp2
!= '\0'); cp2
++)
2849 Var_Delete(cp
, VAR_GLOBAL
);
2851 } else if (strncmp(cp
, "export", 6) == 0) {
2852 for (cp
+= 6; isspace((unsigned char) *cp
); cp
++)
2856 } else if (strncmp(cp
, "unexport", 8) == 0) {
2859 } else if (strncmp(cp
, "info", 4) == 0 ||
2860 strncmp(cp
, "error", 5) == 0 ||
2861 strncmp(cp
, "warning", 7) == 0) {
2862 if (ParseMessage(cp
))
2867 if (*line
== '\t') {
2869 * If a line starts with a tab, it can only hope to be
2870 * a creation command.
2874 for (; isspace ((unsigned char)*cp
); cp
++) {
2879 Parse_Error(PARSE_FATAL
,
2880 "Unassociated shell command \"%s\"",
2883 * So long as it's not a blank line and we're actually
2884 * in a dependency spec, add the command to the list of
2885 * commands of all targets in the dependency spec
2888 cp
= bmake_strdup(cp
);
2889 Lst_ForEach(targets
, ParseAddCmd
, cp
);
2891 Lst_AtEnd(targCmds
, cp
);
2899 if (((strncmp(line
, "include", 7) == 0 &&
2900 isspace((unsigned char) line
[7])) ||
2901 ((line
[0] == 's' || line
[0] == '-') &&
2902 strncmp(&line
[1], "include", 7) == 0 &&
2903 isspace((unsigned char) line
[8]))) &&
2904 strchr(line
, ':') == NULL
) {
2906 * It's an S3/S5-style "include".
2908 ParseTraditionalInclude(line
);
2913 if (strncmp(line
, "export", 6) == 0 &&
2914 isspace((unsigned char) line
[6]) &&
2915 strchr(line
, ':') == NULL
) {
2917 * It's a Gmake "export".
2919 ParseGmakeExport(line
);
2923 if (Parse_IsVar(line
)) {
2925 Parse_DoVar(line
, VAR_GLOBAL
);
2931 * To make life easier on novices, if the line is indented we
2932 * first make sure the line has a dependency operator in it.
2933 * If it doesn't have an operator and we're in a dependency
2934 * line's script, we assume it's actually a shell command
2935 * and add it to the current list of targets.
2938 if (isspace((unsigned char) line
[0])) {
2939 while ((*cp
!= '\0') && isspace((unsigned char) *cp
))
2941 while (*cp
&& (ParseIsEscaped(line
, cp
) ||
2942 (*cp
!= ':') && (*cp
!= '!'))) {
2947 Parse_Error(PARSE_WARNING
,
2948 "Shell command needs a leading tab");
2957 * For some reason - probably to make the parser impossible -
2958 * a ';' can be used to separate commands from dependencies.
2959 * Attempt to avoid ';' inside substitution patterns.
2964 for (cp
= line
; *cp
!= 0; cp
++) {
2965 if (*cp
== '\\' && cp
[1] != 0) {
2970 (cp
[1] == '(' || cp
[1] == '{')) {
2975 if (*cp
== ')' || *cp
== '}') {
2979 } else if (*cp
== ';') {
2985 /* Terminate the dependency list at the ';' */
2991 * We now know it's a dependency line so it needs to have all
2992 * variables expanded before being parsed. Tell the variable
2993 * module to complain if some variable is undefined...
2995 line
= Var_Subst(NULL
, line
, VAR_CMD
, TRUE
);
2998 * Need a non-circular list for the target nodes
3001 Lst_Destroy(targets
, NULL
);
3003 targets
= Lst_Init(FALSE
);
3006 ParseDoDependency(line
);
3009 /* If there were commands after a ';', add them now */
3015 * Reached EOF, but it may be just EOF of an include file...
3017 } while (ParseEOF() == CONTINUE
);
3020 (void)fflush(stdout
);
3021 (void)fprintf(stderr
,
3022 "%s: Fatal errors encountered -- cannot continue",
3024 PrintOnError(NULL
, NULL
);
3030 *---------------------------------------------------------------------
3032 * initialize the parsing module
3038 * the parseIncPath list is initialized...
3039 *---------------------------------------------------------------------
3045 parseIncPath
= Lst_Init(FALSE
);
3046 sysIncPath
= Lst_Init(FALSE
);
3047 defIncPath
= Lst_Init(FALSE
);
3048 includes
= Lst_Init(FALSE
);
3050 targCmds
= Lst_Init(FALSE
);
3058 Lst_Destroy(targCmds
, (FreeProc
*)free
);
3060 Lst_Destroy(targets
, NULL
);
3061 Lst_Destroy(defIncPath
, Dir_Destroy
);
3062 Lst_Destroy(sysIncPath
, Dir_Destroy
);
3063 Lst_Destroy(parseIncPath
, Dir_Destroy
);
3064 Lst_Destroy(includes
, NULL
); /* Should be empty now */
3070 *-----------------------------------------------------------------------
3072 * Return a Lst of the main target to create for main()'s sake. If
3073 * no such target exists, we Punt with an obnoxious error message.
3076 * A Lst of the single node to create.
3081 *-----------------------------------------------------------------------
3084 Parse_MainName(void)
3086 Lst mainList
; /* result list */
3088 mainList
= Lst_Init(FALSE
);
3090 if (mainNode
== NULL
) {
3091 Punt("no target to make.");
3093 } else if (mainNode
->type
& OP_DOUBLEDEP
) {
3094 (void)Lst_AtEnd(mainList
, mainNode
);
3095 Lst_Concat(mainList
, mainNode
->cohorts
, LST_CONCNEW
);
3098 (void)Lst_AtEnd(mainList
, mainNode
);
3099 Var_Append(".TARGETS", mainNode
->name
, VAR_GLOBAL
);
3104 *-----------------------------------------------------------------------
3106 * Add the filename and lineno to the GNode so that we remember
3107 * where it was first defined.
3112 *-----------------------------------------------------------------------
3115 ParseMark(GNode
*gn
)
3117 gn
->fname
= curFile
->fname
;
3118 gn
->lineno
= curFile
->lineno
;