1 /* $NetBSD: parse.c,v 1.191 2013/08/28 21:56:49 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.191 2013/08/28 21:56:49 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.191 2013/08/28 21:56:49 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 *);
368 static void ParseTraditionalInclude(char *);
371 static void ParseGmakeExport(char *);
373 static int ParseEOF(void);
374 static char *ParseReadLine(void);
375 static void ParseFinishLine(void);
376 static void ParseMark(GNode
*);
378 ////////////////////////////////////////////////////////////
382 const char *path
; /* name, for error reports */
383 char *buf
; /* contents buffer */
384 size_t len
; /* length of contents */
385 size_t maplen
; /* length of mmap area, or 0 */
386 Boolean used
; /* XXX: have we used the data yet */
390 * Constructor/destructor for loadedfile
392 static struct loadedfile
*
393 loadedfile_create(const char *path
)
395 struct loadedfile
*lf
;
397 lf
= bmake_malloc(sizeof(*lf
));
398 lf
->path
= (path
== NULL
? "(stdin)" : path
);
407 loadedfile_destroy(struct loadedfile
*lf
)
409 if (lf
->buf
!= NULL
) {
410 if (lf
->maplen
> 0) {
412 munmap(lf
->buf
, lf
->maplen
);
422 * nextbuf() operation for loadedfile, as needed by the weird and twisted
423 * logic below. Once that's cleaned up, we can get rid of lf->used...
426 loadedfile_nextbuf(void *x
, size_t *len
)
428 struct loadedfile
*lf
= x
;
439 * Try to get the size of a file.
442 load_getsize(int fd
, size_t *ret
)
446 if (fstat(fd
, &st
) < 0) {
450 if (!S_ISREG(st
.st_mode
)) {
455 * st_size is an off_t, which is 64 bits signed; *ret is
456 * size_t, which might be 32 bits unsigned or 64 bits
457 * unsigned. Rather than being elaborate, just punt on
458 * files that are more than 2^31 bytes. We should never
459 * see a makefile that size in practice...
461 * While we're at it reject negative sizes too, just in case.
463 if (st
.st_size
< 0 || st
.st_size
> 0x7fffffff) {
467 *ret
= (size_t) st
.st_size
;
474 * Until the path search logic can be moved under here instead of
475 * being in the caller in another source file, we need to have the fd
476 * passed in already open. Bleh.
478 * If the path is NULL use stdin and (to insure against fd leaks)
479 * assert that the caller passed in -1.
481 static struct loadedfile
*
482 loadfile(const char *path
, int fd
)
484 struct loadedfile
*lf
;
491 lf
= loadedfile_create(path
);
498 fd
= open(path
, O_RDONLY
);
501 Error("%s: %s", path
, strerror(errno
));
508 if (load_getsize(fd
, &lf
->len
) == SUCCESS
) {
509 /* found a size, try mmap */
510 pagesize
= sysconf(_SC_PAGESIZE
);
514 /* round size up to a page */
515 lf
->maplen
= pagesize
* ((lf
->len
+ pagesize
- 1)/pagesize
);
518 * XXX hack for dealing with empty files; remove when
519 * we're no longer limited by interfacing to the old
520 * logic elsewhere in this file.
522 if (lf
->maplen
== 0) {
523 lf
->maplen
= pagesize
;
527 * FUTURE: remove PROT_WRITE when the parser no longer
528 * needs to scribble on the input.
530 lf
->buf
= mmap(NULL
, lf
->maplen
, PROT_READ
|PROT_WRITE
,
531 MAP_FILE
|MAP_COPY
, fd
, 0);
532 if (lf
->buf
!= MAP_FAILED
) {
534 if (lf
->len
== lf
->maplen
&& lf
->buf
[lf
->len
- 1] != '\n') {
535 char *b
= malloc(lf
->len
+ 1);
537 memcpy(b
, lf
->buf
, lf
->len
++);
538 munmap(lf
->buf
, lf
->maplen
);
546 /* cannot mmap; load the traditional way */
550 lf
->buf
= bmake_malloc(lf
->len
);
554 assert(bufpos
<= lf
->len
);
555 if (bufpos
== lf
->len
) {
557 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
559 result
= read(fd
, lf
->buf
+ bufpos
, lf
->len
- bufpos
);
561 Error("%s: read error: %s", path
, strerror(errno
));
569 assert(bufpos
<= lf
->len
);
572 /* truncate malloc region to actual length (maybe not useful) */
574 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
586 ////////////////////////////////////////////////////////////
590 *----------------------------------------------------------------------
592 * Check if the current character is escaped on the current line
595 * 0 if the character is not backslash escaped, 1 otherwise
599 *----------------------------------------------------------------------
602 ParseIsEscaped(const char *line
, const char *c
)
615 *----------------------------------------------------------------------
616 * ParseFindKeyword --
617 * Look in the table of keywords for one matching the given string.
623 * The index of the keyword, or -1 if it isn't there.
627 *----------------------------------------------------------------------
630 ParseFindKeyword(const char *str
)
636 end
= (sizeof(parseKeywords
)/sizeof(parseKeywords
[0])) - 1;
639 cur
= start
+ ((end
- start
) / 2);
640 diff
= strcmp(str
, parseKeywords
[cur
].name
);
644 } else if (diff
< 0) {
649 } while (start
<= end
);
654 * ParseVErrorInternal --
655 * Error message abort function for parsing. Prints out the context
656 * of the error (line number and file) as well as the message with
657 * two optional arguments.
663 * "fatals" is incremented if the level is PARSE_FATAL.
667 ParseVErrorInternal(FILE *f
, const char *cfname
, size_t clineno
, int type
,
668 const char *fmt
, va_list ap
)
670 static Boolean fatal_warning_error_printed
= FALSE
;
672 (void)fprintf(f
, "%s: ", progname
);
674 if (cfname
!= NULL
) {
675 (void)fprintf(f
, "\"");
676 if (*cfname
!= '/' && strcmp(cfname
, "(stdin)") != 0) {
681 * Nothing is more annoying than not knowing
682 * which Makefile is the culprit.
684 dir
= Var_Value(".PARSEDIR", VAR_GLOBAL
, &cp
);
685 if (dir
== NULL
|| *dir
== '\0' ||
686 (*dir
== '.' && dir
[1] == '\0'))
687 dir
= Var_Value(".CURDIR", VAR_GLOBAL
, &cp
);
691 (void)fprintf(f
, "%s/%s", dir
, cfname
);
693 (void)fprintf(f
, "%s", cfname
);
695 (void)fprintf(f
, "\" line %d: ", (int)clineno
);
697 if (type
== PARSE_WARNING
)
698 (void)fprintf(f
, "warning: ");
699 (void)vfprintf(f
, fmt
, ap
);
700 (void)fprintf(f
, "\n");
702 if (type
== PARSE_FATAL
|| parseWarnFatal
)
704 if (parseWarnFatal
&& !fatal_warning_error_printed
) {
705 Error("parsing warnings being treated as errors");
706 fatal_warning_error_printed
= TRUE
;
711 * ParseErrorInternal --
722 ParseErrorInternal(const char *cfname
, size_t clineno
, int type
,
723 const char *fmt
, ...)
728 (void)fflush(stdout
);
729 ParseVErrorInternal(stderr
, cfname
, clineno
, type
, fmt
, ap
);
732 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
734 ParseVErrorInternal(debug_file
, cfname
, clineno
, type
, fmt
, ap
);
741 * External interface to ParseErrorInternal; uses the default filename
752 Parse_Error(int type
, const char *fmt
, ...)
758 if (curFile
== NULL
) {
762 fname
= curFile
->fname
;
763 lineno
= curFile
->lineno
;
767 (void)fflush(stdout
);
768 ParseVErrorInternal(stderr
, fname
, lineno
, type
, fmt
, ap
);
771 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
773 ParseVErrorInternal(debug_file
, fname
, lineno
, type
, fmt
, ap
);
781 * Parse a .info .warning or .error directive
783 * The input is the line minus the ".". We substitute
784 * variables, print the message and exit(1) (for .error) or just print
785 * a warning if the directive is malformed.
788 ParseMessage(char *line
)
797 mtype
= PARSE_WARNING
;
803 Parse_Error(PARSE_WARNING
, "invalid syntax: \".%s\"", line
);
807 while (isalpha((u_char
)*line
))
809 if (!isspace((u_char
)*line
))
810 return FALSE
; /* not for us */
811 while (isspace((u_char
)*line
))
814 line
= Var_Subst(NULL
, line
, VAR_CMD
, 0);
815 Parse_Error(mtype
, "%s", line
);
818 if (mtype
== PARSE_FATAL
) {
819 /* Terminate immediately. */
826 *---------------------------------------------------------------------
828 * Link the parent node to its new child. Used in a Lst_ForEach by
829 * ParseDoDependency. If the specType isn't 'Not', the parent
830 * isn't linked as a parent of the child.
833 * pgnp The parent node
834 * cgpn The child node
840 * New elements are added to the parents list of cgn and the
841 * children list of cgn. the unmade field of pgn is updated
842 * to reflect the additional child.
843 *---------------------------------------------------------------------
846 ParseLinkSrc(void *pgnp
, void *cgnp
)
848 GNode
*pgn
= (GNode
*)pgnp
;
849 GNode
*cgn
= (GNode
*)cgnp
;
851 if ((pgn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (pgn
->cohorts
))
852 pgn
= (GNode
*)Lst_Datum(Lst_Last(pgn
->cohorts
));
853 (void)Lst_AtEnd(pgn
->children
, cgn
);
855 (void)Lst_AtEnd(cgn
->parents
, pgn
);
858 fprintf(debug_file
, "# ParseLinkSrc: added child %s - %s\n", pgn
->name
, cgn
->name
);
859 Targ_PrintNode(pgn
, 0);
860 Targ_PrintNode(cgn
, 0);
866 *---------------------------------------------------------------------
868 * Apply the parsed operator to the given target node. Used in a
869 * Lst_ForEach call by ParseDoDependency once all targets have
870 * been found and their operator parsed. If the previous and new
871 * operators are incompatible, a major error is taken.
874 * gnp The node to which the operator is to be applied
875 * opp The operator to apply
881 * The type field of the node is altered to reflect any new bits in
883 *---------------------------------------------------------------------
886 ParseDoOp(void *gnp
, void *opp
)
888 GNode
*gn
= (GNode
*)gnp
;
889 int op
= *(int *)opp
;
891 * If the dependency mask of the operator and the node don't match and
892 * the node has actually had an operator applied to it before, and
893 * the operator actually has some dependency information in it, complain.
895 if (((op
& OP_OPMASK
) != (gn
->type
& OP_OPMASK
)) &&
896 !OP_NOP(gn
->type
) && !OP_NOP(op
))
898 Parse_Error(PARSE_FATAL
, "Inconsistent operator for %s", gn
->name
);
902 if ((op
== OP_DOUBLEDEP
) && ((gn
->type
& OP_OPMASK
) == OP_DOUBLEDEP
)) {
904 * If the node was the object of a :: operator, we need to create a
905 * new instance of it for the children and commands on this dependency
906 * line. The new instance is placed on the 'cohorts' list of the
907 * initial one (note the initial one is not on its own cohorts list)
908 * and the new instance is linked to all parents of the initial
914 * Propagate copied bits to the initial node. They'll be propagated
915 * back to the rest of the cohorts later.
917 gn
->type
|= op
& ~OP_OPMASK
;
919 cohort
= Targ_FindNode(gn
->name
, TARG_NOHASH
);
923 * Make the cohort invisible as well to avoid duplicating it into
924 * other variables. True, parents of this target won't tend to do
925 * anything with their local variables, but better safe than
926 * sorry. (I think this is pointless now, since the relevant list
927 * traversals will no longer see this node anyway. -mycroft)
929 cohort
->type
= op
| OP_INVISIBLE
;
930 (void)Lst_AtEnd(gn
->cohorts
, cohort
);
931 cohort
->centurion
= gn
;
932 gn
->unmade_cohorts
+= 1;
933 snprintf(cohort
->cohort_num
, sizeof cohort
->cohort_num
, "#%d",
937 * We don't want to nuke any previous flags (whatever they were) so we
938 * just OR the new operator into the old
947 *---------------------------------------------------------------------
949 * Given the name of a source, figure out if it is an attribute
950 * and apply it to the targets if it is. Else decide if there is
951 * some attribute which should be applied *to* the source because
952 * of some special target and apply it if so. Otherwise, make the
953 * source be a child of the targets in the list 'targets'
956 * tOp operator (if any) from special targets
957 * src name of the source to handle
963 * Operator bits may be added to the list of targets or to the source.
964 * The targets may have a new source added to their lists of children.
965 *---------------------------------------------------------------------
968 ParseDoSrc(int tOp
, const char *src
)
971 static int wait_number
= 0;
974 if (*src
== '.' && isupper ((unsigned char)src
[1])) {
975 int keywd
= ParseFindKeyword(src
);
977 int op
= parseKeywords
[keywd
].op
;
979 Lst_ForEach(targets
, ParseDoOp
, &op
);
982 if (parseKeywords
[keywd
].spec
== Wait
) {
984 * We add a .WAIT node in the dependency list.
985 * After any dynamic dependencies (and filename globbing)
986 * have happened, it is given a dependency on the each
987 * previous child back to and previous .WAIT node.
988 * The next child won't be scheduled until the .WAIT node
990 * We give each .WAIT node a unique name (mainly for diag).
992 snprintf(wait_src
, sizeof wait_src
, ".WAIT_%u", ++wait_number
);
993 gn
= Targ_FindNode(wait_src
, TARG_NOHASH
);
996 gn
->type
= OP_WAIT
| OP_PHONY
| OP_DEPENDS
| OP_NOTMAIN
;
997 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
1006 * If we have noted the existence of a .MAIN, it means we need
1007 * to add the sources of said target to the list of things
1008 * to create. The string 'src' is likely to be free, so we
1009 * must make a new copy of it. Note that this will only be
1010 * invoked if the user didn't specify a target on the command
1011 * line. This is to allow #ifmake's to succeed, or something...
1013 (void)Lst_AtEnd(create
, bmake_strdup(src
));
1015 * Add the name to the .TARGETS variable as well, so the user can
1016 * employ that, if desired.
1018 Var_Append(".TARGETS", src
, VAR_GLOBAL
);
1023 * Create proper predecessor/successor links between the previous
1024 * source and the current one.
1026 gn
= Targ_FindNode(src
, TARG_CREATE
);
1029 if (predecessor
!= NULL
) {
1030 (void)Lst_AtEnd(predecessor
->order_succ
, gn
);
1031 (void)Lst_AtEnd(gn
->order_pred
, predecessor
);
1033 fprintf(debug_file
, "# ParseDoSrc: added Order dependency %s - %s\n",
1034 predecessor
->name
, gn
->name
);
1035 Targ_PrintNode(predecessor
, 0);
1036 Targ_PrintNode(gn
, 0);
1040 * The current source now becomes the predecessor for the next one.
1047 * If the source is not an attribute, we need to find/create
1048 * a node for it. After that we can apply any operator to it
1049 * from a special target or link it to its parents, as
1052 * In the case of a source that was the object of a :: operator,
1053 * the attribute is applied to all of its instances (as kept in
1054 * the 'cohorts' list of the node) or all the cohorts are linked
1055 * to all the targets.
1058 /* Find/create the 'src' node and attach to all targets */
1059 gn
= Targ_FindNode(src
, TARG_CREATE
);
1065 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
1072 *-----------------------------------------------------------------------
1074 * Find a real target in the list and set it to be the main one.
1075 * Called by ParseDoDependency when a main target hasn't been found
1079 * gnp Node to examine
1082 * 0 if main not found yet, 1 if it is.
1085 * mainNode is changed and Targ_SetMain is called.
1087 *-----------------------------------------------------------------------
1090 ParseFindMain(void *gnp
, void *dummy
)
1092 GNode
*gn
= (GNode
*)gnp
;
1093 if ((gn
->type
& OP_NOTARGET
) == 0) {
1096 return (dummy
? 1 : 1);
1098 return (dummy
? 0 : 0);
1103 *-----------------------------------------------------------------------
1105 * Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
1113 *-----------------------------------------------------------------------
1116 ParseAddDir(void *path
, void *name
)
1118 (void)Dir_AddDir((Lst
) path
, (char *)name
);
1123 *-----------------------------------------------------------------------
1125 * Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
1133 *-----------------------------------------------------------------------
1136 ParseClearPath(void *path
, void *dummy
)
1138 Dir_ClearPath((Lst
) path
);
1139 return(dummy
? 0 : 0);
1143 *---------------------------------------------------------------------
1144 * ParseDoDependency --
1145 * Parse the dependency line in line.
1148 * line the line to parse
1154 * The nodes of the sources are linked as children to the nodes of the
1155 * targets. Some nodes may be created.
1157 * We parse a dependency line by first extracting words from the line and
1158 * finding nodes in the list of all targets with that name. This is done
1159 * until a character is encountered which is an operator character. Currently
1160 * these are only ! and :. At this point the operator is parsed and the
1161 * pointer into the line advanced until the first source is encountered.
1162 * The parsed operator is applied to each node in the 'targets' list,
1163 * which is where the nodes found for the targets are kept, by means of
1164 * the ParseDoOp function.
1165 * The sources are read in much the same way as the targets were except
1166 * that now they are expanded using the wildcarding scheme of the C-Shell
1167 * and all instances of the resulting words in the list of all targets
1168 * are found. Each of the resulting nodes is then linked to each of the
1169 * targets as one of its children.
1170 * Certain targets are handled specially. These are the ones detailed
1171 * by the specType variable.
1172 * The storing of transformation rules is also taken care of here.
1173 * A target is recognized as a transformation rule by calling
1174 * Suff_IsTransform. If it is a transformation rule, its node is gotten
1175 * from the suffix module via Suff_AddTransform rather than the standard
1176 * Targ_FindNode in the target module.
1177 *---------------------------------------------------------------------
1180 ParseDoDependency(char *line
)
1182 char *cp
; /* our current position */
1183 GNode
*gn
= NULL
; /* a general purpose temporary node */
1184 int op
; /* the operator on the line */
1185 char savec
; /* a place to save a character */
1186 Lst paths
; /* List of search paths to alter when parsing
1187 * a list of .PATH targets */
1188 int tOp
; /* operator from special target */
1189 Lst sources
; /* list of archive source names after
1191 Lst curTargs
; /* list of target names to be found and added
1192 * to the targets list */
1193 char *lstart
= line
;
1196 fprintf(debug_file
, "ParseDoDependency(%s)\n", line
);
1202 curTargs
= Lst_Init(FALSE
);
1205 for (cp
= line
; *cp
&& (ParseIsEscaped(lstart
, cp
) ||
1206 !(isspace((unsigned char)*cp
) ||
1207 *cp
== '!' || *cp
== ':' || *cp
== LPAREN
));
1211 * Must be a dynamic source (would have been expanded
1212 * otherwise), so call the Var module to parse the puppy
1213 * so we can safely advance beyond it...There should be
1214 * no errors in this, as they would have been discovered
1215 * in the initial Var_Subst and we wouldn't be here.
1219 __unused
char *result
; /* XXX */
1221 result
= Var_Parse(cp
, VAR_CMD
, TRUE
, &length
, &freeIt
);
1228 if (!ParseIsEscaped(lstart
, cp
) && *cp
== LPAREN
) {
1230 * Archives must be handled specially to make sure the OP_ARCHV
1231 * flag is set in their 'type' field, for one thing, and because
1232 * things like "archive(file1.o file2.o file3.o)" are permissible.
1233 * Arch_ParseArchive will set 'line' to be the first non-blank
1234 * after the archive-spec. It creates/finds nodes for the members
1235 * and places them on the given list, returning SUCCESS if all
1236 * went well and FAILURE if there was an error in the
1237 * specification. On error, line should remain untouched.
1239 if (Arch_ParseArchive(&line
, targets
, VAR_CMD
) != SUCCESS
) {
1240 Parse_Error(PARSE_FATAL
,
1241 "Error in archive specification: \"%s\"", line
);
1251 * Ending a dependency line without an operator is a Bozo
1252 * no-no. As a heuristic, this is also often triggered by
1253 * undetected conflicts from cvs/rcs merges.
1255 if ((strncmp(line
, "<<<<<<", 6) == 0) ||
1256 (strncmp(line
, "======", 6) == 0) ||
1257 (strncmp(line
, ">>>>>>", 6) == 0))
1258 Parse_Error(PARSE_FATAL
,
1259 "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
1261 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1262 : "Need an operator");
1268 * Have a word in line. See if it's a special target and set
1269 * specType to match it.
1271 if (*line
== '.' && isupper ((unsigned char)line
[1])) {
1273 * See if the target is a special target that must have it
1274 * or its sources handled specially.
1276 int keywd
= ParseFindKeyword(line
);
1278 if (specType
== ExPath
&& parseKeywords
[keywd
].spec
!= ExPath
) {
1279 Parse_Error(PARSE_FATAL
, "Mismatched special targets");
1283 specType
= parseKeywords
[keywd
].spec
;
1284 tOp
= parseKeywords
[keywd
].op
;
1287 * Certain special targets have special semantics:
1288 * .PATH Have to set the dirSearchPath
1290 * .MAIN Its sources are only used if
1291 * nothing has been specified to
1293 * .DEFAULT Need to create a node to hang
1294 * commands on, but we don't want
1295 * it in the graph, nor do we want
1296 * it to be the Main Target, so we
1297 * create it, set OP_NOTMAIN and
1298 * add it to the list, setting
1299 * DEFAULT to the new node for
1300 * later use. We claim the node is
1301 * A transformation rule to make
1302 * life easier later, when we'll
1303 * use Make_HandleUse to actually
1304 * apply the .DEFAULT commands.
1305 * .PHONY The list of targets
1306 * .NOPATH Don't search for file in the path
1311 * .INTERRUPT Are not to be considered the
1313 * .NOTPARALLEL Make only one target at a time.
1314 * .SINGLESHELL Create a shell for each command.
1315 * .ORDER Must set initial predecessor to NULL
1319 if (paths
== NULL
) {
1320 paths
= Lst_Init(FALSE
);
1322 (void)Lst_AtEnd(paths
, dirSearchPath
);
1325 if (!Lst_IsEmpty(create
)) {
1334 gn
= Targ_FindNode(line
, TARG_CREATE
);
1337 gn
->type
|= OP_NOTMAIN
|OP_SPECIAL
;
1338 (void)Lst_AtEnd(targets
, gn
);
1341 gn
= Targ_NewGN(".DEFAULT");
1342 gn
->type
|= (OP_NOTMAIN
|OP_TRANSFORM
);
1343 (void)Lst_AtEnd(targets
, gn
);
1358 } else if (strncmp(line
, ".PATH", 5) == 0) {
1360 * .PATH<suffix> has to be handled specially.
1361 * Call on the suffix module to give us a path to
1367 path
= Suff_GetPath(&line
[5]);
1369 Parse_Error(PARSE_FATAL
,
1370 "Suffix '%s' not defined (yet)",
1374 if (paths
== NULL
) {
1375 paths
= Lst_Init(FALSE
);
1377 (void)Lst_AtEnd(paths
, path
);
1383 * Have word in line. Get or create its node and stick it at
1384 * the end of the targets list
1386 if ((specType
== Not
) && (*line
!= '\0')) {
1387 if (Dir_HasWildcards(line
)) {
1389 * Targets are to be sought only in the current directory,
1390 * so create an empty path for the thing. Note we need to
1391 * use Dir_Destroy in the destruction of the path as the
1392 * Dir module could have added a directory to the path...
1394 Lst emptyPath
= Lst_Init(FALSE
);
1396 Dir_Expand(line
, emptyPath
, curTargs
);
1398 Lst_Destroy(emptyPath
, Dir_Destroy
);
1401 * No wildcards, but we want to avoid code duplication,
1402 * so create a list with the word on it.
1404 (void)Lst_AtEnd(curTargs
, line
);
1407 while(!Lst_IsEmpty(curTargs
)) {
1408 char *targName
= (char *)Lst_DeQueue(curTargs
);
1410 if (!Suff_IsTransform (targName
)) {
1411 gn
= Targ_FindNode(targName
, TARG_CREATE
);
1413 gn
= Suff_AddTransform(targName
);
1418 (void)Lst_AtEnd(targets
, gn
);
1420 } else if (specType
== ExPath
&& *line
!= '.' && *line
!= '\0') {
1421 Parse_Error(PARSE_WARNING
, "Extra target (%s) ignored", line
);
1426 * If it is a special type and not .PATH, it's the only target we
1427 * allow on this line...
1429 if (specType
!= Not
&& specType
!= ExPath
) {
1430 Boolean warning
= FALSE
;
1432 while (*cp
&& (ParseIsEscaped(lstart
, cp
) ||
1433 ((*cp
!= '!') && (*cp
!= ':')))) {
1434 if (ParseIsEscaped(lstart
, cp
) ||
1435 (*cp
!= ' ' && *cp
!= '\t')) {
1441 Parse_Error(PARSE_WARNING
, "Extra target ignored");
1444 while (*cp
&& isspace ((unsigned char)*cp
)) {
1449 } while (*line
&& (ParseIsEscaped(lstart
, line
) ||
1450 ((*line
!= '!') && (*line
!= ':'))));
1453 * Don't need the list of target names anymore...
1455 Lst_Destroy(curTargs
, NULL
);
1458 if (!Lst_IsEmpty(targets
)) {
1461 Parse_Error(PARSE_WARNING
, "Special and mundane targets don't mix. Mundane ones ignored");
1470 * These four create nodes on which to hang commands, so
1471 * targets shouldn't be empty...
1475 * Nothing special here -- targets can be empty if it wants.
1482 * Have now parsed all the target names. Must parse the operator next. The
1483 * result is left in op .
1487 } else if (*cp
== ':') {
1495 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1496 : "Missing dependency operator");
1500 cp
++; /* Advance beyond operator */
1502 Lst_ForEach(targets
, ParseDoOp
, &op
);
1505 * Get to the first source
1507 while (*cp
&& isspace ((unsigned char)*cp
)) {
1513 * Several special targets take different actions if present with no
1515 * a .SUFFIXES line with no sources clears out all old suffixes
1516 * a .PRECIOUS line makes all targets precious
1517 * a .IGNORE line ignores errors for all targets
1518 * a .SILENT line creates silence when making all targets
1519 * a .PATH removes all directories from the search path(s).
1524 Suff_ClearSuffixes();
1530 ignoreErrors
= TRUE
;
1536 Lst_ForEach(paths
, ParseClearPath
, NULL
);
1541 Var_Set("%POSIX", "1003.2", VAR_GLOBAL
, 0);
1547 } else if (specType
== MFlags
) {
1549 * Call on functions in main.c to deal with these arguments and
1550 * set the initial character to a null-character so the loop to
1551 * get sources won't get anything
1553 Main_ParseArgLine(line
);
1555 } else if (specType
== ExShell
) {
1556 if (Job_ParseShell(line
) != SUCCESS
) {
1557 Parse_Error(PARSE_FATAL
, "improper shell specification");
1561 } else if ((specType
== NotParallel
) || (specType
== SingleShell
)) {
1566 * NOW GO FOR THE SOURCES
1568 if ((specType
== Suffixes
) || (specType
== ExPath
) ||
1569 (specType
== Includes
) || (specType
== Libs
) ||
1570 (specType
== Null
) || (specType
== ExObjdir
))
1574 * If the target was one that doesn't take files as its sources
1575 * but takes something like suffixes, we take each
1576 * space-separated word on the line as a something and deal
1577 * with it accordingly.
1579 * If the target was .SUFFIXES, we take each source as a
1580 * suffix and add it to the list of suffixes maintained by the
1583 * If the target was a .PATH, we add the source as a directory
1584 * to search on the search path.
1586 * If it was .INCLUDES, the source is taken to be the suffix of
1587 * files which will be #included and whose search path should
1588 * be present in the .INCLUDES variable.
1590 * If it was .LIBS, the source is taken to be the suffix of
1591 * files which are considered libraries and whose search path
1592 * should be present in the .LIBS variable.
1594 * If it was .NULL, the source is the suffix to use when a file
1595 * has no valid suffix.
1597 * If it was .OBJDIR, the source is a new definition for .OBJDIR,
1598 * and will cause make to do a new chdir to that path.
1600 while (*cp
&& !isspace ((unsigned char)*cp
)) {
1607 Suff_AddSuffix(line
, &mainNode
);
1610 Lst_ForEach(paths
, ParseAddDir
, line
);
1613 Suff_AddInclude(line
);
1622 Main_SetObjdir(line
);
1628 if (savec
!= '\0') {
1631 while (*cp
&& isspace ((unsigned char)*cp
)) {
1637 Lst_Destroy(paths
, NULL
);
1639 if (specType
== ExPath
)
1644 * The targets take real sources, so we must beware of archive
1645 * specifications (i.e. things with left parentheses in them)
1646 * and handle them accordingly.
1648 for (; *cp
&& !isspace ((unsigned char)*cp
); cp
++) {
1649 if ((*cp
== LPAREN
) && (cp
> line
) && (cp
[-1] != '$')) {
1651 * Only stop for a left parenthesis if it isn't at the
1652 * start of a word (that'll be for variable changes
1653 * later) and isn't preceded by a dollar sign (a dynamic
1660 if (*cp
== LPAREN
) {
1661 sources
= Lst_Init(FALSE
);
1662 if (Arch_ParseArchive(&line
, sources
, VAR_CMD
) != SUCCESS
) {
1663 Parse_Error(PARSE_FATAL
,
1664 "Error in source archive spec \"%s\"", line
);
1668 while (!Lst_IsEmpty (sources
)) {
1669 gn
= (GNode
*)Lst_DeQueue(sources
);
1670 ParseDoSrc(tOp
, gn
->name
);
1672 Lst_Destroy(sources
, NULL
);
1680 ParseDoSrc(tOp
, line
);
1682 while (*cp
&& isspace ((unsigned char)*cp
)) {
1689 if (mainNode
== NULL
) {
1691 * If we have yet to decide on a main target to make, in the
1692 * absence of any user input, we want the first target on
1693 * the first dependency line that is actually a real target
1694 * (i.e. isn't a .USE or .EXEC rule) to be made.
1696 Lst_ForEach(targets
, ParseFindMain
, NULL
);
1701 Lst_Destroy(curTargs
, NULL
);
1705 *---------------------------------------------------------------------
1707 * Return TRUE if the passed line is a variable assignment. A variable
1708 * assignment consists of a single word followed by optional whitespace
1709 * followed by either a += or an = operator.
1710 * This function is used both by the Parse_File function and main when
1711 * parsing the command-line arguments.
1714 * line the line to check
1717 * TRUE if it is. FALSE if it ain't
1721 *---------------------------------------------------------------------
1724 Parse_IsVar(char *line
)
1726 Boolean wasSpace
= FALSE
; /* set TRUE if found a space */
1729 #define ISEQOPERATOR(c) \
1730 (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1733 * Skip to variable name
1735 for (;(*line
== ' ') || (*line
== '\t'); line
++)
1738 /* Scan for one of the assignment operators outside a variable expansion */
1739 while ((ch
= *line
++) != 0) {
1740 if (ch
== '(' || ch
== '{') {
1744 if (ch
== ')' || ch
== '}') {
1750 while (ch
== ' ' || ch
== '\t') {
1755 if (ch
== ':' && strncmp(line
, "sh", 2) == 0) {
1762 if (*line
== '=' && ISEQOPERATOR(ch
))
1772 *---------------------------------------------------------------------
1774 * Take the variable assignment in the passed line and do it in the
1777 * Note: There is a lexical ambiguity with assignment modifier characters
1778 * in variable names. This routine interprets the character before the =
1779 * as a modifier. Therefore, an assignment like
1781 * is interpreted as "C+ +=" instead of "C++ =".
1784 * line a line guaranteed to be a variable assignment.
1785 * This reduces error checks
1786 * ctxt Context in which to do the assignment
1792 * the variable structure of the given variable name is altered in the
1794 *---------------------------------------------------------------------
1797 Parse_DoVar(char *line
, GNode
*ctxt
)
1799 char *cp
; /* pointer into line */
1801 VAR_SUBST
, VAR_APPEND
, VAR_SHELL
, VAR_NORMAL
1802 } type
; /* Type of assignment */
1803 char *opc
; /* ptr to operator character to
1804 * null-terminate the variable name */
1805 Boolean freeCp
= FALSE
; /* TRUE if cp needs to be freed,
1806 * i.e. if any variable expansion was
1811 * Skip to variable name
1813 while ((*line
== ' ') || (*line
== '\t')) {
1818 * Skip to operator character, nulling out whitespace as we go
1819 * XXX Rather than counting () and {} we should look for $ and
1820 * then expand the variable.
1822 for (depth
= 0, cp
= line
+ 1; depth
!= 0 || *cp
!= '='; cp
++) {
1823 if (*cp
== '(' || *cp
== '{') {
1827 if (*cp
== ')' || *cp
== '}') {
1831 if (depth
== 0 && isspace ((unsigned char)*cp
)) {
1835 opc
= cp
-1; /* operator is the previous character */
1836 *cp
++ = '\0'; /* nuke the = */
1839 * Check operator type
1849 * If the variable already has a value, we don't do anything.
1852 if (Var_Exists(line
, ctxt
)) {
1871 while (opc
> line
&& *opc
!= ':')
1874 if (strncmp(opc
, ":sh", 3) == 0) {
1884 while (isspace ((unsigned char)*cp
)) {
1888 if (type
== VAR_APPEND
) {
1889 Var_Append(line
, cp
, ctxt
);
1890 } else if (type
== VAR_SUBST
) {
1892 * Allow variables in the old value to be undefined, but leave their
1893 * invocation alone -- this is done by forcing oldVars to be false.
1894 * XXX: This can cause recursive variables, but that's not hard to do,
1895 * and this allows someone to do something like
1897 * CFLAGS = $(.INCLUDES)
1898 * CFLAGS := -I.. $(CFLAGS)
1900 * And not get an error.
1902 Boolean oldOldVars
= oldVars
;
1907 * make sure that we set the variable the first time to nothing
1908 * so that it gets substituted!
1910 if (!Var_Exists(line
, ctxt
))
1911 Var_Set(line
, "", ctxt
, 0);
1913 cp
= Var_Subst(NULL
, cp
, ctxt
, FALSE
);
1914 oldVars
= oldOldVars
;
1917 Var_Set(line
, cp
, ctxt
, 0);
1918 } else if (type
== VAR_SHELL
) {
1922 if (strchr(cp
, '$') != NULL
) {
1924 * There's a dollar sign in the command, so perform variable
1925 * expansion on the whole thing. The resulting string will need
1926 * freeing when we're done, so set freeCmd to TRUE.
1928 cp
= Var_Subst(NULL
, cp
, VAR_CMD
, TRUE
);
1932 res
= Cmd_Exec(cp
, &error
);
1933 Var_Set(line
, res
, ctxt
, 0);
1937 Parse_Error(PARSE_WARNING
, error
, cp
);
1940 * Normal assignment -- just do it.
1942 Var_Set(line
, cp
, ctxt
, 0);
1944 if (strcmp(line
, MAKEOVERRIDES
) == 0)
1945 Main_ExportMAKEFLAGS(FALSE
); /* re-export MAKEFLAGS */
1946 else if (strcmp(line
, ".CURDIR") == 0) {
1948 * Somone is being (too?) clever...
1949 * Let's pretend they know what they are doing and
1950 * re-initialize the 'cur' Path.
1954 } else if (strcmp(line
, MAKE_JOB_PREFIX
) == 0) {
1956 } else if (strcmp(line
, MAKE_EXPORTED
) == 0) {
1966 * Lst_ForEach function to add a command line to all targets
1969 * gnp the node to which the command is to be added
1970 * cmd the command to add
1976 * A new element is added to the commands list of the node.
1979 ParseAddCmd(void *gnp
, void *cmd
)
1981 GNode
*gn
= (GNode
*)gnp
;
1983 /* Add to last (ie current) cohort for :: targets */
1984 if ((gn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (gn
->cohorts
))
1985 gn
= (GNode
*)Lst_Datum(Lst_Last(gn
->cohorts
));
1987 /* if target already supplied, ignore commands */
1988 if (!(gn
->type
& OP_HAS_COMMANDS
)) {
1989 (void)Lst_AtEnd(gn
->commands
, cmd
);
1993 /* XXX: We cannot do this until we fix the tree */
1994 (void)Lst_AtEnd(gn
->commands
, cmd
);
1995 Parse_Error(PARSE_WARNING
,
1996 "overriding commands for target \"%s\"; "
1997 "previous commands defined at %s: %d ignored",
1998 gn
->name
, gn
->fname
, gn
->lineno
);
2000 Parse_Error(PARSE_WARNING
,
2001 "duplicate script for target \"%s\" ignored",
2003 ParseErrorInternal(gn
->fname
, gn
->lineno
, PARSE_WARNING
,
2004 "using previous script for \"%s\" defined here",
2012 *-----------------------------------------------------------------------
2013 * ParseHasCommands --
2014 * Callback procedure for Parse_File when destroying the list of
2015 * targets on the last dependency line. Marks a target as already
2016 * having commands if it does, to keep from having shell commands
2017 * on multiple dependency lines.
2020 * gnp Node to examine
2026 * OP_HAS_COMMANDS may be set for the target.
2028 *-----------------------------------------------------------------------
2031 ParseHasCommands(void *gnp
)
2033 GNode
*gn
= (GNode
*)gnp
;
2034 if (!Lst_IsEmpty(gn
->commands
)) {
2035 gn
->type
|= OP_HAS_COMMANDS
;
2040 *-----------------------------------------------------------------------
2041 * Parse_AddIncludeDir --
2042 * Add a directory to the path searched for included makefiles
2043 * bracketed by double-quotes. Used by functions in main.c
2046 * dir The name of the directory to add
2052 * The directory is appended to the list.
2054 *-----------------------------------------------------------------------
2057 Parse_AddIncludeDir(char *dir
)
2059 (void)Dir_AddDir(parseIncPath
, dir
);
2063 *---------------------------------------------------------------------
2065 * Push to another file.
2067 * The input is the line minus the `.'. A file spec is a string
2068 * enclosed in <> or "". The former is looked for only in sysIncPath.
2069 * The latter in . and the directories specified by -I command line
2076 * A structure is added to the includes Lst and readProc, lineno,
2077 * fname and curFILE are altered for the new file
2078 *---------------------------------------------------------------------
2082 Parse_include_file(char *file
, Boolean isSystem
, int silent
)
2084 struct loadedfile
*lf
;
2085 char *fullname
; /* full pathname of file */
2087 char *prefEnd
, *incdir
;
2092 * Now we know the file's name and its search path, we attempt to
2093 * find the durn thing. A return of NULL indicates the file don't
2096 fullname
= file
[0] == '/' ? bmake_strdup(file
) : NULL
;
2098 if (fullname
== NULL
&& !isSystem
) {
2100 * Include files contained in double-quotes are first searched for
2101 * relative to the including file's location. We don't want to
2102 * cd there, of course, so we just tack on the old file's
2103 * leading path components and call Dir_FindFile to see if
2104 * we can locate the beast.
2107 incdir
= bmake_strdup(curFile
->fname
);
2108 prefEnd
= strrchr(incdir
, '/');
2109 if (prefEnd
!= NULL
) {
2111 /* Now do lexical processing of leading "../" on the filename */
2112 for (i
= 0; strncmp(file
+ i
, "../", 3) == 0; i
+= 3) {
2113 prefEnd
= strrchr(incdir
+ 1, '/');
2114 if (prefEnd
== NULL
|| strcmp(prefEnd
, "/..") == 0)
2118 newName
= str_concat(incdir
, file
+ i
, STR_ADDSLASH
);
2119 fullname
= Dir_FindFile(newName
, parseIncPath
);
2120 if (fullname
== NULL
)
2121 fullname
= Dir_FindFile(newName
, dirSearchPath
);
2126 if (fullname
== NULL
) {
2128 * Makefile wasn't found in same directory as included makefile.
2129 * Search for it first on the -I search path,
2130 * then on the .PATH search path, if not found in a -I directory.
2131 * If we have a suffix specific path we should use that.
2134 Lst suffPath
= NULL
;
2136 if ((suff
= strrchr(file
, '.'))) {
2137 suffPath
= Suff_GetPath(suff
);
2138 if (suffPath
!= NULL
) {
2139 fullname
= Dir_FindFile(file
, suffPath
);
2142 if (fullname
== NULL
) {
2143 fullname
= Dir_FindFile(file
, parseIncPath
);
2144 if (fullname
== NULL
) {
2145 fullname
= Dir_FindFile(file
, dirSearchPath
);
2151 /* Looking for a system file or file still not found */
2152 if (fullname
== NULL
) {
2154 * Look for it on the system path
2156 fullname
= Dir_FindFile(file
,
2157 Lst_IsEmpty(sysIncPath
) ? defIncPath
: sysIncPath
);
2160 if (fullname
== NULL
) {
2162 Parse_Error(PARSE_FATAL
, "Could not find %s", file
);
2166 /* Actually open the file... */
2167 fd
= open(fullname
, O_RDONLY
);
2170 Parse_Error(PARSE_FATAL
, "Cannot open %s", fullname
);
2176 lf
= loadfile(fullname
, fd
);
2178 /* Start reading from this file next */
2179 Parse_SetInput(fullname
, 0, -1, loadedfile_nextbuf
, lf
);
2184 ParseDoInclude(char *line
)
2186 char endc
; /* the character which ends the file spec */
2187 char *cp
; /* current position in file spec */
2188 int silent
= (*line
!= 'i') ? 1 : 0;
2189 char *file
= &line
[7 + silent
];
2191 /* Skip to delimiter character so we know where to look */
2192 while (*file
== ' ' || *file
== '\t')
2195 if (*file
!= '"' && *file
!= '<') {
2196 Parse_Error(PARSE_FATAL
,
2197 ".include filename must be delimited by '\"' or '<'");
2202 * Set the search path on which to find the include file based on the
2203 * characters which bracket its name. Angle-brackets imply it's
2204 * a system Makefile while double-quotes imply it's a user makefile
2212 /* Skip to matching delimiter */
2213 for (cp
= ++file
; *cp
&& *cp
!= endc
; cp
++)
2217 Parse_Error(PARSE_FATAL
,
2218 "Unclosed %cinclude filename. '%c' expected",
2225 * Substitute for any variables in the file name before trying to
2228 file
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2230 Parse_include_file(file
, endc
== '>', silent
);
2236 *---------------------------------------------------------------------
2237 * ParseSetParseFile --
2238 * Set the .PARSEDIR and .PARSEFILE variables to the dirname and
2239 * basename of the given filename
2245 * The .PARSEDIR and .PARSEFILE variables are overwritten by the
2246 * dirname and basename of the given filename.
2247 *---------------------------------------------------------------------
2250 ParseSetParseFile(const char *filename
)
2252 char *slash
, *dirname
;
2253 const char *pd
, *pf
;
2256 slash
= strrchr(filename
, '/');
2257 if (slash
== NULL
) {
2258 Var_Set(".PARSEDIR", pd
= curdir
, VAR_GLOBAL
, 0);
2259 Var_Set(".PARSEFILE", pf
= filename
, VAR_GLOBAL
, 0);
2262 len
= slash
- filename
;
2263 dirname
= bmake_malloc(len
+ 1);
2264 memcpy(dirname
, filename
, len
);
2265 dirname
[len
] = '\0';
2266 Var_Set(".PARSEDIR", pd
= dirname
, VAR_GLOBAL
, 0);
2267 Var_Set(".PARSEFILE", pf
= slash
+ 1, VAR_GLOBAL
, 0);
2270 fprintf(debug_file
, "ParseSetParseFile: ${.PARSEDIR} = `%s' "
2271 "${.PARSEFILE} = `%s'\n", pd
, pf
);
2276 * Track the makefiles we read - so makefiles can
2277 * set dependencies on them.
2278 * Avoid adding anything more than once.
2282 ParseTrackInput(const char *name
)
2286 size_t name_len
= strlen(name
);
2288 old
= Var_Value(MAKE_MAKEFILES
, VAR_GLOBAL
, &fp
);
2290 /* does it contain name? */
2291 for (; old
!= NULL
; old
= strchr(old
, ' ')) {
2294 if (memcmp(old
, name
, name_len
) == 0
2295 && (old
[name_len
] == 0 || old
[name_len
] == ' '))
2299 Var_Append (MAKE_MAKEFILES
, name
, VAR_GLOBAL
);
2308 *---------------------------------------------------------------------
2310 * Start Parsing from the given source
2316 * A structure is added to the includes Lst and readProc, lineno,
2317 * fname and curFile are altered for the new file
2318 *---------------------------------------------------------------------
2321 Parse_SetInput(const char *name
, int line
, int fd
,
2322 char *(*nextbuf
)(void *, size_t *), void *arg
)
2328 name
= curFile
->fname
;
2330 ParseTrackInput(name
);
2333 fprintf(debug_file
, "Parse_SetInput: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
2334 name
, line
, fd
, nextbuf
, arg
);
2336 if (fd
== -1 && nextbuf
== NULL
)
2340 if (curFile
!= NULL
)
2341 /* Save exiting file info */
2342 Lst_AtFront(includes
, curFile
);
2344 /* Allocate and fill in new structure */
2345 curFile
= bmake_malloc(sizeof *curFile
);
2348 * Once the previous state has been saved, we can get down to reading
2349 * the new file. We set up the name of the file to be the absolute
2350 * name of the include file so error messages refer to the right
2353 curFile
->fname
= bmake_strdup(name
);
2354 curFile
->lineno
= line
;
2355 curFile
->first_lineno
= line
;
2356 curFile
->nextbuf
= nextbuf
;
2357 curFile
->nextbuf_arg
= arg
;
2360 assert(nextbuf
!= NULL
);
2362 /* Get first block of input data */
2363 buf
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2365 /* Was all a waste of time ... */
2367 free(curFile
->fname
);
2371 curFile
->P_str
= buf
;
2372 curFile
->P_ptr
= buf
;
2373 curFile
->P_end
= buf
+len
;
2375 curFile
->cond_depth
= Cond_save_depth();
2376 ParseSetParseFile(name
);
2381 *---------------------------------------------------------------------
2382 * ParseTraditionalInclude --
2383 * Push to another file.
2385 * The input is the current line. The file name(s) are
2386 * following the "include".
2392 * A structure is added to the includes Lst and readProc, lineno,
2393 * fname and curFILE are altered for the new file
2394 *---------------------------------------------------------------------
2397 ParseTraditionalInclude(char *line
)
2399 char *cp
; /* current position in file spec */
2401 int silent
= (line
[0] != 'i') ? 1 : 0;
2402 char *file
= &line
[silent
+ 7];
2406 fprintf(debug_file
, "ParseTraditionalInclude: %s\n", file
);
2410 * Skip over whitespace
2412 while (isspace((unsigned char)*file
))
2416 * Substitute for any variables in the file name before trying to
2419 all_files
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2421 if (*file
== '\0') {
2422 Parse_Error(PARSE_FATAL
,
2423 "Filename missing from \"include\"");
2427 for (file
= all_files
; !done
; file
= cp
+ 1) {
2428 /* Skip to end of line or next whitespace */
2429 for (cp
= file
; *cp
&& !isspace((unsigned char) *cp
); cp
++)
2437 Parse_include_file(file
, FALSE
, silent
);
2445 *---------------------------------------------------------------------
2446 * ParseGmakeExport --
2447 * Parse export <variable>=<value>
2449 * And set the environment with it.
2456 *---------------------------------------------------------------------
2459 ParseGmakeExport(char *line
)
2461 char *variable
= &line
[6];
2465 fprintf(debug_file
, "ParseGmakeExport: %s\n", variable
);
2469 * Skip over whitespace
2471 while (isspace((unsigned char)*variable
))
2474 for (value
= variable
; *value
&& *value
!= '='; value
++)
2477 if (*value
!= '=') {
2478 Parse_Error(PARSE_FATAL
,
2479 "Variable/Value missing from \"export\"");
2482 *value
++ = '\0'; /* terminate variable */
2485 * Expand the value before putting it in the environment.
2487 value
= Var_Subst(NULL
, value
, VAR_CMD
, FALSE
);
2488 setenv(variable
, value
, 1);
2493 *---------------------------------------------------------------------
2495 * Called when EOF is reached in the current file. If we were reading
2496 * an include file, the includes stack is popped and things set up
2497 * to go back to reading the previous file at the previous location.
2500 * CONTINUE if there's more to do. DONE if not.
2503 * The old curFILE, is closed. The includes list is shortened.
2504 * lineno, curFILE, and fname are changed if CONTINUE is returned.
2505 *---------------------------------------------------------------------
2513 assert(curFile
->nextbuf
!= NULL
);
2515 /* get next input buffer, if any */
2516 ptr
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2517 curFile
->P_ptr
= ptr
;
2518 curFile
->P_str
= ptr
;
2519 curFile
->P_end
= ptr
+ len
;
2520 curFile
->lineno
= curFile
->first_lineno
;
2526 /* Ensure the makefile (or loop) didn't have mismatched conditionals */
2527 Cond_restore_depth(curFile
->cond_depth
);
2529 if (curFile
->lf
!= NULL
) {
2530 loadedfile_destroy(curFile
->lf
);
2534 /* Dispose of curFile info */
2535 /* Leak curFile->fname because all the gnodes have pointers to it */
2536 free(curFile
->P_str
);
2539 curFile
= Lst_DeQueue(includes
);
2541 if (curFile
== NULL
) {
2542 /* We've run out of input */
2543 Var_Delete(".PARSEDIR", VAR_GLOBAL
);
2544 Var_Delete(".PARSEFILE", VAR_GLOBAL
);
2549 fprintf(debug_file
, "ParseEOF: returning to file %s, line %d\n",
2550 curFile
->fname
, curFile
->lineno
);
2552 /* Restore the PARSEDIR/PARSEFILE variables */
2553 ParseSetParseFile(curFile
->fname
);
2558 #define PARSE_SKIP 2
2561 ParseGetLine(int flags
, int *length
)
2563 IFile
*cf
= curFile
;
2572 /* Loop through blank lines and comment lines */
2581 if (cf
->P_end
!= NULL
&& ptr
== cf
->P_end
) {
2587 if (ch
== 0 || (ch
== '\\' && ptr
[1] == 0)) {
2588 if (cf
->P_end
== NULL
)
2589 /* End of string (aka for loop) data */
2591 /* see if there is more we can parse */
2592 while (ptr
++ < cf
->P_end
) {
2593 if ((ch
= *ptr
) == '\n') {
2594 if (ptr
> line
&& ptr
[-1] == '\\')
2596 Parse_Error(PARSE_WARNING
,
2597 "Zero byte read from file, skipping rest of line.");
2601 if (cf
->nextbuf
!= NULL
) {
2603 * End of this buffer; return EOF and outer logic
2604 * will get the next one. (eww)
2608 Parse_Error(PARSE_FATAL
, "Zero byte read from file");
2613 /* Don't treat next character as special, remember first one */
2614 if (escaped
== NULL
)
2622 if (ch
== '#' && comment
== NULL
) {
2623 /* Remember first '#' for comment stripping */
2624 /* Unless previous char was '[', as in modifier :[#] */
2625 if (!(ptr
> line
&& ptr
[-1] == '['))
2631 if (!isspace((unsigned char)ch
))
2632 /* We are not interested in trailing whitespace */
2636 /* Save next 'to be processed' location */
2639 /* Check we have a non-comment, non-blank line */
2640 if (line_end
== line
|| comment
== line
) {
2642 /* At end of file */
2644 /* Parse another line */
2648 /* We now have a line of data */
2651 if (flags
& PARSE_RAW
) {
2652 /* Leave '\' (etc) in line buffer (eg 'for' lines) */
2653 *length
= line_end
- line
;
2657 if (flags
& PARSE_SKIP
) {
2658 /* Completely ignore non-directives */
2661 /* We could do more of the .else/.elif/.endif checks here */
2666 /* Brutally ignore anything after a non-escaped '#' in non-commands */
2667 if (comment
!= NULL
&& line
[0] != '\t') {
2672 /* If we didn't see a '\\' then the in-situ data is fine */
2673 if (escaped
== NULL
) {
2674 *length
= line_end
- line
;
2678 /* Remove escapes from '\n' and '#' */
2681 for (; ; *tp
++ = ch
) {
2691 /* Delete '\\' at end of buffer */
2696 if (ch
== '#' && line
[0] != '\t')
2697 /* Delete '\\' from before '#' on non-command lines */
2701 /* Leave '\\' in buffer for later */
2703 /* Make sure we don't delete an escaped ' ' from the line end */
2708 /* Escaped '\n' replace following whitespace with a single ' ' */
2709 while (ptr
[0] == ' ' || ptr
[0] == '\t')
2714 /* Delete any trailing spaces - eg from empty continuations */
2715 while (tp
> escaped
&& isspace((unsigned char)tp
[-1]))
2719 *length
= tp
- line
;
2724 *---------------------------------------------------------------------
2726 * Read an entire line from the input file. Called only by Parse_File.
2729 * A line w/o its newline
2732 * Only those associated with reading a character
2733 *---------------------------------------------------------------------
2738 char *line
; /* Result */
2739 int lineLength
; /* Length of result */
2740 int lineno
; /* Saved line # */
2744 line
= ParseGetLine(0, &lineLength
);
2752 * The line might be a conditional. Ask the conditional module
2753 * about it and act accordingly
2755 switch (Cond_Eval(line
)) {
2757 /* Skip to next conditional that evaluates to COND_PARSE. */
2759 line
= ParseGetLine(PARSE_SKIP
, &lineLength
);
2760 } while (line
&& Cond_Eval(line
) != COND_PARSE
);
2766 case COND_INVALID
: /* Not a conditional line */
2767 /* Check for .for loops */
2768 rval
= For_Eval(line
);
2770 /* Not a .for line */
2773 /* Syntax error - error printed, ignore line */
2775 /* Start of a .for loop */
2776 lineno
= curFile
->lineno
;
2777 /* Accumulate loop lines until matching .endfor */
2779 line
= ParseGetLine(PARSE_RAW
, &lineLength
);
2781 Parse_Error(PARSE_FATAL
,
2782 "Unexpected end of file in for loop.");
2785 } while (For_Accum(line
));
2786 /* Stash each iteration as a new 'input file' */
2788 /* Read next line from for-loop buffer */
2796 *-----------------------------------------------------------------------
2797 * ParseFinishLine --
2798 * Handle the end of a dependency group.
2804 * inLine set FALSE. 'targets' list destroyed.
2806 *-----------------------------------------------------------------------
2809 ParseFinishLine(void)
2812 Lst_ForEach(targets
, Suff_EndTransform
, NULL
);
2813 Lst_Destroy(targets
, ParseHasCommands
);
2821 *---------------------------------------------------------------------
2823 * Parse a file into its component parts, incorporating it into the
2824 * current dependency graph. This is the main function and controls
2825 * almost every other function in this module
2828 * name the name of the file being read
2829 * fd Open file to makefile to parse
2836 * Loads. Nodes are added to the list of all targets, nodes and links
2837 * are added to the dependency graph. etc. etc. etc.
2838 *---------------------------------------------------------------------
2841 Parse_File(const char *name
, int fd
)
2843 char *cp
; /* pointer into the line */
2844 char *line
; /* the line we're working on */
2845 struct loadedfile
*lf
;
2847 lf
= loadfile(name
, fd
);
2856 Parse_SetInput(name
, 0, -1, loadedfile_nextbuf
, lf
);
2860 for (; (line
= ParseReadLine()) != NULL
; ) {
2862 fprintf(debug_file
, "ParseReadLine (%d): '%s'\n",
2863 curFile
->lineno
, line
);
2866 * Lines that begin with the special character may be
2867 * include or undef directives.
2868 * On the other hand they can be suffix rules (.c.o: ...)
2869 * or just dependencies for filenames that start '.'.
2871 for (cp
= line
+ 1; isspace((unsigned char)*cp
); cp
++) {
2874 if (strncmp(cp
, "include", 7) == 0 ||
2875 ((cp
[0] == 's' || cp
[0] == '-') &&
2876 strncmp(&cp
[1], "include", 7) == 0)) {
2880 if (strncmp(cp
, "undef", 5) == 0) {
2882 for (cp
+= 5; isspace((unsigned char) *cp
); cp
++)
2884 for (cp2
= cp
; !isspace((unsigned char) *cp2
) &&
2885 (*cp2
!= '\0'); cp2
++)
2888 Var_Delete(cp
, VAR_GLOBAL
);
2890 } else if (strncmp(cp
, "export", 6) == 0) {
2891 for (cp
+= 6; isspace((unsigned char) *cp
); cp
++)
2895 } else if (strncmp(cp
, "unexport", 8) == 0) {
2898 } else if (strncmp(cp
, "info", 4) == 0 ||
2899 strncmp(cp
, "error", 5) == 0 ||
2900 strncmp(cp
, "warning", 7) == 0) {
2901 if (ParseMessage(cp
))
2906 if (*line
== '\t') {
2908 * If a line starts with a tab, it can only hope to be
2909 * a creation command.
2913 for (; isspace ((unsigned char)*cp
); cp
++) {
2918 Parse_Error(PARSE_FATAL
,
2919 "Unassociated shell command \"%s\"",
2922 * So long as it's not a blank line and we're actually
2923 * in a dependency spec, add the command to the list of
2924 * commands of all targets in the dependency spec
2927 cp
= bmake_strdup(cp
);
2928 Lst_ForEach(targets
, ParseAddCmd
, cp
);
2930 Lst_AtEnd(targCmds
, cp
);
2938 if (((strncmp(line
, "include", 7) == 0 &&
2939 isspace((unsigned char) line
[7])) ||
2940 ((line
[0] == 's' || line
[0] == '-') &&
2941 strncmp(&line
[1], "include", 7) == 0 &&
2942 isspace((unsigned char) line
[8]))) &&
2943 strchr(line
, ':') == NULL
) {
2945 * It's an S3/S5-style "include".
2947 ParseTraditionalInclude(line
);
2952 if (strncmp(line
, "export", 6) == 0 &&
2953 isspace((unsigned char) line
[6]) &&
2954 strchr(line
, ':') == NULL
) {
2956 * It's a Gmake "export".
2958 ParseGmakeExport(line
);
2962 if (Parse_IsVar(line
)) {
2964 Parse_DoVar(line
, VAR_GLOBAL
);
2970 * To make life easier on novices, if the line is indented we
2971 * first make sure the line has a dependency operator in it.
2972 * If it doesn't have an operator and we're in a dependency
2973 * line's script, we assume it's actually a shell command
2974 * and add it to the current list of targets.
2977 if (isspace((unsigned char) line
[0])) {
2978 while ((*cp
!= '\0') && isspace((unsigned char) *cp
))
2980 while (*cp
&& (ParseIsEscaped(line
, cp
) ||
2981 (*cp
!= ':') && (*cp
!= '!'))) {
2986 Parse_Error(PARSE_WARNING
,
2987 "Shell command needs a leading tab");
2996 * For some reason - probably to make the parser impossible -
2997 * a ';' can be used to separate commands from dependencies.
2998 * Attempt to avoid ';' inside substitution patterns.
3003 for (cp
= line
; *cp
!= 0; cp
++) {
3004 if (*cp
== '\\' && cp
[1] != 0) {
3009 (cp
[1] == '(' || cp
[1] == '{')) {
3014 if (*cp
== ')' || *cp
== '}') {
3018 } else if (*cp
== ';') {
3024 /* Terminate the dependency list at the ';' */
3030 * We now know it's a dependency line so it needs to have all
3031 * variables expanded before being parsed. Tell the variable
3032 * module to complain if some variable is undefined...
3034 line
= Var_Subst(NULL
, line
, VAR_CMD
, TRUE
);
3037 * Need a non-circular list for the target nodes
3040 Lst_Destroy(targets
, NULL
);
3042 targets
= Lst_Init(FALSE
);
3045 ParseDoDependency(line
);
3048 /* If there were commands after a ';', add them now */
3054 * Reached EOF, but it may be just EOF of an include file...
3056 } while (ParseEOF() == CONTINUE
);
3059 (void)fflush(stdout
);
3060 (void)fprintf(stderr
,
3061 "%s: Fatal errors encountered -- cannot continue",
3063 PrintOnError(NULL
, NULL
);
3069 *---------------------------------------------------------------------
3071 * initialize the parsing module
3077 * the parseIncPath list is initialized...
3078 *---------------------------------------------------------------------
3084 parseIncPath
= Lst_Init(FALSE
);
3085 sysIncPath
= Lst_Init(FALSE
);
3086 defIncPath
= Lst_Init(FALSE
);
3087 includes
= Lst_Init(FALSE
);
3089 targCmds
= Lst_Init(FALSE
);
3097 Lst_Destroy(targCmds
, (FreeProc
*)free
);
3099 Lst_Destroy(targets
, NULL
);
3100 Lst_Destroy(defIncPath
, Dir_Destroy
);
3101 Lst_Destroy(sysIncPath
, Dir_Destroy
);
3102 Lst_Destroy(parseIncPath
, Dir_Destroy
);
3103 Lst_Destroy(includes
, NULL
); /* Should be empty now */
3109 *-----------------------------------------------------------------------
3111 * Return a Lst of the main target to create for main()'s sake. If
3112 * no such target exists, we Punt with an obnoxious error message.
3115 * A Lst of the single node to create.
3120 *-----------------------------------------------------------------------
3123 Parse_MainName(void)
3125 Lst mainList
; /* result list */
3127 mainList
= Lst_Init(FALSE
);
3129 if (mainNode
== NULL
) {
3130 Punt("no target to make.");
3132 } else if (mainNode
->type
& OP_DOUBLEDEP
) {
3133 (void)Lst_AtEnd(mainList
, mainNode
);
3134 Lst_Concat(mainList
, mainNode
->cohorts
, LST_CONCNEW
);
3137 (void)Lst_AtEnd(mainList
, mainNode
);
3138 Var_Append(".TARGETS", mainNode
->name
, VAR_GLOBAL
);
3143 *-----------------------------------------------------------------------
3145 * Add the filename and lineno to the GNode so that we remember
3146 * where it was first defined.
3151 *-----------------------------------------------------------------------
3154 ParseMark(GNode
*gn
)
3156 gn
->fname
= curFile
->fname
;
3157 gn
->lineno
= curFile
->lineno
;