1 /* $NetBSD: parse.c,v 1.204 2014/09/18 08:06:13 dholland 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.204 2014/09/18 08:06:13 dholland 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.204 2014/09/18 08:06:13 dholland 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/mman.h>
128 #include <sys/stat.h>
140 #define MAP_COPY MAP_PRIVATE
148 #include "pathnames.h"
150 ////////////////////////////////////////////////////////////
151 // types and constants
154 * Structure for a file being read ("included file")
156 typedef struct IFile
{
157 char *fname
; /* name of file */
158 int lineno
; /* current line number in file */
159 int first_lineno
; /* line number of start of text */
160 int cond_depth
; /* 'if' nesting when file opened */
161 char *P_str
; /* point to base of string buffer */
162 char *P_ptr
; /* point to next char of string buffer */
163 char *P_end
; /* point to the end of string buffer */
164 char *(*nextbuf
)(void *, size_t *); /* Function to get more data */
165 void *nextbuf_arg
; /* Opaque arg for nextbuf() */
166 struct loadedfile
*lf
; /* loadedfile object, if any */
171 * These values are returned by ParseEOF to tell Parse_File whether to
172 * CONTINUE parsing, i.e. it had only reached the end of an include file,
179 * Tokens for target attributes
183 Default
, /* .DEFAULT */
185 dotError
, /* .ERROR */
186 Ignore
, /* .IGNORE */
187 Includes
, /* .INCLUDES */
188 Interrupt
, /* .INTERRUPT */
191 MFlags
, /* .MFLAGS or .MAKEFLAGS */
192 Main
, /* .MAIN and we don't have anything user-specified to
194 NoExport
, /* .NOEXPORT */
195 NoMeta
, /* .NOMETA */
196 NoMetaCmp
, /* .NOMETA_CMP */
197 NoPath
, /* .NOPATH */
198 Not
, /* Not special */
199 NotParallel
, /* .NOTPARALLEL */
201 ExObjdir
, /* .OBJDIR */
203 Parallel
, /* .PARALLEL */
209 Precious
, /* .PRECIOUS */
210 ExShell
, /* .SHELL */
211 Silent
, /* .SILENT */
212 SingleShell
, /* .SINGLESHELL */
214 Suffixes
, /* .SUFFIXES */
216 Attribute
/* Generic attribute */
226 ////////////////////////////////////////////////////////////
230 * The main target to create. This is the first target on the first
231 * dependency line in the first makefile.
233 static GNode
*mainNode
;
235 ////////////////////////////////////////////////////////////
238 /* targets we're working on */
242 /* command lines for targets */
247 * specType contains the SPECial TYPE of the current target. It is
248 * Not if the target is unspecial. If it *is* special, however, the children
249 * are linked as children of the parent but not vice versa. This variable is
250 * set in ParseDoDependency
252 static ParseSpecial specType
;
255 * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
256 * seen, then set to each successive source on the line.
258 static GNode
*predecessor
;
260 ////////////////////////////////////////////////////////////
263 /* true if currently in a dependency line or its commands */
264 static Boolean inLine
;
266 /* number of fatal errors */
267 static int fatals
= 0;
270 * Variables for doing includes
273 /* current file being read */
274 static IFile
*curFile
;
276 /* stack of IFiles generated by .includes */
279 /* include paths (lists of directories) */
280 Lst parseIncPath
; /* dirs for "..." includes */
281 Lst sysIncPath
; /* dirs for <...> includes */
282 Lst defIncPath
; /* default for sysIncPath */
284 ////////////////////////////////////////////////////////////
288 * The parseKeywords table is searched using binary search when deciding
289 * if a target or source is special. The 'spec' field is the ParseSpecial
290 * type of the keyword ("Not" if the keyword isn't special as a target) while
291 * the 'op' field is the operator to apply to the list of targets if the
292 * keyword is used as a source ("0" if the keyword isn't special as a source)
294 static const struct {
295 const char *name
; /* Name of keyword */
296 ParseSpecial spec
; /* Type when used as a target */
297 int op
; /* Operator when used as a source */
298 } parseKeywords
[] = {
299 { ".BEGIN", Begin
, 0 },
300 { ".DEFAULT", Default
, 0 },
302 { ".ERROR", dotError
, 0 },
303 { ".EXEC", Attribute
, OP_EXEC
},
304 { ".IGNORE", Ignore
, OP_IGNORE
},
305 { ".INCLUDES", Includes
, 0 },
306 { ".INTERRUPT", Interrupt
, 0 },
307 { ".INVISIBLE", Attribute
, OP_INVISIBLE
},
308 { ".JOIN", Attribute
, OP_JOIN
},
309 { ".LIBS", Libs
, 0 },
310 { ".MADE", Attribute
, OP_MADE
},
311 { ".MAIN", Main
, 0 },
312 { ".MAKE", Attribute
, OP_MAKE
},
313 { ".MAKEFLAGS", MFlags
, 0 },
314 { ".META", Meta
, OP_META
},
315 { ".MFLAGS", MFlags
, 0 },
316 { ".NOMETA", NoMeta
, OP_NOMETA
},
317 { ".NOMETA_CMP", NoMetaCmp
, OP_NOMETA_CMP
},
318 { ".NOPATH", NoPath
, OP_NOPATH
},
319 { ".NOTMAIN", Attribute
, OP_NOTMAIN
},
320 { ".NOTPARALLEL", NotParallel
, 0 },
321 { ".NO_PARALLEL", NotParallel
, 0 },
322 { ".NULL", Null
, 0 },
323 { ".OBJDIR", ExObjdir
, 0 },
324 { ".OPTIONAL", Attribute
, OP_OPTIONAL
},
325 { ".ORDER", Order
, 0 },
326 { ".PARALLEL", Parallel
, 0 },
327 { ".PATH", ExPath
, 0 },
328 { ".PHONY", Phony
, OP_PHONY
},
330 { ".POSIX", Posix
, 0 },
332 { ".PRECIOUS", Precious
, OP_PRECIOUS
},
333 { ".RECURSIVE", Attribute
, OP_MAKE
},
334 { ".SHELL", ExShell
, 0 },
335 { ".SILENT", Silent
, OP_SILENT
},
336 { ".SINGLESHELL", SingleShell
, 0 },
337 { ".STALE", Stale
, 0 },
338 { ".SUFFIXES", Suffixes
, 0 },
339 { ".USE", Attribute
, OP_USE
},
340 { ".USEBEFORE", Attribute
, OP_USEBEFORE
},
341 { ".WAIT", Wait
, 0 },
344 ////////////////////////////////////////////////////////////
347 static int ParseIsEscaped(const char *, const char *);
348 static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
349 MAKE_ATTR_PRINTFLIKE(4,5);
350 static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list)
351 MAKE_ATTR_PRINTFLIKE(5, 0);
352 static int ParseFindKeyword(const char *);
353 static int ParseLinkSrc(void *, void *);
354 static int ParseDoOp(void *, void *);
355 static void ParseDoSrc(int, const char *);
356 static int ParseFindMain(void *, void *);
357 static int ParseAddDir(void *, void *);
358 static int ParseClearPath(void *, void *);
359 static void ParseDoDependency(char *);
360 static int ParseAddCmd(void *, void *);
361 static void ParseHasCommands(void *);
362 static void ParseDoInclude(char *);
363 static void ParseSetParseFile(const char *);
364 static void ParseSetIncludedFile(void);
366 static void ParseTraditionalInclude(char *);
369 static void ParseGmakeExport(char *);
371 static int ParseEOF(void);
372 static char *ParseReadLine(void);
373 static void ParseFinishLine(void);
374 static void ParseMark(GNode
*);
376 ////////////////////////////////////////////////////////////
380 const char *path
; /* name, for error reports */
381 char *buf
; /* contents buffer */
382 size_t len
; /* length of contents */
383 size_t maplen
; /* length of mmap area, or 0 */
384 Boolean used
; /* XXX: have we used the data yet */
388 * Constructor/destructor for loadedfile
390 static struct loadedfile
*
391 loadedfile_create(const char *path
)
393 struct loadedfile
*lf
;
395 lf
= bmake_malloc(sizeof(*lf
));
396 lf
->path
= (path
== NULL
? "(stdin)" : path
);
405 loadedfile_destroy(struct loadedfile
*lf
)
407 if (lf
->buf
!= NULL
) {
408 if (lf
->maplen
> 0) {
409 munmap(lf
->buf
, lf
->maplen
);
418 * nextbuf() operation for loadedfile, as needed by the weird and twisted
419 * logic below. Once that's cleaned up, we can get rid of lf->used...
422 loadedfile_nextbuf(void *x
, size_t *len
)
424 struct loadedfile
*lf
= x
;
435 * Try to get the size of a file.
438 load_getsize(int fd
, size_t *ret
)
442 if (fstat(fd
, &st
) < 0) {
446 if (!S_ISREG(st
.st_mode
)) {
451 * st_size is an off_t, which is 64 bits signed; *ret is
452 * size_t, which might be 32 bits unsigned or 64 bits
453 * unsigned. Rather than being elaborate, just punt on
454 * files that are more than 2^31 bytes. We should never
455 * see a makefile that size in practice...
457 * While we're at it reject negative sizes too, just in case.
459 if (st
.st_size
< 0 || st
.st_size
> 0x7fffffff) {
463 *ret
= (size_t) st
.st_size
;
470 * Until the path search logic can be moved under here instead of
471 * being in the caller in another source file, we need to have the fd
472 * passed in already open. Bleh.
474 * If the path is NULL use stdin and (to insure against fd leaks)
475 * assert that the caller passed in -1.
477 static struct loadedfile
*
478 loadfile(const char *path
, int fd
)
480 struct loadedfile
*lf
;
485 lf
= loadedfile_create(path
);
492 fd
= open(path
, O_RDONLY
);
495 Error("%s: %s", path
, strerror(errno
));
501 if (load_getsize(fd
, &lf
->len
) == SUCCESS
) {
502 /* found a size, try mmap */
503 pagesize
= sysconf(_SC_PAGESIZE
);
507 /* round size up to a page */
508 lf
->maplen
= pagesize
* ((lf
->len
+ pagesize
- 1)/pagesize
);
511 * XXX hack for dealing with empty files; remove when
512 * we're no longer limited by interfacing to the old
513 * logic elsewhere in this file.
515 if (lf
->maplen
== 0) {
516 lf
->maplen
= pagesize
;
520 * FUTURE: remove PROT_WRITE when the parser no longer
521 * needs to scribble on the input.
523 lf
->buf
= mmap(NULL
, lf
->maplen
, PROT_READ
|PROT_WRITE
,
524 MAP_FILE
|MAP_COPY
, fd
, 0);
525 if (lf
->buf
!= MAP_FAILED
) {
527 if (lf
->len
== lf
->maplen
&& lf
->buf
[lf
->len
- 1] != '\n') {
528 char *b
= malloc(lf
->len
+ 1);
530 memcpy(b
, lf
->buf
, lf
->len
++);
531 munmap(lf
->buf
, lf
->maplen
);
539 /* cannot mmap; load the traditional way */
543 lf
->buf
= bmake_malloc(lf
->len
);
547 assert(bufpos
<= lf
->len
);
548 if (bufpos
== lf
->len
) {
550 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
552 result
= read(fd
, lf
->buf
+ bufpos
, lf
->len
- bufpos
);
554 Error("%s: read error: %s", path
, strerror(errno
));
562 assert(bufpos
<= lf
->len
);
565 /* truncate malloc region to actual length (maybe not useful) */
567 lf
->buf
= bmake_realloc(lf
->buf
, lf
->len
);
577 ////////////////////////////////////////////////////////////
581 *----------------------------------------------------------------------
583 * Check if the current character is escaped on the current line
586 * 0 if the character is not backslash escaped, 1 otherwise
590 *----------------------------------------------------------------------
593 ParseIsEscaped(const char *line
, const char *c
)
606 *----------------------------------------------------------------------
607 * ParseFindKeyword --
608 * Look in the table of keywords for one matching the given string.
614 * The index of the keyword, or -1 if it isn't there.
618 *----------------------------------------------------------------------
621 ParseFindKeyword(const char *str
)
627 end
= (sizeof(parseKeywords
)/sizeof(parseKeywords
[0])) - 1;
630 cur
= start
+ ((end
- start
) / 2);
631 diff
= strcmp(str
, parseKeywords
[cur
].name
);
635 } else if (diff
< 0) {
640 } while (start
<= end
);
645 * ParseVErrorInternal --
646 * Error message abort function for parsing. Prints out the context
647 * of the error (line number and file) as well as the message with
648 * two optional arguments.
654 * "fatals" is incremented if the level is PARSE_FATAL.
658 ParseVErrorInternal(FILE *f
, const char *cfname
, size_t clineno
, int type
,
659 const char *fmt
, va_list ap
)
661 static Boolean fatal_warning_error_printed
= FALSE
;
663 (void)fprintf(f
, "%s: ", progname
);
665 if (cfname
!= NULL
) {
666 (void)fprintf(f
, "\"");
667 if (*cfname
!= '/' && strcmp(cfname
, "(stdin)") != 0) {
672 * Nothing is more annoying than not knowing
673 * which Makefile is the culprit.
675 dir
= Var_Value(".PARSEDIR", VAR_GLOBAL
, &cp
);
676 if (dir
== NULL
|| *dir
== '\0' ||
677 (*dir
== '.' && dir
[1] == '\0'))
678 dir
= Var_Value(".CURDIR", VAR_GLOBAL
, &cp
);
682 (void)fprintf(f
, "%s/%s", dir
, cfname
);
684 (void)fprintf(f
, "%s", cfname
);
686 (void)fprintf(f
, "\" line %d: ", (int)clineno
);
688 if (type
== PARSE_WARNING
)
689 (void)fprintf(f
, "warning: ");
690 (void)vfprintf(f
, fmt
, ap
);
691 (void)fprintf(f
, "\n");
693 if (type
== PARSE_FATAL
|| parseWarnFatal
)
695 if (parseWarnFatal
&& !fatal_warning_error_printed
) {
696 Error("parsing warnings being treated as errors");
697 fatal_warning_error_printed
= TRUE
;
702 * ParseErrorInternal --
713 ParseErrorInternal(const char *cfname
, size_t clineno
, int type
,
714 const char *fmt
, ...)
719 (void)fflush(stdout
);
720 ParseVErrorInternal(stderr
, cfname
, clineno
, type
, fmt
, ap
);
723 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
725 ParseVErrorInternal(debug_file
, cfname
, clineno
, type
, fmt
, ap
);
732 * External interface to ParseErrorInternal; uses the default filename
743 Parse_Error(int type
, const char *fmt
, ...)
749 if (curFile
== NULL
) {
753 fname
= curFile
->fname
;
754 lineno
= curFile
->lineno
;
758 (void)fflush(stdout
);
759 ParseVErrorInternal(stderr
, fname
, lineno
, type
, fmt
, ap
);
762 if (debug_file
!= stderr
&& debug_file
!= stdout
) {
764 ParseVErrorInternal(debug_file
, fname
, lineno
, type
, fmt
, ap
);
772 * Parse a .info .warning or .error directive
774 * The input is the line minus the ".". We substitute
775 * variables, print the message and exit(1) (for .error) or just print
776 * a warning if the directive is malformed.
779 ParseMessage(char *line
)
788 mtype
= PARSE_WARNING
;
794 Parse_Error(PARSE_WARNING
, "invalid syntax: \".%s\"", line
);
798 while (isalpha((u_char
)*line
))
800 if (!isspace((u_char
)*line
))
801 return FALSE
; /* not for us */
802 while (isspace((u_char
)*line
))
805 line
= Var_Subst(NULL
, line
, VAR_CMD
, 0);
806 Parse_Error(mtype
, "%s", line
);
809 if (mtype
== PARSE_FATAL
) {
810 /* Terminate immediately. */
817 *---------------------------------------------------------------------
819 * Link the parent node to its new child. Used in a Lst_ForEach by
820 * ParseDoDependency. If the specType isn't 'Not', the parent
821 * isn't linked as a parent of the child.
824 * pgnp The parent node
825 * cgpn The child node
831 * New elements are added to the parents list of cgn and the
832 * children list of cgn. the unmade field of pgn is updated
833 * to reflect the additional child.
834 *---------------------------------------------------------------------
837 ParseLinkSrc(void *pgnp
, void *cgnp
)
839 GNode
*pgn
= (GNode
*)pgnp
;
840 GNode
*cgn
= (GNode
*)cgnp
;
842 if ((pgn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (pgn
->cohorts
))
843 pgn
= (GNode
*)Lst_Datum(Lst_Last(pgn
->cohorts
));
844 (void)Lst_AtEnd(pgn
->children
, cgn
);
846 (void)Lst_AtEnd(cgn
->parents
, pgn
);
849 fprintf(debug_file
, "# %s: added child %s - %s\n", __func__
,
850 pgn
->name
, cgn
->name
);
851 Targ_PrintNode(pgn
, 0);
852 Targ_PrintNode(cgn
, 0);
858 *---------------------------------------------------------------------
860 * Apply the parsed operator to the given target node. Used in a
861 * Lst_ForEach call by ParseDoDependency once all targets have
862 * been found and their operator parsed. If the previous and new
863 * operators are incompatible, a major error is taken.
866 * gnp The node to which the operator is to be applied
867 * opp The operator to apply
873 * The type field of the node is altered to reflect any new bits in
875 *---------------------------------------------------------------------
878 ParseDoOp(void *gnp
, void *opp
)
880 GNode
*gn
= (GNode
*)gnp
;
881 int op
= *(int *)opp
;
883 * If the dependency mask of the operator and the node don't match and
884 * the node has actually had an operator applied to it before, and
885 * the operator actually has some dependency information in it, complain.
887 if (((op
& OP_OPMASK
) != (gn
->type
& OP_OPMASK
)) &&
888 !OP_NOP(gn
->type
) && !OP_NOP(op
))
890 Parse_Error(PARSE_FATAL
, "Inconsistent operator for %s", gn
->name
);
894 if ((op
== OP_DOUBLEDEP
) && ((gn
->type
& OP_OPMASK
) == OP_DOUBLEDEP
)) {
896 * If the node was the object of a :: operator, we need to create a
897 * new instance of it for the children and commands on this dependency
898 * line. The new instance is placed on the 'cohorts' list of the
899 * initial one (note the initial one is not on its own cohorts list)
900 * and the new instance is linked to all parents of the initial
906 * Propagate copied bits to the initial node. They'll be propagated
907 * back to the rest of the cohorts later.
909 gn
->type
|= op
& ~OP_OPMASK
;
911 cohort
= Targ_FindNode(gn
->name
, TARG_NOHASH
);
915 * Make the cohort invisible as well to avoid duplicating it into
916 * other variables. True, parents of this target won't tend to do
917 * anything with their local variables, but better safe than
918 * sorry. (I think this is pointless now, since the relevant list
919 * traversals will no longer see this node anyway. -mycroft)
921 cohort
->type
= op
| OP_INVISIBLE
;
922 (void)Lst_AtEnd(gn
->cohorts
, cohort
);
923 cohort
->centurion
= gn
;
924 gn
->unmade_cohorts
+= 1;
925 snprintf(cohort
->cohort_num
, sizeof cohort
->cohort_num
, "#%d",
929 * We don't want to nuke any previous flags (whatever they were) so we
930 * just OR the new operator into the old
939 *---------------------------------------------------------------------
941 * Given the name of a source, figure out if it is an attribute
942 * and apply it to the targets if it is. Else decide if there is
943 * some attribute which should be applied *to* the source because
944 * of some special target and apply it if so. Otherwise, make the
945 * source be a child of the targets in the list 'targets'
948 * tOp operator (if any) from special targets
949 * src name of the source to handle
955 * Operator bits may be added to the list of targets or to the source.
956 * The targets may have a new source added to their lists of children.
957 *---------------------------------------------------------------------
960 ParseDoSrc(int tOp
, const char *src
)
963 static int wait_number
= 0;
966 if (*src
== '.' && isupper ((unsigned char)src
[1])) {
967 int keywd
= ParseFindKeyword(src
);
969 int op
= parseKeywords
[keywd
].op
;
971 Lst_ForEach(targets
, ParseDoOp
, &op
);
974 if (parseKeywords
[keywd
].spec
== Wait
) {
976 * We add a .WAIT node in the dependency list.
977 * After any dynamic dependencies (and filename globbing)
978 * have happened, it is given a dependency on the each
979 * previous child back to and previous .WAIT node.
980 * The next child won't be scheduled until the .WAIT node
982 * We give each .WAIT node a unique name (mainly for diag).
984 snprintf(wait_src
, sizeof wait_src
, ".WAIT_%u", ++wait_number
);
985 gn
= Targ_FindNode(wait_src
, TARG_NOHASH
);
988 gn
->type
= OP_WAIT
| OP_PHONY
| OP_DEPENDS
| OP_NOTMAIN
;
989 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
998 * If we have noted the existence of a .MAIN, it means we need
999 * to add the sources of said target to the list of things
1000 * to create. The string 'src' is likely to be free, so we
1001 * must make a new copy of it. Note that this will only be
1002 * invoked if the user didn't specify a target on the command
1003 * line. This is to allow #ifmake's to succeed, or something...
1005 (void)Lst_AtEnd(create
, bmake_strdup(src
));
1007 * Add the name to the .TARGETS variable as well, so the user can
1008 * employ that, if desired.
1010 Var_Append(".TARGETS", src
, VAR_GLOBAL
);
1015 * Create proper predecessor/successor links between the previous
1016 * source and the current one.
1018 gn
= Targ_FindNode(src
, TARG_CREATE
);
1021 if (predecessor
!= NULL
) {
1022 (void)Lst_AtEnd(predecessor
->order_succ
, gn
);
1023 (void)Lst_AtEnd(gn
->order_pred
, predecessor
);
1025 fprintf(debug_file
, "# %s: added Order dependency %s - %s\n",
1026 __func__
, predecessor
->name
, gn
->name
);
1027 Targ_PrintNode(predecessor
, 0);
1028 Targ_PrintNode(gn
, 0);
1032 * The current source now becomes the predecessor for the next one.
1039 * If the source is not an attribute, we need to find/create
1040 * a node for it. After that we can apply any operator to it
1041 * from a special target or link it to its parents, as
1044 * In the case of a source that was the object of a :: operator,
1045 * the attribute is applied to all of its instances (as kept in
1046 * the 'cohorts' list of the node) or all the cohorts are linked
1047 * to all the targets.
1050 /* Find/create the 'src' node and attach to all targets */
1051 gn
= Targ_FindNode(src
, TARG_CREATE
);
1057 Lst_ForEach(targets
, ParseLinkSrc
, gn
);
1064 *-----------------------------------------------------------------------
1066 * Find a real target in the list and set it to be the main one.
1067 * Called by ParseDoDependency when a main target hasn't been found
1071 * gnp Node to examine
1074 * 0 if main not found yet, 1 if it is.
1077 * mainNode is changed and Targ_SetMain is called.
1079 *-----------------------------------------------------------------------
1082 ParseFindMain(void *gnp
, void *dummy
)
1084 GNode
*gn
= (GNode
*)gnp
;
1085 if ((gn
->type
& OP_NOTARGET
) == 0) {
1088 return (dummy
? 1 : 1);
1090 return (dummy
? 0 : 0);
1095 *-----------------------------------------------------------------------
1097 * Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
1105 *-----------------------------------------------------------------------
1108 ParseAddDir(void *path
, void *name
)
1110 (void)Dir_AddDir((Lst
) path
, (char *)name
);
1115 *-----------------------------------------------------------------------
1117 * Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
1125 *-----------------------------------------------------------------------
1128 ParseClearPath(void *path
, void *dummy
)
1130 Dir_ClearPath((Lst
) path
);
1131 return(dummy
? 0 : 0);
1135 *---------------------------------------------------------------------
1136 * ParseDoDependency --
1137 * Parse the dependency line in line.
1140 * line the line to parse
1146 * The nodes of the sources are linked as children to the nodes of the
1147 * targets. Some nodes may be created.
1149 * We parse a dependency line by first extracting words from the line and
1150 * finding nodes in the list of all targets with that name. This is done
1151 * until a character is encountered which is an operator character. Currently
1152 * these are only ! and :. At this point the operator is parsed and the
1153 * pointer into the line advanced until the first source is encountered.
1154 * The parsed operator is applied to each node in the 'targets' list,
1155 * which is where the nodes found for the targets are kept, by means of
1156 * the ParseDoOp function.
1157 * The sources are read in much the same way as the targets were except
1158 * that now they are expanded using the wildcarding scheme of the C-Shell
1159 * and all instances of the resulting words in the list of all targets
1160 * are found. Each of the resulting nodes is then linked to each of the
1161 * targets as one of its children.
1162 * Certain targets are handled specially. These are the ones detailed
1163 * by the specType variable.
1164 * The storing of transformation rules is also taken care of here.
1165 * A target is recognized as a transformation rule by calling
1166 * Suff_IsTransform. If it is a transformation rule, its node is gotten
1167 * from the suffix module via Suff_AddTransform rather than the standard
1168 * Targ_FindNode in the target module.
1169 *---------------------------------------------------------------------
1172 ParseDoDependency(char *line
)
1174 char *cp
; /* our current position */
1175 GNode
*gn
= NULL
; /* a general purpose temporary node */
1176 int op
; /* the operator on the line */
1177 char savec
; /* a place to save a character */
1178 Lst paths
; /* List of search paths to alter when parsing
1179 * a list of .PATH targets */
1180 int tOp
; /* operator from special target */
1181 Lst sources
; /* list of archive source names after
1183 Lst curTargs
; /* list of target names to be found and added
1184 * to the targets list */
1185 char *lstart
= line
;
1188 fprintf(debug_file
, "ParseDoDependency(%s)\n", line
);
1194 curTargs
= Lst_Init(FALSE
);
1197 * First, grind through the targets.
1202 * Here LINE points to the beginning of the next word, and
1203 * LSTART points to the actual beginning of the line.
1206 /* Find the end of the next word. */
1207 for (cp
= line
; *cp
&& (ParseIsEscaped(lstart
, cp
) ||
1208 !(isspace((unsigned char)*cp
) ||
1209 *cp
== '!' || *cp
== ':' || *cp
== LPAREN
));
1213 * Must be a dynamic source (would have been expanded
1214 * otherwise), so call the Var module to parse the puppy
1215 * so we can safely advance beyond it...There should be
1216 * no errors in this, as they would have been discovered
1217 * in the initial Var_Subst and we wouldn't be here.
1222 (void)Var_Parse(cp
, VAR_CMD
, TRUE
, &length
, &freeIt
);
1230 * If the word is followed by a left parenthesis, it's the
1231 * name of an object file inside an archive (ar file).
1233 if (!ParseIsEscaped(lstart
, cp
) && *cp
== LPAREN
) {
1235 * Archives must be handled specially to make sure the OP_ARCHV
1236 * flag is set in their 'type' field, for one thing, and because
1237 * things like "archive(file1.o file2.o file3.o)" are permissible.
1238 * Arch_ParseArchive will set 'line' to be the first non-blank
1239 * after the archive-spec. It creates/finds nodes for the members
1240 * and places them on the given list, returning SUCCESS if all
1241 * went well and FAILURE if there was an error in the
1242 * specification. On error, line should remain untouched.
1244 if (Arch_ParseArchive(&line
, targets
, VAR_CMD
) != SUCCESS
) {
1245 Parse_Error(PARSE_FATAL
,
1246 "Error in archive specification: \"%s\"", line
);
1249 /* Done with this word; on to the next. */
1256 * We got to the end of the line while we were still
1257 * looking at targets.
1259 * Ending a dependency line without an operator is a Bozo
1260 * no-no. As a heuristic, this is also often triggered by
1261 * undetected conflicts from cvs/rcs merges.
1263 if ((strncmp(line
, "<<<<<<", 6) == 0) ||
1264 (strncmp(line
, "======", 6) == 0) ||
1265 (strncmp(line
, ">>>>>>", 6) == 0))
1266 Parse_Error(PARSE_FATAL
,
1267 "Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
1269 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1270 : "Need an operator");
1274 /* Insert a null terminator. */
1279 * Got the word. See if it's a special target and if so set
1280 * specType to match it.
1282 if (*line
== '.' && isupper ((unsigned char)line
[1])) {
1284 * See if the target is a special target that must have it
1285 * or its sources handled specially.
1287 int keywd
= ParseFindKeyword(line
);
1289 if (specType
== ExPath
&& parseKeywords
[keywd
].spec
!= ExPath
) {
1290 Parse_Error(PARSE_FATAL
, "Mismatched special targets");
1294 specType
= parseKeywords
[keywd
].spec
;
1295 tOp
= parseKeywords
[keywd
].op
;
1298 * Certain special targets have special semantics:
1299 * .PATH Have to set the dirSearchPath
1301 * .MAIN Its sources are only used if
1302 * nothing has been specified to
1304 * .DEFAULT Need to create a node to hang
1305 * commands on, but we don't want
1306 * it in the graph, nor do we want
1307 * it to be the Main Target, so we
1308 * create it, set OP_NOTMAIN and
1309 * add it to the list, setting
1310 * DEFAULT to the new node for
1311 * later use. We claim the node is
1312 * A transformation rule to make
1313 * life easier later, when we'll
1314 * use Make_HandleUse to actually
1315 * apply the .DEFAULT commands.
1316 * .PHONY The list of targets
1317 * .NOPATH Don't search for file in the path
1322 * .INTERRUPT Are not to be considered the
1324 * .NOTPARALLEL Make only one target at a time.
1325 * .SINGLESHELL Create a shell for each command.
1326 * .ORDER Must set initial predecessor to NULL
1330 if (paths
== NULL
) {
1331 paths
= Lst_Init(FALSE
);
1333 (void)Lst_AtEnd(paths
, dirSearchPath
);
1336 if (!Lst_IsEmpty(create
)) {
1345 gn
= Targ_FindNode(line
, TARG_CREATE
);
1348 gn
->type
|= OP_NOTMAIN
|OP_SPECIAL
;
1349 (void)Lst_AtEnd(targets
, gn
);
1352 gn
= Targ_NewGN(".DEFAULT");
1353 gn
->type
|= (OP_NOTMAIN
|OP_TRANSFORM
);
1354 (void)Lst_AtEnd(targets
, gn
);
1369 } else if (strncmp(line
, ".PATH", 5) == 0) {
1371 * .PATH<suffix> has to be handled specially.
1372 * Call on the suffix module to give us a path to
1378 path
= Suff_GetPath(&line
[5]);
1380 Parse_Error(PARSE_FATAL
,
1381 "Suffix '%s' not defined (yet)",
1385 if (paths
== NULL
) {
1386 paths
= Lst_Init(FALSE
);
1388 (void)Lst_AtEnd(paths
, path
);
1394 * Have word in line. Get or create its node and stick it at
1395 * the end of the targets list
1397 if ((specType
== Not
) && (*line
!= '\0')) {
1398 if (Dir_HasWildcards(line
)) {
1400 * Targets are to be sought only in the current directory,
1401 * so create an empty path for the thing. Note we need to
1402 * use Dir_Destroy in the destruction of the path as the
1403 * Dir module could have added a directory to the path...
1405 Lst emptyPath
= Lst_Init(FALSE
);
1407 Dir_Expand(line
, emptyPath
, curTargs
);
1409 Lst_Destroy(emptyPath
, Dir_Destroy
);
1412 * No wildcards, but we want to avoid code duplication,
1413 * so create a list with the word on it.
1415 (void)Lst_AtEnd(curTargs
, line
);
1418 /* Apply the targets. */
1420 while(!Lst_IsEmpty(curTargs
)) {
1421 char *targName
= (char *)Lst_DeQueue(curTargs
);
1423 if (!Suff_IsTransform (targName
)) {
1424 gn
= Targ_FindNode(targName
, TARG_CREATE
);
1426 gn
= Suff_AddTransform(targName
);
1431 (void)Lst_AtEnd(targets
, gn
);
1433 } else if (specType
== ExPath
&& *line
!= '.' && *line
!= '\0') {
1434 Parse_Error(PARSE_WARNING
, "Extra target (%s) ignored", line
);
1437 /* Don't need the inserted null terminator any more. */
1441 * If it is a special type and not .PATH, it's the only target we
1442 * allow on this line...
1444 if (specType
!= Not
&& specType
!= ExPath
) {
1445 Boolean warning
= FALSE
;
1447 while (*cp
&& (ParseIsEscaped(lstart
, cp
) ||
1448 ((*cp
!= '!') && (*cp
!= ':')))) {
1449 if (ParseIsEscaped(lstart
, cp
) ||
1450 (*cp
!= ' ' && *cp
!= '\t')) {
1456 Parse_Error(PARSE_WARNING
, "Extra target ignored");
1459 while (*cp
&& isspace ((unsigned char)*cp
)) {
1464 } while (*line
&& (ParseIsEscaped(lstart
, line
) ||
1465 ((*line
!= '!') && (*line
!= ':'))));
1468 * Don't need the list of target names anymore...
1470 Lst_Destroy(curTargs
, NULL
);
1473 if (!Lst_IsEmpty(targets
)) {
1476 Parse_Error(PARSE_WARNING
, "Special and mundane targets don't mix. Mundane ones ignored");
1485 * These four create nodes on which to hang commands, so
1486 * targets shouldn't be empty...
1490 * Nothing special here -- targets can be empty if it wants.
1497 * Have now parsed all the target names. Must parse the operator next. The
1498 * result is left in op .
1502 } else if (*cp
== ':') {
1510 Parse_Error(PARSE_FATAL
, lstart
[0] == '.' ? "Unknown directive"
1511 : "Missing dependency operator");
1515 /* Advance beyond the operator */
1519 * Apply the operator to the target. This is how we remember which
1520 * operator a target was defined with. It fails if the operator
1521 * used isn't consistent across all references.
1523 Lst_ForEach(targets
, ParseDoOp
, &op
);
1526 * Onward to the sources.
1528 * LINE will now point to the first source word, if any, or the
1529 * end of the string if not.
1531 while (*cp
&& isspace ((unsigned char)*cp
)) {
1537 * Several special targets take different actions if present with no
1539 * a .SUFFIXES line with no sources clears out all old suffixes
1540 * a .PRECIOUS line makes all targets precious
1541 * a .IGNORE line ignores errors for all targets
1542 * a .SILENT line creates silence when making all targets
1543 * a .PATH removes all directories from the search path(s).
1548 Suff_ClearSuffixes();
1554 ignoreErrors
= TRUE
;
1560 Lst_ForEach(paths
, ParseClearPath
, NULL
);
1565 Var_Set("%POSIX", "1003.2", VAR_GLOBAL
, 0);
1571 } else if (specType
== MFlags
) {
1573 * Call on functions in main.c to deal with these arguments and
1574 * set the initial character to a null-character so the loop to
1575 * get sources won't get anything
1577 Main_ParseArgLine(line
);
1579 } else if (specType
== ExShell
) {
1580 if (Job_ParseShell(line
) != SUCCESS
) {
1581 Parse_Error(PARSE_FATAL
, "improper shell specification");
1585 } else if ((specType
== NotParallel
) || (specType
== SingleShell
)) {
1590 * NOW GO FOR THE SOURCES
1592 if ((specType
== Suffixes
) || (specType
== ExPath
) ||
1593 (specType
== Includes
) || (specType
== Libs
) ||
1594 (specType
== Null
) || (specType
== ExObjdir
))
1598 * If the target was one that doesn't take files as its sources
1599 * but takes something like suffixes, we take each
1600 * space-separated word on the line as a something and deal
1601 * with it accordingly.
1603 * If the target was .SUFFIXES, we take each source as a
1604 * suffix and add it to the list of suffixes maintained by the
1607 * If the target was a .PATH, we add the source as a directory
1608 * to search on the search path.
1610 * If it was .INCLUDES, the source is taken to be the suffix of
1611 * files which will be #included and whose search path should
1612 * be present in the .INCLUDES variable.
1614 * If it was .LIBS, the source is taken to be the suffix of
1615 * files which are considered libraries and whose search path
1616 * should be present in the .LIBS variable.
1618 * If it was .NULL, the source is the suffix to use when a file
1619 * has no valid suffix.
1621 * If it was .OBJDIR, the source is a new definition for .OBJDIR,
1622 * and will cause make to do a new chdir to that path.
1624 while (*cp
&& !isspace ((unsigned char)*cp
)) {
1631 Suff_AddSuffix(line
, &mainNode
);
1634 Lst_ForEach(paths
, ParseAddDir
, line
);
1637 Suff_AddInclude(line
);
1646 Main_SetObjdir(line
);
1652 if (savec
!= '\0') {
1655 while (*cp
&& isspace ((unsigned char)*cp
)) {
1661 Lst_Destroy(paths
, NULL
);
1663 if (specType
== ExPath
)
1668 * The targets take real sources, so we must beware of archive
1669 * specifications (i.e. things with left parentheses in them)
1670 * and handle them accordingly.
1672 for (; *cp
&& !isspace ((unsigned char)*cp
); cp
++) {
1673 if ((*cp
== LPAREN
) && (cp
> line
) && (cp
[-1] != '$')) {
1675 * Only stop for a left parenthesis if it isn't at the
1676 * start of a word (that'll be for variable changes
1677 * later) and isn't preceded by a dollar sign (a dynamic
1684 if (*cp
== LPAREN
) {
1685 sources
= Lst_Init(FALSE
);
1686 if (Arch_ParseArchive(&line
, sources
, VAR_CMD
) != SUCCESS
) {
1687 Parse_Error(PARSE_FATAL
,
1688 "Error in source archive spec \"%s\"", line
);
1692 while (!Lst_IsEmpty (sources
)) {
1693 gn
= (GNode
*)Lst_DeQueue(sources
);
1694 ParseDoSrc(tOp
, gn
->name
);
1696 Lst_Destroy(sources
, NULL
);
1704 ParseDoSrc(tOp
, line
);
1706 while (*cp
&& isspace ((unsigned char)*cp
)) {
1713 if (mainNode
== NULL
) {
1715 * If we have yet to decide on a main target to make, in the
1716 * absence of any user input, we want the first target on
1717 * the first dependency line that is actually a real target
1718 * (i.e. isn't a .USE or .EXEC rule) to be made.
1720 Lst_ForEach(targets
, ParseFindMain
, NULL
);
1725 Lst_Destroy(curTargs
, NULL
);
1729 *---------------------------------------------------------------------
1731 * Return TRUE if the passed line is a variable assignment. A variable
1732 * assignment consists of a single word followed by optional whitespace
1733 * followed by either a += or an = operator.
1734 * This function is used both by the Parse_File function and main when
1735 * parsing the command-line arguments.
1738 * line the line to check
1741 * TRUE if it is. FALSE if it ain't
1745 *---------------------------------------------------------------------
1748 Parse_IsVar(char *line
)
1750 Boolean wasSpace
= FALSE
; /* set TRUE if found a space */
1753 #define ISEQOPERATOR(c) \
1754 (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1757 * Skip to variable name
1759 for (;(*line
== ' ') || (*line
== '\t'); line
++)
1762 /* Scan for one of the assignment operators outside a variable expansion */
1763 while ((ch
= *line
++) != 0) {
1764 if (ch
== '(' || ch
== '{') {
1768 if (ch
== ')' || ch
== '}') {
1774 while (ch
== ' ' || ch
== '\t') {
1779 if (ch
== ':' && strncmp(line
, "sh", 2) == 0) {
1786 if (*line
== '=' && ISEQOPERATOR(ch
))
1796 *---------------------------------------------------------------------
1798 * Take the variable assignment in the passed line and do it in the
1801 * Note: There is a lexical ambiguity with assignment modifier characters
1802 * in variable names. This routine interprets the character before the =
1803 * as a modifier. Therefore, an assignment like
1805 * is interpreted as "C+ +=" instead of "C++ =".
1808 * line a line guaranteed to be a variable assignment.
1809 * This reduces error checks
1810 * ctxt Context in which to do the assignment
1816 * the variable structure of the given variable name is altered in the
1818 *---------------------------------------------------------------------
1821 Parse_DoVar(char *line
, GNode
*ctxt
)
1823 char *cp
; /* pointer into line */
1825 VAR_SUBST
, VAR_APPEND
, VAR_SHELL
, VAR_NORMAL
1826 } type
; /* Type of assignment */
1827 char *opc
; /* ptr to operator character to
1828 * null-terminate the variable name */
1829 Boolean freeCp
= FALSE
; /* TRUE if cp needs to be freed,
1830 * i.e. if any variable expansion was
1835 * Skip to variable name
1837 while ((*line
== ' ') || (*line
== '\t')) {
1842 * Skip to operator character, nulling out whitespace as we go
1843 * XXX Rather than counting () and {} we should look for $ and
1844 * then expand the variable.
1846 for (depth
= 0, cp
= line
+ 1; depth
!= 0 || *cp
!= '='; cp
++) {
1847 if (*cp
== '(' || *cp
== '{') {
1851 if (*cp
== ')' || *cp
== '}') {
1855 if (depth
== 0 && isspace ((unsigned char)*cp
)) {
1859 opc
= cp
-1; /* operator is the previous character */
1860 *cp
++ = '\0'; /* nuke the = */
1863 * Check operator type
1873 * If the variable already has a value, we don't do anything.
1876 if (Var_Exists(line
, ctxt
)) {
1895 while (opc
> line
&& *opc
!= ':')
1898 if (strncmp(opc
, ":sh", 3) == 0) {
1908 while (isspace ((unsigned char)*cp
)) {
1912 if (type
== VAR_APPEND
) {
1913 Var_Append(line
, cp
, ctxt
);
1914 } else if (type
== VAR_SUBST
) {
1916 * Allow variables in the old value to be undefined, but leave their
1917 * invocation alone -- this is done by forcing oldVars to be false.
1918 * XXX: This can cause recursive variables, but that's not hard to do,
1919 * and this allows someone to do something like
1921 * CFLAGS = $(.INCLUDES)
1922 * CFLAGS := -I.. $(CFLAGS)
1924 * And not get an error.
1926 Boolean oldOldVars
= oldVars
;
1931 * make sure that we set the variable the first time to nothing
1932 * so that it gets substituted!
1934 if (!Var_Exists(line
, ctxt
))
1935 Var_Set(line
, "", ctxt
, 0);
1937 cp
= Var_Subst(NULL
, cp
, ctxt
, FALSE
);
1938 oldVars
= oldOldVars
;
1941 Var_Set(line
, cp
, ctxt
, 0);
1942 } else if (type
== VAR_SHELL
) {
1946 if (strchr(cp
, '$') != NULL
) {
1948 * There's a dollar sign in the command, so perform variable
1949 * expansion on the whole thing. The resulting string will need
1950 * freeing when we're done, so set freeCmd to TRUE.
1952 cp
= Var_Subst(NULL
, cp
, VAR_CMD
, TRUE
);
1956 res
= Cmd_Exec(cp
, &error
);
1957 Var_Set(line
, res
, ctxt
, 0);
1961 Parse_Error(PARSE_WARNING
, error
, cp
);
1964 * Normal assignment -- just do it.
1966 Var_Set(line
, cp
, ctxt
, 0);
1968 if (strcmp(line
, MAKEOVERRIDES
) == 0)
1969 Main_ExportMAKEFLAGS(FALSE
); /* re-export MAKEFLAGS */
1970 else if (strcmp(line
, ".CURDIR") == 0) {
1972 * Somone is being (too?) clever...
1973 * Let's pretend they know what they are doing and
1974 * re-initialize the 'cur' Path.
1978 } else if (strcmp(line
, MAKE_JOB_PREFIX
) == 0) {
1980 } else if (strcmp(line
, MAKE_EXPORTED
) == 0) {
1989 * ParseMaybeSubMake --
1990 * Scan the command string to see if it a possible submake node
1992 * cmd the command to scan
1994 * TRUE if the command is possibly a submake, FALSE if not.
1997 ParseMaybeSubMake(const char *cmd
)
2004 #define MKV(A) { A, sizeof(A) - 1 }
2011 for (i
= 0; i
< sizeof(vals
)/sizeof(vals
[0]); i
++) {
2013 if ((ptr
= strstr(cmd
, vals
[i
].name
)) == NULL
)
2015 if ((ptr
== cmd
|| !isalnum((unsigned char)ptr
[-1]))
2016 && !isalnum((unsigned char)ptr
[vals
[i
].len
]))
2024 * Lst_ForEach function to add a command line to all targets
2027 * gnp the node to which the command is to be added
2028 * cmd the command to add
2034 * A new element is added to the commands list of the node,
2035 * and the node can be marked as a submake node if the command is
2036 * determined to be that.
2039 ParseAddCmd(void *gnp
, void *cmd
)
2041 GNode
*gn
= (GNode
*)gnp
;
2043 /* Add to last (ie current) cohort for :: targets */
2044 if ((gn
->type
& OP_DOUBLEDEP
) && !Lst_IsEmpty (gn
->cohorts
))
2045 gn
= (GNode
*)Lst_Datum(Lst_Last(gn
->cohorts
));
2047 /* if target already supplied, ignore commands */
2048 if (!(gn
->type
& OP_HAS_COMMANDS
)) {
2049 (void)Lst_AtEnd(gn
->commands
, cmd
);
2050 if (ParseMaybeSubMake(cmd
))
2051 gn
->type
|= OP_SUBMAKE
;
2055 /* XXX: We cannot do this until we fix the tree */
2056 (void)Lst_AtEnd(gn
->commands
, cmd
);
2057 Parse_Error(PARSE_WARNING
,
2058 "overriding commands for target \"%s\"; "
2059 "previous commands defined at %s: %d ignored",
2060 gn
->name
, gn
->fname
, gn
->lineno
);
2062 Parse_Error(PARSE_WARNING
,
2063 "duplicate script for target \"%s\" ignored",
2065 ParseErrorInternal(gn
->fname
, gn
->lineno
, PARSE_WARNING
,
2066 "using previous script for \"%s\" defined here",
2074 *-----------------------------------------------------------------------
2075 * ParseHasCommands --
2076 * Callback procedure for Parse_File when destroying the list of
2077 * targets on the last dependency line. Marks a target as already
2078 * having commands if it does, to keep from having shell commands
2079 * on multiple dependency lines.
2082 * gnp Node to examine
2088 * OP_HAS_COMMANDS may be set for the target.
2090 *-----------------------------------------------------------------------
2093 ParseHasCommands(void *gnp
)
2095 GNode
*gn
= (GNode
*)gnp
;
2096 if (!Lst_IsEmpty(gn
->commands
)) {
2097 gn
->type
|= OP_HAS_COMMANDS
;
2102 *-----------------------------------------------------------------------
2103 * Parse_AddIncludeDir --
2104 * Add a directory to the path searched for included makefiles
2105 * bracketed by double-quotes. Used by functions in main.c
2108 * dir The name of the directory to add
2114 * The directory is appended to the list.
2116 *-----------------------------------------------------------------------
2119 Parse_AddIncludeDir(char *dir
)
2121 (void)Dir_AddDir(parseIncPath
, dir
);
2125 *---------------------------------------------------------------------
2127 * Push to another file.
2129 * The input is the line minus the `.'. A file spec is a string
2130 * enclosed in <> or "". The former is looked for only in sysIncPath.
2131 * The latter in . and the directories specified by -I command line
2138 * A structure is added to the includes Lst and readProc, lineno,
2139 * fname and curFILE are altered for the new file
2140 *---------------------------------------------------------------------
2144 Parse_include_file(char *file
, Boolean isSystem
, int silent
)
2146 struct loadedfile
*lf
;
2147 char *fullname
; /* full pathname of file */
2149 char *prefEnd
, *incdir
;
2154 * Now we know the file's name and its search path, we attempt to
2155 * find the durn thing. A return of NULL indicates the file don't
2158 fullname
= file
[0] == '/' ? bmake_strdup(file
) : NULL
;
2160 if (fullname
== NULL
&& !isSystem
) {
2162 * Include files contained in double-quotes are first searched for
2163 * relative to the including file's location. We don't want to
2164 * cd there, of course, so we just tack on the old file's
2165 * leading path components and call Dir_FindFile to see if
2166 * we can locate the beast.
2169 incdir
= bmake_strdup(curFile
->fname
);
2170 prefEnd
= strrchr(incdir
, '/');
2171 if (prefEnd
!= NULL
) {
2173 /* Now do lexical processing of leading "../" on the filename */
2174 for (i
= 0; strncmp(file
+ i
, "../", 3) == 0; i
+= 3) {
2175 prefEnd
= strrchr(incdir
+ 1, '/');
2176 if (prefEnd
== NULL
|| strcmp(prefEnd
, "/..") == 0)
2180 newName
= str_concat(incdir
, file
+ i
, STR_ADDSLASH
);
2181 fullname
= Dir_FindFile(newName
, parseIncPath
);
2182 if (fullname
== NULL
)
2183 fullname
= Dir_FindFile(newName
, dirSearchPath
);
2188 if (fullname
== NULL
) {
2190 * Makefile wasn't found in same directory as included makefile.
2191 * Search for it first on the -I search path,
2192 * then on the .PATH search path, if not found in a -I directory.
2193 * If we have a suffix specific path we should use that.
2196 Lst suffPath
= NULL
;
2198 if ((suff
= strrchr(file
, '.'))) {
2199 suffPath
= Suff_GetPath(suff
);
2200 if (suffPath
!= NULL
) {
2201 fullname
= Dir_FindFile(file
, suffPath
);
2204 if (fullname
== NULL
) {
2205 fullname
= Dir_FindFile(file
, parseIncPath
);
2206 if (fullname
== NULL
) {
2207 fullname
= Dir_FindFile(file
, dirSearchPath
);
2213 /* Looking for a system file or file still not found */
2214 if (fullname
== NULL
) {
2216 * Look for it on the system path
2218 fullname
= Dir_FindFile(file
,
2219 Lst_IsEmpty(sysIncPath
) ? defIncPath
: sysIncPath
);
2222 if (fullname
== NULL
) {
2224 Parse_Error(PARSE_FATAL
, "Could not find %s", file
);
2228 /* Actually open the file... */
2229 fd
= open(fullname
, O_RDONLY
);
2232 Parse_Error(PARSE_FATAL
, "Cannot open %s", fullname
);
2238 lf
= loadfile(fullname
, fd
);
2240 ParseSetIncludedFile();
2241 /* Start reading from this file next */
2242 Parse_SetInput(fullname
, 0, -1, loadedfile_nextbuf
, lf
);
2247 ParseDoInclude(char *line
)
2249 char endc
; /* the character which ends the file spec */
2250 char *cp
; /* current position in file spec */
2251 int silent
= (*line
!= 'i') ? 1 : 0;
2252 char *file
= &line
[7 + silent
];
2254 /* Skip to delimiter character so we know where to look */
2255 while (*file
== ' ' || *file
== '\t')
2258 if (*file
!= '"' && *file
!= '<') {
2259 Parse_Error(PARSE_FATAL
,
2260 ".include filename must be delimited by '\"' or '<'");
2265 * Set the search path on which to find the include file based on the
2266 * characters which bracket its name. Angle-brackets imply it's
2267 * a system Makefile while double-quotes imply it's a user makefile
2275 /* Skip to matching delimiter */
2276 for (cp
= ++file
; *cp
&& *cp
!= endc
; cp
++)
2280 Parse_Error(PARSE_FATAL
,
2281 "Unclosed %cinclude filename. '%c' expected",
2288 * Substitute for any variables in the file name before trying to
2291 file
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2293 Parse_include_file(file
, endc
== '>', silent
);
2299 *---------------------------------------------------------------------
2300 * ParseSetIncludedFile --
2301 * Set the .INCLUDEDFROMFILE variable to the contents of .PARSEFILE
2302 * and the .INCLUDEDFROMDIR variable to the contents of .PARSEDIR
2308 * The .INCLUDEDFROMFILE variable is overwritten by the contents
2309 * of .PARSEFILE and the .INCLUDEDFROMDIR variable is overwriten
2310 * by the contents of .PARSEDIR
2311 *---------------------------------------------------------------------
2314 ParseSetIncludedFile(void)
2316 char *pf
, *fp
= NULL
;
2317 char *pd
, *dp
= NULL
;
2319 pf
= Var_Value(".PARSEFILE", VAR_GLOBAL
, &fp
);
2320 Var_Set(".INCLUDEDFROMFILE", pf
, VAR_GLOBAL
, 0);
2321 pd
= Var_Value(".PARSEDIR", VAR_GLOBAL
, &dp
);
2322 Var_Set(".INCLUDEDFROMDIR", pd
, VAR_GLOBAL
, 0);
2325 fprintf(debug_file
, "%s: ${.INCLUDEDFROMDIR} = `%s' "
2326 "${.INCLUDEDFROMFILE} = `%s'\n", __func__
, pd
, pf
);
2334 *---------------------------------------------------------------------
2335 * ParseSetParseFile --
2336 * Set the .PARSEDIR and .PARSEFILE variables to the dirname and
2337 * basename of the given filename
2343 * The .PARSEDIR and .PARSEFILE variables are overwritten by the
2344 * dirname and basename of the given filename.
2345 *---------------------------------------------------------------------
2348 ParseSetParseFile(const char *filename
)
2350 char *slash
, *dirname
;
2351 const char *pd
, *pf
;
2354 slash
= strrchr(filename
, '/');
2355 if (slash
== NULL
) {
2356 Var_Set(".PARSEDIR", pd
= curdir
, VAR_GLOBAL
, 0);
2357 Var_Set(".PARSEFILE", pf
= filename
, VAR_GLOBAL
, 0);
2360 len
= slash
- filename
;
2361 dirname
= bmake_malloc(len
+ 1);
2362 memcpy(dirname
, filename
, len
);
2363 dirname
[len
] = '\0';
2364 Var_Set(".PARSEDIR", pd
= dirname
, VAR_GLOBAL
, 0);
2365 Var_Set(".PARSEFILE", pf
= slash
+ 1, VAR_GLOBAL
, 0);
2368 fprintf(debug_file
, "%s: ${.PARSEDIR} = `%s' ${.PARSEFILE} = `%s'\n",
2374 * Track the makefiles we read - so makefiles can
2375 * set dependencies on them.
2376 * Avoid adding anything more than once.
2380 ParseTrackInput(const char *name
)
2384 size_t name_len
= strlen(name
);
2386 old
= Var_Value(MAKE_MAKEFILES
, VAR_GLOBAL
, &fp
);
2388 /* does it contain name? */
2389 for (; old
!= NULL
; old
= strchr(old
, ' ')) {
2392 if (memcmp(old
, name
, name_len
) == 0
2393 && (old
[name_len
] == 0 || old
[name_len
] == ' '))
2397 Var_Append (MAKE_MAKEFILES
, name
, VAR_GLOBAL
);
2406 *---------------------------------------------------------------------
2408 * Start Parsing from the given source
2414 * A structure is added to the includes Lst and readProc, lineno,
2415 * fname and curFile are altered for the new file
2416 *---------------------------------------------------------------------
2419 Parse_SetInput(const char *name
, int line
, int fd
,
2420 char *(*nextbuf
)(void *, size_t *), void *arg
)
2426 name
= curFile
->fname
;
2428 ParseTrackInput(name
);
2431 fprintf(debug_file
, "%s: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
2432 __func__
, name
, line
, fd
, nextbuf
, arg
);
2434 if (fd
== -1 && nextbuf
== NULL
)
2438 if (curFile
!= NULL
)
2439 /* Save exiting file info */
2440 Lst_AtFront(includes
, curFile
);
2442 /* Allocate and fill in new structure */
2443 curFile
= bmake_malloc(sizeof *curFile
);
2446 * Once the previous state has been saved, we can get down to reading
2447 * the new file. We set up the name of the file to be the absolute
2448 * name of the include file so error messages refer to the right
2451 curFile
->fname
= bmake_strdup(name
);
2452 curFile
->lineno
= line
;
2453 curFile
->first_lineno
= line
;
2454 curFile
->nextbuf
= nextbuf
;
2455 curFile
->nextbuf_arg
= arg
;
2458 assert(nextbuf
!= NULL
);
2460 /* Get first block of input data */
2461 buf
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2463 /* Was all a waste of time ... */
2465 free(curFile
->fname
);
2469 curFile
->P_str
= buf
;
2470 curFile
->P_ptr
= buf
;
2471 curFile
->P_end
= buf
+len
;
2473 curFile
->cond_depth
= Cond_save_depth();
2474 ParseSetParseFile(name
);
2479 *---------------------------------------------------------------------
2480 * ParseTraditionalInclude --
2481 * Push to another file.
2483 * The input is the current line. The file name(s) are
2484 * following the "include".
2490 * A structure is added to the includes Lst and readProc, lineno,
2491 * fname and curFILE are altered for the new file
2492 *---------------------------------------------------------------------
2495 ParseTraditionalInclude(char *line
)
2497 char *cp
; /* current position in file spec */
2499 int silent
= (line
[0] != 'i') ? 1 : 0;
2500 char *file
= &line
[silent
+ 7];
2504 fprintf(debug_file
, "%s: %s\n", __func__
, file
);
2508 * Skip over whitespace
2510 while (isspace((unsigned char)*file
))
2514 * Substitute for any variables in the file name before trying to
2517 all_files
= Var_Subst(NULL
, file
, VAR_CMD
, FALSE
);
2519 if (*file
== '\0') {
2520 Parse_Error(PARSE_FATAL
,
2521 "Filename missing from \"include\"");
2525 for (file
= all_files
; !done
; file
= cp
+ 1) {
2526 /* Skip to end of line or next whitespace */
2527 for (cp
= file
; *cp
&& !isspace((unsigned char) *cp
); cp
++)
2535 Parse_include_file(file
, FALSE
, silent
);
2543 *---------------------------------------------------------------------
2544 * ParseGmakeExport --
2545 * Parse export <variable>=<value>
2547 * And set the environment with it.
2554 *---------------------------------------------------------------------
2557 ParseGmakeExport(char *line
)
2559 char *variable
= &line
[6];
2563 fprintf(debug_file
, "%s: %s\n", __func__
, variable
);
2567 * Skip over whitespace
2569 while (isspace((unsigned char)*variable
))
2572 for (value
= variable
; *value
&& *value
!= '='; value
++)
2575 if (*value
!= '=') {
2576 Parse_Error(PARSE_FATAL
,
2577 "Variable/Value missing from \"export\"");
2580 *value
++ = '\0'; /* terminate variable */
2583 * Expand the value before putting it in the environment.
2585 value
= Var_Subst(NULL
, value
, VAR_CMD
, FALSE
);
2586 setenv(variable
, value
, 1);
2591 *---------------------------------------------------------------------
2593 * Called when EOF is reached in the current file. If we were reading
2594 * an include file, the includes stack is popped and things set up
2595 * to go back to reading the previous file at the previous location.
2598 * CONTINUE if there's more to do. DONE if not.
2601 * The old curFILE, is closed. The includes list is shortened.
2602 * lineno, curFILE, and fname are changed if CONTINUE is returned.
2603 *---------------------------------------------------------------------
2611 assert(curFile
->nextbuf
!= NULL
);
2613 /* get next input buffer, if any */
2614 ptr
= curFile
->nextbuf(curFile
->nextbuf_arg
, &len
);
2615 curFile
->P_ptr
= ptr
;
2616 curFile
->P_str
= ptr
;
2617 curFile
->P_end
= ptr
+ len
;
2618 curFile
->lineno
= curFile
->first_lineno
;
2624 /* Ensure the makefile (or loop) didn't have mismatched conditionals */
2625 Cond_restore_depth(curFile
->cond_depth
);
2627 if (curFile
->lf
!= NULL
) {
2628 loadedfile_destroy(curFile
->lf
);
2632 /* Dispose of curFile info */
2633 /* Leak curFile->fname because all the gnodes have pointers to it */
2634 free(curFile
->P_str
);
2637 curFile
= Lst_DeQueue(includes
);
2639 if (curFile
== NULL
) {
2640 /* We've run out of input */
2641 Var_Delete(".PARSEDIR", VAR_GLOBAL
);
2642 Var_Delete(".PARSEFILE", VAR_GLOBAL
);
2643 Var_Delete(".INCLUDEDFROMDIR", VAR_GLOBAL
);
2644 Var_Delete(".INCLUDEDFROMFILE", VAR_GLOBAL
);
2649 fprintf(debug_file
, "ParseEOF: returning to file %s, line %d\n",
2650 curFile
->fname
, curFile
->lineno
);
2652 /* Restore the PARSEDIR/PARSEFILE variables */
2653 ParseSetParseFile(curFile
->fname
);
2658 #define PARSE_SKIP 2
2661 ParseGetLine(int flags
, int *length
)
2663 IFile
*cf
= curFile
;
2672 /* Loop through blank lines and comment lines */
2681 if (cf
->P_end
!= NULL
&& ptr
== cf
->P_end
) {
2687 if (ch
== 0 || (ch
== '\\' && ptr
[1] == 0)) {
2688 if (cf
->P_end
== NULL
)
2689 /* End of string (aka for loop) data */
2691 /* see if there is more we can parse */
2692 while (ptr
++ < cf
->P_end
) {
2693 if ((ch
= *ptr
) == '\n') {
2694 if (ptr
> line
&& ptr
[-1] == '\\')
2696 Parse_Error(PARSE_WARNING
,
2697 "Zero byte read from file, skipping rest of line.");
2701 if (cf
->nextbuf
!= NULL
) {
2703 * End of this buffer; return EOF and outer logic
2704 * will get the next one. (eww)
2708 Parse_Error(PARSE_FATAL
, "Zero byte read from file");
2713 /* Don't treat next character as special, remember first one */
2714 if (escaped
== NULL
)
2722 if (ch
== '#' && comment
== NULL
) {
2723 /* Remember first '#' for comment stripping */
2724 /* Unless previous char was '[', as in modifier :[#] */
2725 if (!(ptr
> line
&& ptr
[-1] == '['))
2731 if (!isspace((unsigned char)ch
))
2732 /* We are not interested in trailing whitespace */
2736 /* Save next 'to be processed' location */
2739 /* Check we have a non-comment, non-blank line */
2740 if (line_end
== line
|| comment
== line
) {
2742 /* At end of file */
2744 /* Parse another line */
2748 /* We now have a line of data */
2751 if (flags
& PARSE_RAW
) {
2752 /* Leave '\' (etc) in line buffer (eg 'for' lines) */
2753 *length
= line_end
- line
;
2757 if (flags
& PARSE_SKIP
) {
2758 /* Completely ignore non-directives */
2761 /* We could do more of the .else/.elif/.endif checks here */
2766 /* Brutally ignore anything after a non-escaped '#' in non-commands */
2767 if (comment
!= NULL
&& line
[0] != '\t') {
2772 /* If we didn't see a '\\' then the in-situ data is fine */
2773 if (escaped
== NULL
) {
2774 *length
= line_end
- line
;
2778 /* Remove escapes from '\n' and '#' */
2781 for (; ; *tp
++ = ch
) {
2791 /* Delete '\\' at end of buffer */
2796 if (ch
== '#' && line
[0] != '\t')
2797 /* Delete '\\' from before '#' on non-command lines */
2801 /* Leave '\\' in buffer for later */
2803 /* Make sure we don't delete an escaped ' ' from the line end */
2808 /* Escaped '\n' replace following whitespace with a single ' ' */
2809 while (ptr
[0] == ' ' || ptr
[0] == '\t')
2814 /* Delete any trailing spaces - eg from empty continuations */
2815 while (tp
> escaped
&& isspace((unsigned char)tp
[-1]))
2819 *length
= tp
- line
;
2824 *---------------------------------------------------------------------
2826 * Read an entire line from the input file. Called only by Parse_File.
2829 * A line w/o its newline
2832 * Only those associated with reading a character
2833 *---------------------------------------------------------------------
2838 char *line
; /* Result */
2839 int lineLength
; /* Length of result */
2840 int lineno
; /* Saved line # */
2844 line
= ParseGetLine(0, &lineLength
);
2852 * The line might be a conditional. Ask the conditional module
2853 * about it and act accordingly
2855 switch (Cond_Eval(line
)) {
2857 /* Skip to next conditional that evaluates to COND_PARSE. */
2859 line
= ParseGetLine(PARSE_SKIP
, &lineLength
);
2860 } while (line
&& Cond_Eval(line
) != COND_PARSE
);
2866 case COND_INVALID
: /* Not a conditional line */
2867 /* Check for .for loops */
2868 rval
= For_Eval(line
);
2870 /* Not a .for line */
2873 /* Syntax error - error printed, ignore line */
2875 /* Start of a .for loop */
2876 lineno
= curFile
->lineno
;
2877 /* Accumulate loop lines until matching .endfor */
2879 line
= ParseGetLine(PARSE_RAW
, &lineLength
);
2881 Parse_Error(PARSE_FATAL
,
2882 "Unexpected end of file in for loop.");
2885 } while (For_Accum(line
));
2886 /* Stash each iteration as a new 'input file' */
2888 /* Read next line from for-loop buffer */
2896 *-----------------------------------------------------------------------
2897 * ParseFinishLine --
2898 * Handle the end of a dependency group.
2904 * inLine set FALSE. 'targets' list destroyed.
2906 *-----------------------------------------------------------------------
2909 ParseFinishLine(void)
2912 Lst_ForEach(targets
, Suff_EndTransform
, NULL
);
2913 Lst_Destroy(targets
, ParseHasCommands
);
2921 *---------------------------------------------------------------------
2923 * Parse a file into its component parts, incorporating it into the
2924 * current dependency graph. This is the main function and controls
2925 * almost every other function in this module
2928 * name the name of the file being read
2929 * fd Open file to makefile to parse
2936 * Loads. Nodes are added to the list of all targets, nodes and links
2937 * are added to the dependency graph. etc. etc. etc.
2938 *---------------------------------------------------------------------
2941 Parse_File(const char *name
, int fd
)
2943 char *cp
; /* pointer into the line */
2944 char *line
; /* the line we're working on */
2945 struct loadedfile
*lf
;
2947 lf
= loadfile(name
, fd
);
2956 Parse_SetInput(name
, 0, -1, loadedfile_nextbuf
, lf
);
2960 for (; (line
= ParseReadLine()) != NULL
; ) {
2962 fprintf(debug_file
, "ParseReadLine (%d): '%s'\n",
2963 curFile
->lineno
, line
);
2966 * Lines that begin with the special character may be
2967 * include or undef directives.
2968 * On the other hand they can be suffix rules (.c.o: ...)
2969 * or just dependencies for filenames that start '.'.
2971 for (cp
= line
+ 1; isspace((unsigned char)*cp
); cp
++) {
2974 if (strncmp(cp
, "include", 7) == 0 ||
2975 ((cp
[0] == 's' || cp
[0] == '-') &&
2976 strncmp(&cp
[1], "include", 7) == 0)) {
2980 if (strncmp(cp
, "undef", 5) == 0) {
2982 for (cp
+= 5; isspace((unsigned char) *cp
); cp
++)
2984 for (cp2
= cp
; !isspace((unsigned char) *cp2
) &&
2985 (*cp2
!= '\0'); cp2
++)
2988 Var_Delete(cp
, VAR_GLOBAL
);
2990 } else if (strncmp(cp
, "export", 6) == 0) {
2991 for (cp
+= 6; isspace((unsigned char) *cp
); cp
++)
2995 } else if (strncmp(cp
, "unexport", 8) == 0) {
2998 } else if (strncmp(cp
, "info", 4) == 0 ||
2999 strncmp(cp
, "error", 5) == 0 ||
3000 strncmp(cp
, "warning", 7) == 0) {
3001 if (ParseMessage(cp
))
3006 if (*line
== '\t') {
3008 * If a line starts with a tab, it can only hope to be
3009 * a creation command.
3013 for (; isspace ((unsigned char)*cp
); cp
++) {
3018 Parse_Error(PARSE_FATAL
,
3019 "Unassociated shell command \"%s\"",
3022 * So long as it's not a blank line and we're actually
3023 * in a dependency spec, add the command to the list of
3024 * commands of all targets in the dependency spec
3027 cp
= bmake_strdup(cp
);
3028 Lst_ForEach(targets
, ParseAddCmd
, cp
);
3030 Lst_AtEnd(targCmds
, cp
);
3038 if (((strncmp(line
, "include", 7) == 0 &&
3039 isspace((unsigned char) line
[7])) ||
3040 ((line
[0] == 's' || line
[0] == '-') &&
3041 strncmp(&line
[1], "include", 7) == 0 &&
3042 isspace((unsigned char) line
[8]))) &&
3043 strchr(line
, ':') == NULL
) {
3045 * It's an S3/S5-style "include".
3047 ParseTraditionalInclude(line
);
3052 if (strncmp(line
, "export", 6) == 0 &&
3053 isspace((unsigned char) line
[6]) &&
3054 strchr(line
, ':') == NULL
) {
3056 * It's a Gmake "export".
3058 ParseGmakeExport(line
);
3062 if (Parse_IsVar(line
)) {
3064 Parse_DoVar(line
, VAR_GLOBAL
);
3070 * To make life easier on novices, if the line is indented we
3071 * first make sure the line has a dependency operator in it.
3072 * If it doesn't have an operator and we're in a dependency
3073 * line's script, we assume it's actually a shell command
3074 * and add it to the current list of targets.
3077 if (isspace((unsigned char) line
[0])) {
3078 while ((*cp
!= '\0') && isspace((unsigned char) *cp
))
3080 while (*cp
&& (ParseIsEscaped(line
, cp
) ||
3081 (*cp
!= ':') && (*cp
!= '!'))) {
3086 Parse_Error(PARSE_WARNING
,
3087 "Shell command needs a leading tab");
3096 * For some reason - probably to make the parser impossible -
3097 * a ';' can be used to separate commands from dependencies.
3098 * Attempt to avoid ';' inside substitution patterns.
3103 for (cp
= line
; *cp
!= 0; cp
++) {
3104 if (*cp
== '\\' && cp
[1] != 0) {
3109 (cp
[1] == '(' || cp
[1] == '{')) {
3114 if (*cp
== ')' || *cp
== '}') {
3118 } else if (*cp
== ';') {
3124 /* Terminate the dependency list at the ';' */
3130 * We now know it's a dependency line so it needs to have all
3131 * variables expanded before being parsed. Tell the variable
3132 * module to complain if some variable is undefined...
3134 line
= Var_Subst(NULL
, line
, VAR_CMD
, TRUE
);
3137 * Need a non-circular list for the target nodes
3140 Lst_Destroy(targets
, NULL
);
3142 targets
= Lst_Init(FALSE
);
3145 ParseDoDependency(line
);
3148 /* If there were commands after a ';', add them now */
3154 * Reached EOF, but it may be just EOF of an include file...
3156 } while (ParseEOF() == CONTINUE
);
3159 (void)fflush(stdout
);
3160 (void)fprintf(stderr
,
3161 "%s: Fatal errors encountered -- cannot continue",
3163 PrintOnError(NULL
, NULL
);
3169 *---------------------------------------------------------------------
3171 * initialize the parsing module
3177 * the parseIncPath list is initialized...
3178 *---------------------------------------------------------------------
3184 parseIncPath
= Lst_Init(FALSE
);
3185 sysIncPath
= Lst_Init(FALSE
);
3186 defIncPath
= Lst_Init(FALSE
);
3187 includes
= Lst_Init(FALSE
);
3189 targCmds
= Lst_Init(FALSE
);
3197 Lst_Destroy(targCmds
, (FreeProc
*)free
);
3199 Lst_Destroy(targets
, NULL
);
3200 Lst_Destroy(defIncPath
, Dir_Destroy
);
3201 Lst_Destroy(sysIncPath
, Dir_Destroy
);
3202 Lst_Destroy(parseIncPath
, Dir_Destroy
);
3203 Lst_Destroy(includes
, NULL
); /* Should be empty now */
3209 *-----------------------------------------------------------------------
3211 * Return a Lst of the main target to create for main()'s sake. If
3212 * no such target exists, we Punt with an obnoxious error message.
3215 * A Lst of the single node to create.
3220 *-----------------------------------------------------------------------
3223 Parse_MainName(void)
3225 Lst mainList
; /* result list */
3227 mainList
= Lst_Init(FALSE
);
3229 if (mainNode
== NULL
) {
3230 Punt("no target to make.");
3232 } else if (mainNode
->type
& OP_DOUBLEDEP
) {
3233 (void)Lst_AtEnd(mainList
, mainNode
);
3234 Lst_Concat(mainList
, mainNode
->cohorts
, LST_CONCNEW
);
3237 (void)Lst_AtEnd(mainList
, mainNode
);
3238 Var_Append(".TARGETS", mainNode
->name
, VAR_GLOBAL
);
3243 *-----------------------------------------------------------------------
3245 * Add the filename and lineno to the GNode so that we remember
3246 * where it was first defined.
3251 *-----------------------------------------------------------------------
3254 ParseMark(GNode
*gn
)
3256 gn
->fname
= curFile
->fname
;
3257 gn
->lineno
= curFile
->lineno
;