2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1989 by Berkeley Softworks
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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)parse.c 8.3 (Berkeley) 3/19/94
39 * $FreeBSD: src/usr.bin/make/parse.c,v 1.75 2005/02/07 11:27:47 harti Exp $
40 * $DragonFly: src/usr.bin/make/parse.c,v 1.62 2005/04/01 00:32:03 okumoto Exp $
45 * Functions to parse a makefile.
47 * One function, Parse_Init, must be called before any functions
48 * in this module are used. After that, the function Parse_File is the
49 * main entry point and controls most of the other functions in this
52 * Most important structures are kept in Lsts. Directories for
53 * the #include "..." function are kept in the 'parseIncPath' Lst, while
54 * those for the #include <...> are kept in the 'sysIncPath' Lst. The
55 * targets currently being defined are kept in the 'targets' Lst.
57 * The variables 'curFile.fname' and 'curFile.lineno' are used to track
58 * the name of the current file and the line number in that file so that
59 * error messages can be more meaningful.
62 * Parse_Init Initialization function which must be
63 * called before anything else in this module is used.
65 * Parse_File Function used to parse a makefile. It must
66 * be given the name of the file, which should
67 * already have been opened, and a function
68 * to call to read a character from the file.
70 * Parse_IsVar Returns TRUE if the given line is a
71 * variable assignment. Used by MainParseArgs
72 * to determine if an argument is a target
73 * or a variable assignment. Used internally
74 * for pretty much the same thing...
76 * Parse_Error Function called when an error occurs in
77 * parsing. Used by the variable and
78 * conditional modules.
80 * Parse_MainName Returns a Lst of the main target to create.
101 #include "pathnames.h"
109 * These values are returned by ParseEOF to tell Parse_File whether to
110 * CONTINUE parsing, i.e. it had only reached the end of an include file,
116 /* targets we're working on */
117 static Lst targets = Lst_Initializer(targets);
119 /* true if currently in a dependency line or its commands */
120 static Boolean inLine;
122 static int fatals = 0;
125 * The main target to create. This is the first target on the
126 * first dependency line in the first makefile.
128 static GNode *mainNode;
130 IFile curFile; /* current makefile */
132 /* stack of IFiles generated by * #includes */
133 static Lst includes = Lst_Initializer(includes);
135 /* list of directories for "..." includes */
136 struct Path parseIncPath = TAILQ_HEAD_INITIALIZER(parseIncPath);
138 /* list of directories for <...> includes */
139 struct Path sysIncPath = TAILQ_HEAD_INITIALIZER(sysIncPath);
142 * specType contains the SPECial TYPE of the current target. It is
143 * Not if the target is unspecial. If it *is* special, however, the children
144 * are linked as children of the parent but not vice versa. This variable is
145 * set in ParseDoDependency
149 Default, /* .DEFAULT */
151 Ignore, /* .IGNORE */
152 Includes, /* .INCLUDES */
153 Interrupt, /* .INTERRUPT */
155 MFlags, /* .MFLAGS or .MAKEFLAGS */
156 Main, /* .MAIN and we don't have anyth. user-spec. to make */
157 NoExport, /* .NOEXPORT */
158 Not, /* Not special */
159 NotParallel, /* .NOTPARALELL */
162 Parallel, /* .PARALLEL */
166 Precious, /* .PRECIOUS */
167 ExShell, /* .SHELL */
168 Silent, /* .SILENT */
169 SingleShell, /* .SINGLESHELL */
170 Suffixes, /* .SUFFIXES */
172 Attribute /* Generic attribute */
175 static ParseSpecial specType;
179 * Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
180 * seen, then set to each successive source on the line.
182 static GNode *predecessor;
185 * The parseKeywords table is searched using binary search when deciding
186 * if a target or source is special. The 'spec' field is the ParseSpecial
187 * type of the keyword ("Not" if the keyword isn't special as a target) while
188 * the 'op' field is the operator to apply to the list of targets if the
189 * keyword is used as a source ("0" if the keyword isn't special as a source)
192 const char *name; /* Name of keyword */
193 ParseSpecial spec; /* Type when used as a target */
194 int op; /* Operator when used as a source */
195 } parseKeywords[] = {
196 { ".BEGIN", Begin, 0 },
197 { ".DEFAULT", Default, 0 },
199 { ".EXEC", Attribute, OP_EXEC },
200 { ".IGNORE", Ignore, OP_IGNORE },
201 { ".INCLUDES", Includes, 0 },
202 { ".INTERRUPT", Interrupt, 0 },
203 { ".INVISIBLE", Attribute, OP_INVISIBLE },
204 { ".JOIN", Attribute, OP_JOIN },
205 { ".LIBS", Libs, 0 },
206 { ".MAIN", Main, 0 },
207 { ".MAKE", Attribute, OP_MAKE },
208 { ".MAKEFLAGS", MFlags, 0 },
209 { ".MFLAGS", MFlags, 0 },
210 { ".NOTMAIN", Attribute, OP_NOTMAIN },
211 { ".NOTPARALLEL", NotParallel, 0 },
212 { ".NO_PARALLEL", NotParallel, 0 },
213 { ".NULL", Null, 0 },
214 { ".OPTIONAL", Attribute, OP_OPTIONAL },
215 { ".ORDER", Order, 0 },
216 { ".PARALLEL", Parallel, 0 },
217 { ".PATH", ExPath, 0 },
218 { ".PHONY", Phony, OP_PHONY },
219 { ".POSIX", Posix, 0 },
220 { ".PRECIOUS", Precious, OP_PRECIOUS },
221 { ".RECURSIVE", Attribute, OP_MAKE },
222 { ".SHELL", ExShell, 0 },
223 { ".SILENT", Silent, OP_SILENT },
224 { ".SINGLESHELL", SingleShell, 0 },
225 { ".SUFFIXES", Suffixes, 0 },
226 { ".USE", Attribute, OP_USE },
227 { ".WAIT", Wait, 0 },
230 static int ParseEOF(int);
233 *----------------------------------------------------------------------
234 * ParseFindKeyword --
235 * Look in the table of keywords for one matching the given string.
238 * The index of the keyword, or -1 if it isn't there.
242 *----------------------------------------------------------------------
245 ParseFindKeyword(char *str)
253 end = (sizeof(parseKeywords) / sizeof(parseKeywords[0])) - 1;
256 cur = start + (end - start) / 2;
257 diff = strcmp(str, parseKeywords[cur].name);
260 } else if (diff < 0) {
265 } while (start <= end);
272 * Error message abort function for parsing. Prints out the context
273 * of the error (line number and file) as well as the message with
274 * two optional arguments.
280 * "fatals" is incremented if the level is PARSE_FATAL.
284 Parse_Error(int type, const char *fmt, ...)
289 fprintf(stderr, "\"%s\", line %d: ",
290 curFile.fname, curFile.lineno);
291 if (type == PARSE_WARNING)
292 fprintf(stderr, "warning: ");
293 vfprintf(stderr, fmt, ap);
295 fprintf(stderr, "\n");
297 if (type == PARSE_FATAL)
302 *---------------------------------------------------------------------
304 * Link the parent nodes to their new child. Used by
305 * ParseDoDependency. If the specType isn't 'Not', the parent
306 * isn't linked as a parent of the child.
309 * New elements are added to the parents lists of cgn and the
310 * children list of cgn. the unmade field of pgn is updated
311 * to reflect the additional child.
312 *---------------------------------------------------------------------
315 ParseLinkSrc(Lst *parents, GNode *cgn)
320 LST_FOREACH(ln, parents) {
322 if (Lst_Member(&pgn->children, cgn) == NULL) {
323 Lst_AtEnd(&pgn->children, cgn);
324 if (specType == Not) {
325 Lst_AtEnd(&cgn->parents, pgn);
333 *---------------------------------------------------------------------
335 * Apply the parsed operator to all target nodes. Used in
336 * ParseDoDependency once all targets have been found and their
337 * operator parsed. If the previous and new operators are incompatible,
338 * a major error is taken.
341 * The type field of the node is altered to reflect any new bits in
343 *---------------------------------------------------------------------
352 LST_FOREACH(ln, &targets) {
356 * If the dependency mask of the operator and the node don't
357 * match and the node has actually had an operator applied to
358 * it before, and the operator actually has some dependency
359 * information in it, complain.
361 if ((op & OP_OPMASK) != (gn->type & OP_OPMASK) &&
362 !OP_NOP(gn->type) && !OP_NOP(op)) {
363 Parse_Error(PARSE_FATAL, "Inconsistent operator for %s",
368 if (op == OP_DOUBLEDEP &&
369 (gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
371 * If the node was the object of a :: operator, we need
372 * to create a new instance of it for the children and
373 * commands on this dependency line. The new instance
374 * is placed on the 'cohorts' list of the initial one
375 * (note the initial one is not on its own cohorts list)
376 * and the new instance is linked to all parents of the
379 cohort = Targ_NewGN(gn->name);
382 * Duplicate links to parents so graph traversal is
383 * simple. Perhaps some type bits should be duplicated?
385 * Make the cohort invisible as well to avoid
386 * duplicating it into other variables. True, parents
387 * of this target won't tend to do anything with their
388 * local variables, but better safe than sorry.
390 ParseLinkSrc(&gn->parents, cohort);
391 cohort->type = OP_DOUBLEDEP|OP_INVISIBLE;
392 Lst_AtEnd(&gn->cohorts, cohort);
395 * Replace the node in the targets list with the
398 Lst_Replace(ln, cohort);
402 * We don't want to nuke any previous flags (whatever they were)
403 * so we just OR the new operator into the old
410 *---------------------------------------------------------------------
412 * Given the name of a source, figure out if it is an attribute
413 * and apply it to the targets if it is. Else decide if there is
414 * some attribute which should be applied *to* the source because
415 * of some special target and apply it if so. Otherwise, make the
416 * source be a child of the targets in the list 'targets'
422 * Operator bits may be added to the list of targets or to the source.
423 * The targets may have a new source added to their lists of children.
424 *---------------------------------------------------------------------
427 ParseDoSrc(int tOp, char *src, Lst *allsrc)
431 if (*src == '.' && isupper ((unsigned char) src[1])) {
432 int keywd = ParseFindKeyword(src);
434 if(parseKeywords[keywd].op != 0) {
435 ParseDoOp(parseKeywords[keywd].op);
438 if (parseKeywords[keywd].spec == Wait) {
448 * If we have noted the existence of a .MAIN, it means we need
449 * to add the sources of said target to the list of things
450 * to create. The string 'src' is likely to be free, so we
451 * must make a new copy of it. Note that this will only be
452 * invoked if the user didn't specify a target on the command
453 * line. This is to allow #ifmake's to succeed, or something...
455 Lst_AtEnd(&create, estrdup(src));
457 * Add the name to the .TARGETS variable as well, so the user
458 * can employ that, if desired.
460 Var_Append(".TARGETS", src, VAR_GLOBAL);
465 * Create proper predecessor/successor links between the
466 * previous source and the current one.
468 gn = Targ_FindNode(src, TARG_CREATE);
469 if (predecessor != NULL) {
470 Lst_AtEnd(&predecessor->successors, gn);
471 Lst_AtEnd(&gn->preds, predecessor);
474 * The current source now becomes the predecessor for the next
482 * If the source is not an attribute, we need to find/create
483 * a node for it. After that we can apply any operator to it
484 * from a special target or link it to its parents, as
487 * In the case of a source that was the object of a :: operator,
488 * the attribute is applied to all of its instances (as kept in
489 * the 'cohorts' list of the node) or all the cohorts are linked
490 * to all the targets.
492 gn = Targ_FindNode(src, TARG_CREATE);
496 ParseLinkSrc(&targets, gn);
498 if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
502 for (ln = Lst_First(&gn->cohorts); ln != NULL;
504 cohort = Lst_Datum(ln);
508 ParseLinkSrc(&targets, cohort);
516 Lst_AtEnd(allsrc, gn);
522 * Check if GNodes needs to be synchronized.
523 * This has to be when two nodes are on different sides of a
526 LST_FOREACH(ln, allsrc) {
529 if (p->order >= gn->order)
532 * XXX: This can cause loops, and loops can cause
533 * unmade targets, but checking is tedious, and the
534 * debugging output can show the problem
536 Lst_AtEnd(&p->successors, gn);
537 Lst_AtEnd(&gn->preds, p);
543 stripvarname(char *cp)
547 while (isspace((unsigned char)*cp))
550 while (*cp2 && !isspace((unsigned char)*cp2))
558 *---------------------------------------------------------------------
559 * ParseDoDependency --
560 * Parse the dependency line in line.
566 * The nodes of the sources are linked as children to the nodes of the
567 * targets. Some nodes may be created.
569 * We parse a dependency line by first extracting words from the line and
570 * finding nodes in the list of all targets with that name. This is done
571 * until a character is encountered which is an operator character. Currently
572 * these are only ! and :. At this point the operator is parsed and the
573 * pointer into the line advanced until the first source is encountered.
574 * The parsed operator is applied to each node in the 'targets' list,
575 * which is where the nodes found for the targets are kept, by means of
576 * the ParseDoOp function.
577 * The sources are read in much the same way as the targets were except
578 * that now they are expanded using the wildcarding scheme of the C-Shell
579 * and all instances of the resulting words in the list of all targets
580 * are found. Each of the resulting nodes is then linked to each of the
581 * targets as one of its children.
582 * Certain targets are handled specially. These are the ones detailed
583 * by the specType variable.
584 * The storing of transformation rules is also taken care of here.
585 * A target is recognized as a transformation rule by calling
586 * Suff_IsTransform. If it is a transformation rule, its node is gotten
587 * from the suffix module via Suff_AddTransform rather than the standard
588 * Targ_FindNode in the target module.
589 *---------------------------------------------------------------------
592 ParseDoDependency(char *line)
594 char *cp; /* our current position */
595 GNode *gn; /* a general purpose temporary node */
596 int op; /* the operator on the line */
597 char savec; /* a place to save a character */
598 Lst paths; /* Search paths to alter when parsing .PATH targets */
599 int tOp; /* operator from special target */
610 *cp && !isspace((unsigned char)*cp) && *cp != '(';
614 * Must be a dynamic source (would have been
615 * expanded otherwise), so call the Var module
616 * to parse the puppy so we can safely advance
617 * beyond it...There should be no errors in this
618 * as they would have been discovered in the
619 * initial Var_Subst and we wouldn't be here.
625 result = Var_Parse(cp, VAR_CMD, TRUE,
633 } else if (*cp == '!' || *cp == ':') {
635 * We don't want to end a word on ':' or '!' if
636 * there is a better match later on in the
637 * string (greedy matching).
638 * This allows the user to have targets like:
641 * where "fie::fi:fo" and "foo::bar" are the
642 * targets. In real life this is used for perl5
643 * library man pages where "::" separates an
644 * object from its class. Ie:
645 * "File::Spec::Unix". This behaviour is also
646 * consistent with other versions of make.
650 if (*cp == ':' && *p == ':')
653 /* Found the best match already. */
654 if (*p == '\0' || isspace(*p))
657 p += strcspn(p, "!:");
659 /* No better match later on... */
667 * Archives must be handled specially to make sure the
668 * OP_ARCHV flag is set in their 'type' field, for one
669 * thing, and because things like "archive(file1.o
670 * file2.o file3.o)" are permissible. Arch_ParseArchive
671 * will set 'line' to be the first non-blank after the
672 * archive-spec. It creates/finds nodes for the members
673 * and places them on the given list, returning SUCCESS
674 * if all went well and FAILURE if there was an error in
675 * the specification. On error, line should remain
678 if (Arch_ParseArchive(&line, &targets, VAR_CMD) !=
680 Parse_Error(PARSE_FATAL,
681 "Error in archive specification: \"%s\"",
693 * Ending a dependency line without an operator is a * Bozo no-no. As a heuristic, this is also often
694 * triggered by undetected conflicts from cvs/rcs
697 if (strncmp(line, "<<<<<<", 6) == 0 ||
698 strncmp(line, "======", 6) == 0 ||
699 strncmp(line, ">>>>>>", 6) == 0) {
700 Parse_Error(PARSE_FATAL, "Makefile appears to "
701 "contain unresolved cvs/rcs/??? merge "
704 Parse_Error(PARSE_FATAL, "Need an operator");
709 * Have a word in line. See if it's a special target and set
710 * specType to match it.
712 if (*line == '.' && isupper((unsigned char)line[1])) {
714 * See if the target is a special target that must have
715 * it or its sources handled specially.
717 int keywd = ParseFindKeyword(line);
720 if (specType == ExPath &&
721 parseKeywords[keywd].spec != ExPath) {
722 Parse_Error(PARSE_FATAL,
723 "Mismatched special targets");
727 specType = parseKeywords[keywd].spec;
728 tOp = parseKeywords[keywd].op;
731 * Certain special targets have special
733 * .PATH Have to set the dirSearchPath
735 * .MAIN Its sources are only used if
736 * nothing has been specified to
738 * .DEFAULT Need to create a node to hang
739 * commands on, but we don't want
740 * it in the graph, nor do we want
741 * it to be the Main Target, so we
742 * create it, set OP_NOTMAIN and
743 * add it to the list, setting
744 * DEFAULT to the new node for
745 * later use. We claim the node is
746 * A transformation rule to make
747 * life easier later, when we'll
748 * use Make_HandleUse to actually
749 * apply the .DEFAULT commands.
750 * .PHONY The list of targets
753 * .INTERRUPT Are not to be considered the
755 * .NOTPARALLEL Make only one target at a time.
756 * .SINGLESHELL Create a shell for each
758 * .ORDER Must set initial predecessor
763 Lst_AtEnd(&paths, &dirSearchPath);
766 if (!Lst_IsEmpty(&create)) {
773 gn = Targ_FindNode(line, TARG_CREATE);
774 gn->type |= OP_NOTMAIN;
775 Lst_AtEnd(&targets, gn);
778 gn = Targ_NewGN(".DEFAULT");
779 gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
780 Lst_AtEnd(&targets, gn);
796 } else if (strncmp(line, ".PATH", 5) == 0) {
798 * .PATH<suffix> has to be handled specially.
799 * Call on the suffix module to give us a path
805 path = Suff_GetPath(&line[5]);
807 Parse_Error(PARSE_FATAL, "Suffix '%s' "
808 "not defined (yet)", &line[5]);
811 Lst_AtEnd(&paths, path);
816 * Have word in line. Get or create its node and stick it at
817 * the end of the targets list
819 if ((specType == Not) && (*line != '\0')) {
821 /* target names to be found and added to targets list */
822 Lst curTargs = Lst_Initializer(curTargs);
824 if (Dir_HasWildcards(line)) {
826 * Targets are to be sought only in the current
827 * directory, so create an empty path for the
828 * thing. Note we need to use Path_Clear in the
829 * destruction of the path as the Dir module
830 * could have added a directory to the path...
832 struct Path emptyPath =
833 TAILQ_HEAD_INITIALIZER(emptyPath);
835 Path_Expand(line, &emptyPath, &curTargs);
836 Path_Clear(&emptyPath);
840 * No wildcards, but we want to avoid code
841 * duplication, so create a list with the word
844 Lst_AtEnd(&curTargs, line);
847 while (!Lst_IsEmpty(&curTargs)) {
848 char *targName = Lst_DeQueue(&curTargs);
850 if (!Suff_IsTransform (targName)) {
851 gn = Targ_FindNode(targName,
854 gn = Suff_AddTransform(targName);
857 Lst_AtEnd(&targets, gn);
859 } else if (specType == ExPath && *line != '.' && *line != '\0'){
860 Parse_Error(PARSE_WARNING, "Extra target (%s) ignored",
866 * If it is a special type and not .PATH, it's the only
867 * target we allow on this line...
869 if (specType != Not && specType != ExPath) {
870 Boolean warnFlag = FALSE;
872 while ((*cp != '!') && (*cp != ':') && *cp) {
873 if (*cp != ' ' && *cp != '\t') {
879 Parse_Error(PARSE_WARNING,
880 "Extra target ignored");
883 while (*cp && isspace((unsigned char)*cp)) {
888 } while ((*line != '!') && (*line != ':') && *line);
890 if (!Lst_IsEmpty(&targets)) {
893 Parse_Error(PARSE_WARNING, "Special and mundane "
894 "targets don't mix. Mundane ones ignored");
901 * These four create nodes on which to hang commands, so
902 * targets shouldn't be empty...
906 * Nothing special here -- targets can be empty if it
914 * Have now parsed all the target names. Must parse the operator next.
915 * The result is left in op.
919 } else if (*cp == ':') {
927 Parse_Error(PARSE_FATAL, "Missing dependency operator");
931 cp++; /* Advance beyond operator */
936 * Get to the first source
938 while (*cp && isspace((unsigned char)*cp)) {
944 * Several special targets take different actions if present with no
946 * a .SUFFIXES line with no sources clears out all old suffixes
947 * a .PRECIOUS line makes all targets precious
948 * a .IGNORE line ignores errors for all targets
949 * a .SILENT line creates silence when making all targets
950 * a .PATH removes all directories from the search path(s).
955 Suff_ClearSuffixes();
967 LST_FOREACH(ln, &paths)
968 Path_Clear(Lst_Datum(ln));
971 Var_Set("%POSIX", "1003.2", VAR_GLOBAL);
977 } else if (specType == MFlags) {
979 * Call on functions in main.c to deal with these arguments and
980 * set the initial character to a null-character so the loop to
981 * get sources won't get anything
983 Main_ParseArgLine(line, 0);
986 } else if (specType == ExShell) {
987 if (Job_ParseShell(line) != SUCCESS) {
988 Parse_Error(PARSE_FATAL,
989 "improper shell specification");
994 } else if ((specType == NotParallel) || (specType == SingleShell)) {
999 * NOW GO FOR THE SOURCES
1001 if ((specType == Suffixes) || (specType == ExPath) ||
1002 (specType == Includes) || (specType == Libs) ||
1003 (specType == Null)) {
1006 * If the target was one that doesn't take files as its
1007 * sources but takes something like suffixes, we take
1008 * each space-separated word on the line as a something
1009 * and deal with it accordingly.
1011 * If the target was .SUFFIXES, we take each source as
1012 * a suffix and add it to the list of suffixes
1013 * maintained by the Suff module.
1015 * If the target was a .PATH, we add the source as a
1016 * directory to search on the search path.
1018 * If it was .INCLUDES, the source is taken to be the
1019 * suffix of files which will be #included and whose
1020 * search path should be present in the .INCLUDES
1023 * If it was .LIBS, the source is taken to be the
1024 * suffix of files which are considered libraries and
1025 * whose search path should be present in the .LIBS
1028 * If it was .NULL, the source is the suffix to use
1029 * when a file has no valid suffix.
1032 while (*cp && !isspace((unsigned char)*cp)) {
1039 Suff_AddSuffix(line);
1042 LST_FOREACH(ln, &paths)
1043 Path_AddDir(Lst_Datum(ln), line);
1046 Suff_AddInclude(line);
1058 if (savech != '\0') {
1061 while (*cp && isspace((unsigned char)*cp)) {
1066 Lst_Destroy(&paths, NOFREE);
1069 /* list of sources in order */
1070 Lst curSrcs = Lst_Initializer(curSrc);
1074 * The targets take real sources, so we must beware of
1075 * archive specifications (i.e. things with left
1076 * parentheses in them) and handle them accordingly.
1078 while (*cp && !isspace((unsigned char)*cp)) {
1079 if (*cp == '(' && cp > line && cp[-1] != '$') {
1081 * Only stop for a left parenthesis if
1082 * it isn't at the start of a word
1083 * (that'll be for variable changes
1084 * later) and isn't preceded by a dollar
1085 * sign (a dynamic source).
1096 /* list of archive source names after exp. */
1097 Lst sources = Lst_Initializer(sources);
1099 if (Arch_ParseArchive(&line, &sources,
1100 VAR_CMD) != SUCCESS) {
1101 Parse_Error(PARSE_FATAL, "Error in "
1102 "source archive spec \"%s\"", line);
1106 while (!Lst_IsEmpty(&sources)) {
1107 gnp = Lst_DeQueue(&sources);
1108 ParseDoSrc(tOp, gnp->name, &curSrcs);
1117 ParseDoSrc(tOp, line, &curSrcs);
1119 while (*cp && isspace((unsigned char)*cp)) {
1124 Lst_Destroy(&curSrcs, NOFREE);
1127 if (mainNode == NULL) {
1129 * If we have yet to decide on a main target to make, in the
1130 * absence of any user input, we want the first target on
1131 * the first dependency line that is actually a real target
1132 * (i.e. isn't a .USE or .EXEC rule) to be made.
1134 LST_FOREACH(ln, &targets) {
1136 if ((gn->type & (OP_NOTMAIN | OP_USE |
1137 OP_EXEC | OP_TRANSFORM)) == 0) {
1147 *---------------------------------------------------------------------
1149 * Return TRUE if the passed line is a variable assignment. A variable
1150 * assignment consists of a single word followed by optional whitespace
1151 * followed by either a += or an = operator.
1152 * This function is used both by the Parse_File function and main when
1153 * parsing the command-line arguments.
1156 * TRUE if it is. FALSE if it ain't
1160 *---------------------------------------------------------------------
1163 Parse_IsVar(char *line)
1165 Boolean wasSpace = FALSE; /* set TRUE if found a space */
1166 Boolean haveName = FALSE; /* Set TRUE if have a variable name */
1169 #define ISEQOPERATOR(c) \
1170 (((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
1173 * Skip to variable name
1175 for (; (*line == ' ') || (*line == '\t'); line++)
1178 for (; *line != '=' || level != 0; line++) {
1182 * end-of-line -- can't be a variable assignment.
1189 * there can be as much white space as desired so long
1190 * as there is only one word before the operator
1206 if (wasSpace && haveName) {
1207 if (ISEQOPERATOR(*line)) {
1209 * We must have a finished word
1215 * When an = operator [+?!:] is found,
1216 * the next character must be an = or
1217 * it ain't a valid assignment.
1223 * This is a shell command
1225 if (strncmp(line, ":sh", 3) == 0)
1230 * This is the start of another word, so not
1247 *---------------------------------------------------------------------
1249 * Take the variable assignment in the passed line and do it in the
1252 * Note: There is a lexical ambiguity with assignment modifier characters
1253 * in variable names. This routine interprets the character before the =
1254 * as a modifier. Therefore, an assignment like
1256 * is interpreted as "C+ +=" instead of "C++ =".
1262 * the variable structure of the given variable name is altered in the
1264 *---------------------------------------------------------------------
1267 Parse_DoVar(char *line, GNode *ctxt)
1269 char *cp; /* pointer into line */
1275 } type; /* Type of assignment */
1276 char *opc; /* ptr to operator character to
1277 * null-terminate the variable name */
1280 * Avoid clobbered variable warnings by forcing the compiler
1281 * to ``unregister'' variables
1289 * Skip to variable name
1291 while ((*line == ' ') || (*line == '\t')) {
1296 * Skip to operator character, nulling out whitespace as we go
1298 for (cp = line + 1; *cp != '='; cp++) {
1299 if (isspace((unsigned char)*cp)) {
1303 opc = cp - 1; /* operator is the previous character */
1304 *cp++ = '\0'; /* nuke the = */
1307 * Check operator type
1317 * If the variable already has a value, we don't do anything.
1320 if (Var_Exists(line, ctxt)) {
1339 while (*opc != ':') {
1346 if (strncmp(opc, ":sh", 3) == 0) {
1356 while (isspace((unsigned char)*cp)) {
1360 if (type == VAR_APPEND) {
1361 Var_Append(line, cp, ctxt);
1363 } else if (type == VAR_SUBST) {
1365 * Allow variables in the old value to be undefined, but leave
1366 * their invocation alone -- this is done by forcing oldVars
1368 * XXX: This can cause recursive variables, but that's not
1369 * hard to do, and this allows someone to do something like
1371 * CFLAGS = $(.INCLUDES)
1372 * CFLAGS := -I.. $(CFLAGS)
1374 * And not get an error.
1376 Boolean oldOldVars = oldVars;
1381 * make sure that we set the variable the first time to nothing
1382 * so that it gets substituted!
1384 if (!Var_Exists(line, ctxt))
1385 Var_Set(line, "", ctxt);
1387 cp = Buf_Peel(Var_Subst(NULL, cp, ctxt, FALSE));
1389 oldVars = oldOldVars;
1391 Var_Set(line, cp, ctxt);
1394 } else if (type == VAR_SHELL) {
1396 * TRUE if the command needs to be freed, i.e.
1397 * if any variable expansion was performed
1399 Boolean freeCmd = FALSE;
1403 if (strchr(cp, '$') != NULL) {
1405 * There's a dollar sign in the command, so perform
1406 * variable expansion on the whole thing. The
1407 * resulting string will need freeing when we're done,
1408 * so set freeCmd to TRUE.
1410 cp = Buf_Peel(Var_Subst(NULL, cp, VAR_CMD, TRUE));
1414 buf = Cmd_Exec(cp, &error);
1415 Var_Set(line, Buf_Data(buf), ctxt);
1416 Buf_Destroy(buf, TRUE);
1419 Parse_Error(PARSE_WARNING, error, cp);
1426 * Normal assignment -- just do it.
1428 Var_Set(line, cp, ctxt);
1433 *-----------------------------------------------------------------------
1434 * ParseHasCommands --
1435 * Callback procedure for Parse_File when destroying the list of
1436 * targets on the last dependency line. Marks a target as already
1437 * having commands if it does, to keep from having shell commands
1438 * on multiple dependency lines.
1444 * OP_HAS_COMMANDS may be set for the target.
1446 *-----------------------------------------------------------------------
1449 ParseHasCommands(void *gnp)
1453 if (!Lst_IsEmpty(&gn->commands)) {
1454 gn->type |= OP_HAS_COMMANDS;
1459 *-----------------------------------------------------------------------
1460 * Parse_AddIncludeDir --
1461 * Add a directory to the path searched for included makefiles
1462 * bracketed by double-quotes. Used by functions in main.c
1468 * The directory is appended to the list.
1470 *-----------------------------------------------------------------------
1473 Parse_AddIncludeDir(char *dir)
1476 Path_AddDir(&parseIncPath, dir);
1479 /*---------------------------------------------------------------------
1481 * Handle error directive
1483 * The input is the line minus the ".error". We substitute variables,
1484 * print the message and exit(1) or just print a warning if the ".error"
1485 * directive is malformed.
1487 *---------------------------------------------------------------------
1490 ParseDoError(char *errmsg)
1494 if (!isspace((unsigned char)*errmsg)) {
1495 Parse_Error(PARSE_WARNING, "invalid syntax: .error%s", errmsg);
1499 while (isspace((unsigned char)*errmsg))
1502 buf = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
1503 Parse_Error(PARSE_FATAL, "%s", Buf_Data(buf));
1504 Buf_Destroy(buf, TRUE);
1506 /* Terminate immediately. */
1510 /*---------------------------------------------------------------------
1512 * Handle warning directive
1514 * The input is the line minus the ".warning". We substitute variables
1515 * and print the message or just print a warning if the ".warning"
1516 * directive is malformed.
1518 *---------------------------------------------------------------------
1521 ParseDoWarning(char *warnmsg)
1525 if (!isspace((unsigned char)*warnmsg)) {
1526 Parse_Error(PARSE_WARNING, "invalid syntax: .warning%s",
1531 while (isspace((unsigned char)*warnmsg))
1534 buf = Var_Subst(NULL, warnmsg, VAR_GLOBAL, FALSE);
1535 Parse_Error(PARSE_WARNING, "%s", Buf_Data(buf));
1536 Buf_Destroy(buf, TRUE);
1540 *---------------------------------------------------------------------
1542 * Push to another file.
1544 * The input is the line minus the #include. A file spec is a string
1545 * enclosed in <> or "". The former is looked for only in sysIncPath.
1546 * The latter in . and the directories specified by -I command line
1553 * A structure is added to the includes Lst and readProc, curFile.lineno,
1554 * curFile.fname and curFile.F are altered for the new file
1555 *---------------------------------------------------------------------
1558 ParseDoInclude(char *file)
1560 char *fullname; /* full pathname of file */
1561 IFile *oldFile; /* state associated with current file */
1562 char endc; /* the character which ends the file spec */
1563 char *cp; /* current position in file spec */
1564 Boolean isSystem; /* TRUE if makefile is a system makefile */
1568 * Skip to delimiter character so we know where to look
1570 while ((*file == ' ') || (*file == '\t')) {
1574 if ((*file != '"') && (*file != '<')) {
1575 Parse_Error(PARSE_FATAL,
1576 ".include filename must be delimited by '\"' or '<'");
1581 * Set the search path on which to find the include file based on the
1582 * characters which bracket its name. Angle-brackets imply it's
1583 * a system Makefile while double-quotes imply it's a user makefile
1594 * Skip to matching delimiter
1596 for (cp = ++file; *cp && *cp != endc; cp++) {
1601 Parse_Error(PARSE_FATAL,
1602 "Unclosed %cinclude filename. '%c' expected", '.', endc);
1608 * Substitute for any variables in the file name before trying to
1611 buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
1612 file = Buf_Peel(buf);
1615 * Now we know the file's name and its search path, we attempt to
1616 * find the durn thing. A return of NULL indicates the file don't
1621 * Include files contained in double-quotes are first searched
1622 * for relative to the including file's location. We don't want
1623 * to cd there, of course, so we just tack on the old file's
1624 * leading path components and call Dir_FindFile to see if
1625 * we can locate the beast.
1627 char *prefEnd, *Fname;
1629 /* Make a temporary copy of this, to be safe. */
1630 Fname = estrdup(curFile.fname);
1632 prefEnd = strrchr(Fname, '/');
1633 if (prefEnd != (char *)NULL) {
1638 newName = estrdup(file);
1640 newName = str_concat(Fname, file, STR_ADDSLASH);
1641 fullname = Path_FindFile(newName, &parseIncPath);
1642 if (fullname == NULL) {
1643 fullname = Path_FindFile(newName,
1656 if (fullname == NULL) {
1658 * System makefile or makefile wasn't found in same directory as
1659 * included makefile. Search for it first on the -I search path,
1660 * then on the .PATH search path, if not found in a -I
1662 * XXX: Suffix specific?
1664 fullname = Path_FindFile(file, &parseIncPath);
1665 if (fullname == NULL) {
1666 fullname = Path_FindFile(file, &dirSearchPath);
1670 if (fullname == NULL) {
1672 * Still haven't found the makefile. Look for it on the system
1673 * path as a last resort.
1675 fullname = Path_FindFile(file, &sysIncPath);
1678 if (fullname == NULL) {
1680 Parse_Error(PARSE_FATAL, "Could not find %s", file);
1681 /* XXXHB free(file) */
1688 * Once we find the absolute path to the file, we get to save all the
1689 * state from the current file before we can start reading this
1690 * include file. The state is stored in an IFile structure which
1691 * is placed on a list with other IFile structures. The list makes
1692 * a very nice stack to track how we got here...
1694 oldFile = emalloc(sizeof(IFile));
1695 memcpy(oldFile, &curFile, sizeof(IFile));
1697 Lst_AtFront(&includes, oldFile);
1700 * Once the previous state has been saved, we can get down to reading
1701 * the new file. We set up the name of the file to be the absolute
1702 * name of the include file so error messages refer to the right
1703 * place. Naturally enough, we start reading at line number 0.
1705 curFile.fname = fullname;
1708 curFile.F = fopen(fullname, "r");
1710 if (curFile.F == NULL) {
1711 Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
1713 * Pop to previous file
1717 Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL);
1722 *---------------------------------------------------------------------
1723 * Parse_FromString --
1724 * Start Parsing from the given string
1730 * A structure is added to the includes Lst and readProc, curFile.lineno,
1731 * curFile.fname and curFile.F are altered for the new file
1732 *---------------------------------------------------------------------
1735 Parse_FromString(char *str, int lineno)
1737 IFile *oldFile; /* state associated with this file */
1739 DEBUGF(FOR, ("%s\n---- at line %d\n", str, lineno));
1741 oldFile = emalloc(sizeof(IFile));
1742 memcpy(oldFile, &curFile, sizeof(IFile));
1744 Lst_AtFront(&includes, oldFile);
1747 curFile.p = emalloc(sizeof(PTR));
1748 curFile.p->str = curFile.p->ptr = str;
1749 curFile.lineno = lineno;
1750 curFile.fname = estrdup(curFile.fname);
1755 *---------------------------------------------------------------------
1756 * ParseTraditionalInclude --
1757 * Push to another file.
1759 * The input is the line minus the "include". The file name is
1760 * the string following the "include".
1766 * A structure is added to the includes Lst and readProc, curFile.lineno,
1767 * curFile.fname and curFile.F are altered for the new file
1768 *---------------------------------------------------------------------
1771 ParseTraditionalInclude(char *file)
1773 char *fullname; /* full pathname of file */
1774 IFile *oldFile; /* state associated with current file */
1775 char *cp; /* current position in file spec */
1779 * Skip over whitespace
1781 while ((*file == ' ') || (*file == '\t')) {
1785 if (*file == '\0') {
1786 Parse_Error(PARSE_FATAL, "Filename missing from \"include\"");
1791 * Skip to end of line or next whitespace
1793 for (cp = file; *cp && *cp != '\n' && *cp != '\t' && *cp != ' '; cp++) {
1800 * Substitute for any variables in the file name before trying to
1803 buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
1804 file = Buf_Peel(buf);
1807 * Now we know the file's name, we attempt to find the durn thing.
1808 * Search for it first on the -I search path, then on the .PATH
1809 * search path, if not found in a -I directory.
1811 fullname = Path_FindFile(file, &parseIncPath);
1812 if (fullname == NULL) {
1813 fullname = Path_FindFile(file, &dirSearchPath);
1816 if (fullname == NULL) {
1818 * Still haven't found the makefile. Look for it on the system
1819 * path as a last resort.
1821 fullname = Path_FindFile(file, &sysIncPath);
1824 if (fullname == NULL) {
1825 Parse_Error(PARSE_FATAL, "Could not find %s", file);
1826 /* XXXHB free(file) */
1830 /* XXXHB free(file) */
1833 * Once we find the absolute path to the file, we get to save all the
1834 * state from the current file before we can start reading this
1835 * include file. The state is stored in an IFile structure which
1836 * is placed on a list with other IFile structures. The list makes
1837 * a very nice stack to track how we got here...
1839 oldFile = emalloc(sizeof(IFile));
1840 memcpy(oldFile, &curFile, sizeof(IFile));
1842 Lst_AtFront(&includes, oldFile);
1845 * Once the previous state has been saved, we can get down to reading
1846 * the new file. We set up the name of the file to be the absolute
1847 * name of the include file so error messages refer to the right
1848 * place. Naturally enough, we start reading at line number 0.
1850 curFile.fname = fullname;
1853 curFile.F = fopen(fullname, "r");
1855 if (curFile.F == NULL) {
1856 Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
1858 * Pop to previous file
1862 Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL);
1868 *---------------------------------------------------------------------
1870 * Called when EOF is reached in the current file. If we were reading
1871 * an include file, the includes stack is popped and things set up
1872 * to go back to reading the previous file at the previous location.
1875 * CONTINUE if there's more to do. DONE if not.
1878 * The old curFile.F is closed. The includes list is shortened.
1879 * curFile.lineno, curFile.F, and curFile.fname are changed if
1880 * CONTINUE is returned.
1881 *---------------------------------------------------------------------
1884 ParseEOF(int opened)
1886 IFile *ifile; /* the state on the top of the includes stack */
1888 if (Lst_IsEmpty(&includes)) {
1889 Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL);
1893 ifile = Lst_DeQueue(&includes);
1894 free(curFile.fname);
1895 if (opened && curFile.F) {
1897 Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL);
1900 free(curFile.p->str);
1903 memcpy(&curFile, ifile, sizeof(IFile));
1909 *---------------------------------------------------------------------
1911 * Read a character from the current file
1914 * The character that was read
1917 *---------------------------------------------------------------------
1924 return (fgetc(curFile.F));
1926 if (curFile.p && *curFile.p->ptr)
1927 return (*curFile.p->ptr++);
1933 *---------------------------------------------------------------------
1935 * Put back a character to the current file
1941 *---------------------------------------------------------------------
1948 ungetc(c, curFile.F);
1952 *--(curFile.p->ptr) = c;
1958 * Grab the next line unless it begins with a dot (`.') and we're told to
1959 * ignore such lines.
1962 ParseSkipLine(int skip, int keep_newline)
1968 buf = Buf_Init(MAKE_BSIZE);
1974 while (((c = ParseReadc()) != '\n' || lastc == '\\')
1976 if (skip && c == '#' && lastc != '\\') {
1978 * let a comment be terminated even by an
1979 * escaped \n. This is consistent to comment
1980 * handling in ParseReadLine
1982 while ((c = ParseReadc()) != '\n' && c != EOF)
1988 Buf_AddByte(buf, (Byte)c);
1990 Buf_ReplaceLastByte(buf, (Byte)' ');
1993 while ((c = ParseReadc()) == ' ' || c == '\t')
2000 Buf_AddByte(buf, (Byte)c);
2005 Parse_Error(PARSE_FATAL,
2006 "Unclosed conditional/for loop");
2007 Buf_Destroy(buf, TRUE);
2012 Buf_AddByte(buf, (Byte)'\0');
2013 line = Buf_Data(buf);
2014 } while (skip == 1 && line[0] != '.');
2016 Buf_Destroy(buf, FALSE);
2021 *---------------------------------------------------------------------
2023 * Read an entire line from the input file. Called only by Parse_File.
2024 * To facilitate escaped newlines and what have you, a character is
2025 * buffered in 'lastc', which is '\0' when no characters have been
2026 * read. When we break out of the loop, c holds the terminating
2027 * character and lastc holds a character that should be added to
2028 * the line (unless we don't read anything but a terminator).
2031 * A line w/o its newline
2034 * Only those associated with reading a character
2035 *---------------------------------------------------------------------
2040 Buffer *buf; /* Buffer for current line */
2041 int c; /* the current character */
2042 int lastc; /* The most-recent character */
2043 Boolean semiNL; /* treat semi-colons as newlines */
2044 Boolean ignDepOp; /* TRUE if should ignore dependency operators
2045 * for the purposes of setting semiNL */
2046 Boolean ignComment; /* TRUE if should ignore comments (in a
2048 char *line; /* Result */
2049 char *ep; /* to strip trailing blanks */
2050 int lineno; /* Saved line # */
2057 * Handle special-characters at the beginning of the line. Either a
2058 * leading tab (shell command) or pound-sign (possible conditional)
2059 * forces us to ignore comments and dependency operators and treat
2060 * semi-colons as semi-colons (by leaving semiNL FALSE). This also
2061 * discards completely blank lines.
2067 ignComment = ignDepOp = TRUE;
2069 } else if (c == '\n') {
2071 } else if (c == '#') {
2076 * Anything else breaks out without doing anything
2084 buf = Buf_Init(MAKE_BSIZE);
2086 while (((c = ParseReadc()) != '\n' || (lastc == '\\')) &&
2092 * Escaped newline: read characters until a
2093 * non-space or an unescaped newline and
2094 * replace them all by a single space. This is
2095 * done by storing the space over the backslash
2096 * and dropping through with the next nonspace.
2097 * If it is a semi-colon and semiNL is TRUE,
2098 * it will be recognized as a newline in the
2099 * code below this...
2103 while ((c = ParseReadc()) == ' ' || c == '\t') {
2106 if (c == EOF || c == '\n') {
2110 * Check for comments, semiNL's, etc. --
2111 * easier than ParseUnreadc(c);
2121 * Semi-colon: Need to see if it should be
2122 * interpreted as a newline
2126 * To make sure the command that may
2127 * be following this semi-colon begins
2128 * with a tab, we push one back into the
2129 * input stream. This will overwrite the
2130 * semi-colon in the buffer. If there is
2131 * no command following, this does no
2132 * harm, since the newline remains in
2133 * the buffer and the
2134 * whole line is ignored.
2143 * Haven't seen a dependency operator
2144 * before this, so this must be a
2145 * variable assignment -- don't pay
2146 * attention to dependency operators
2150 } else if (lastc == ':' || lastc == '!') {
2152 * Well, we've seen a dependency
2153 * operator already, but it was the
2154 * previous character, so this is really
2155 * just an expanded variable assignment.
2156 * Revert semi-colons to being just
2157 * semi-colons again and ignore any more
2158 * dependency operators.
2160 * XXX: Note that a line like
2161 * "foo : a:=b" will blow up, but who'd
2162 * write a line like that anyway?
2170 if (lastc != '\\') {
2172 * If the character is a hash
2173 * mark and it isn't escaped
2174 * (or we're being compatible),
2175 * the thing is a comment.
2176 * Skip to the end of the line.
2180 } while (c != '\n' && c != EOF);
2184 * Don't add the backslash.
2185 * Just let the # get copied
2196 if (!ignDepOp && (c == ':' || c == '!')) {
2198 * A semi-colon is recognized as a
2199 * newline only on dependency lines.
2200 * Dependency lines are lines with a
2201 * colon or an exclamation point.
2212 * Copy in the previous character and save this one in
2215 Buf_AddByte(buf, (Byte)lastc);
2221 if (lastc != '\0') {
2222 Buf_AddByte(buf, (Byte)lastc);
2224 Buf_AddByte(buf, (Byte)'\0');
2225 line = Buf_Peel(buf);
2228 * Strip trailing blanks and tabs from the line.
2229 * Do not strip a blank or tab that is preceded by
2235 while (ep > line + 1 && (ep[-1] == ' ' || ep[-1] == '\t')) {
2236 if (ep > line + 1 && ep[-2] == '\\')
2242 if (line[0] == '.') {
2244 * The line might be a conditional. Ask the
2245 * conditional module about it and act accordingly
2247 switch (Cond_Eval(line)) {
2250 * Skip to next conditional that evaluates to
2255 line = ParseSkipLine(1, 0);
2256 } while (line && Cond_Eval(line) != COND_PARSE);
2263 line = ParseReadLine();
2267 if (For_Eval(line)) {
2270 lineno = curFile.lineno;
2273 * Skip after the matching end
2275 line = ParseSkipLine(0, 1);
2277 Parse_Error(PARSE_FATAL,
2283 ok = For_Eval(line);
2288 line = ParseReadLine();
2300 * Hit end-of-file, so return a NULL line to indicate this.
2307 *-----------------------------------------------------------------------
2308 * ParseFinishLine --
2309 * Handle the end of a dependency group.
2315 * inLine set FALSE. 'targets' list destroyed.
2317 *-----------------------------------------------------------------------
2320 ParseFinishLine(void)
2325 LST_FOREACH(ln, &targets) {
2326 if (((const GNode *)Lst_Datum(ln))->type & OP_TRANSFORM)
2327 Suff_EndTransform(Lst_Datum(ln));
2329 Lst_Destroy(&targets, ParseHasCommands);
2336 *---------------------------------------------------------------------
2338 * Parse a file into its component parts, incorporating it into the
2339 * current dependency graph. This is the main function and controls
2340 * almost every other function in this module
2346 * Loads. Nodes are added to the list of all targets, nodes and links
2347 * are added to the dependency graph. etc. etc. etc.
2348 *---------------------------------------------------------------------
2351 Parse_File(char *name, FILE *stream)
2353 char *cp; /* pointer into the line */
2354 char *line; /* the line we're working on */
2358 curFile.fname = name;
2363 Var_Append(".MAKEFILE_LIST", name, VAR_GLOBAL);
2366 while ((line = ParseReadLine()) != NULL) {
2369 * Lines that begin with the special character
2370 * are either include or undef directives.
2372 for (cp = line + 1; isspace((unsigned char)*cp);
2376 if (strncmp(cp, "include", 7) == 0) {
2377 ParseDoInclude(cp + 7);
2379 } else if (strncmp(cp, "error", 5) == 0) {
2380 ParseDoError(cp + 5);
2382 } else if (strncmp(cp, "warning", 7) == 0) {
2383 ParseDoWarning(cp + 7);
2385 } else if (strncmp(cp, "undef", 5) == 0) {
2386 cp = stripvarname(cp + 5);
2387 buf = Var_Subst(NULL, cp, VAR_CMD,
2391 Var_Delete(cp, VAR_GLOBAL);
2393 } else if (strncmp(cp, "makeenv", 7) == 0) {
2394 cp = stripvarname(cp + 7);
2395 Var_SetEnv(cp, VAR_GLOBAL);
2401 * If we're this far, the line must be
2407 if (*line == '\t') {
2409 * If a line starts with a tab, it can only
2410 * hope to be a creation command.
2413 isspace((unsigned char)*cp); cp++) {
2422 * So long as it's not a blank
2423 * line and we're actually in a
2424 * dependency spec, add the
2425 * command to the list of
2426 * commands of all targets in
2427 * the dependency spec.
2429 LST_FOREACH(ln, &targets) {
2439 Lst_AtEnd(&gn->commands, cp);
2441 Parse_Error(PARSE_WARNING, "duplicate script "
2442 "for target \"%s\" ignored", gn->name);
2446 Parse_Error(PARSE_FATAL,
2447 "Unassociated shell command \"%s\"",
2452 } else if (strncmp(line, "include", 7) == 0 &&
2453 isspace((unsigned char)line[7]) &&
2454 strchr(line, ':') == NULL) {
2456 * It's an S3/S5-style "include".
2458 ParseTraditionalInclude(line + 7);
2461 } else if (Parse_IsVar(line)) {
2463 Parse_DoVar(line, VAR_GLOBAL);
2467 * We now know it's a dependency line so it
2468 * needs to have all variables expanded before
2469 * being parsed. Tell the variable module to
2470 * complain if some variable is undefined...
2471 * To make life easier on novices, if the line
2472 * is indented we first make sure the line has
2473 * a dependency operator in it. If it doesn't
2474 * have an operator and we're in a dependency
2475 * line's script, we assume it's actually a
2476 * shell command and add it to the current
2480 if (isspace((unsigned char)line[0])) {
2481 while ((*cp != '\0') &&
2482 isspace((unsigned char)*cp)) {
2492 buf = Var_Subst(NULL, line, VAR_CMD, TRUE);
2499 * Need a non-circular list for the target nodes
2501 Lst_Destroy(&targets, NOFREE);
2504 ParseDoDependency(line);
2512 * Reached EOF, but it may be just EOF of an include file...
2514 } while (ParseEOF(1) == CONTINUE);
2519 * Make sure conditionals are clean
2524 errx(1, "fatal errors encountered -- cannot continue");
2528 *---------------------------------------------------------------------
2530 * initialize the parsing module
2536 * the parseIncPath list is initialized...
2537 *---------------------------------------------------------------------
2547 *-----------------------------------------------------------------------
2549 * Return a Lst of the main target to create for main()'s sake. If
2550 * no such target exists, we Punt with an obnoxious error message.
2553 * A Lst of the single node to create.
2558 *-----------------------------------------------------------------------
2561 Parse_MainName(Lst *listmain)
2564 if (mainNode == NULL) {
2565 Punt("no target to make.");
2567 } else if (mainNode->type & OP_DOUBLEDEP) {
2568 Lst_AtEnd(listmain, mainNode);
2569 Lst_Concat(listmain, &mainNode->cohorts, LST_CONCNEW);
2571 Lst_AtEnd(listmain, mainNode);