2005-02-01 10:50:37 +00:00
|
|
|
/*-
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* Copyright (c) 1989 by Berkeley Softworks
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Adam de Boor.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2000-07-09 02:54:54 +00:00
|
|
|
*
|
|
|
|
* @(#)parse.c 8.3 (Berkeley) 3/19/94
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-09 02:54:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
2002-04-13 10:17:18 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* parse.c --
|
|
|
|
* Functions to parse a makefile.
|
|
|
|
*
|
|
|
|
* One function, Parse_Init, must be called before any functions
|
|
|
|
* in this module are used. After that, the function Parse_File is the
|
|
|
|
* main entry point and controls most of the other functions in this
|
|
|
|
* module.
|
|
|
|
*
|
|
|
|
* Most important structures are kept in Lsts. Directories for
|
|
|
|
* the #include "..." function are kept in the 'parseIncPath' Lst, while
|
|
|
|
* those for the #include <...> are kept in the 'sysIncPath' Lst. The
|
|
|
|
* targets currently being defined are kept in the 'targets' Lst.
|
|
|
|
*
|
2004-03-10 21:51:06 +00:00
|
|
|
* The variables 'curFile.fname' and 'curFile.lineno' are used to track
|
|
|
|
* the name of the current file and the line number in that file so that
|
|
|
|
* error messages can be more meaningful.
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Interface:
|
|
|
|
* Parse_Init Initialization function which must be
|
|
|
|
* called before anything else in this module
|
|
|
|
* is used.
|
|
|
|
*
|
|
|
|
* Parse_File Function used to parse a makefile. It must
|
|
|
|
* be given the name of the file, which should
|
|
|
|
* already have been opened, and a function
|
|
|
|
* to call to read a character from the file.
|
|
|
|
*
|
|
|
|
* Parse_IsVar Returns TRUE if the given line is a
|
|
|
|
* variable assignment. Used by MainParseArgs
|
|
|
|
* to determine if an argument is a target
|
|
|
|
* or a variable assignment. Used internally
|
|
|
|
* for pretty much the same thing...
|
|
|
|
*
|
|
|
|
* Parse_Error Function called when an error occurs in
|
|
|
|
* parsing. Used by the variable and
|
|
|
|
* conditional modules.
|
|
|
|
* Parse_MainName Returns a Lst of the main target to create.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2005-02-01 10:50:37 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
1997-07-24 06:58:08 +00:00
|
|
|
#include <err.h>
|
2005-02-01 10:50:37 +00:00
|
|
|
|
|
|
|
#include "arch.h"
|
|
|
|
#include "buf.h"
|
|
|
|
#include "cond.h"
|
|
|
|
#include "config.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "dir.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "for.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "GNode.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "job.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "make.h"
|
|
|
|
#include "nonints.h"
|
|
|
|
#include "parse.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
#include "pathnames.h"
|
2005-02-01 10:50:37 +00:00
|
|
|
#include "str.h"
|
|
|
|
#include "suff.h"
|
|
|
|
#include "targ.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "var.h"
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These values are returned by ParseEOF to tell Parse_File whether to
|
|
|
|
* CONTINUE parsing, i.e. it had only reached the end of an include file,
|
|
|
|
* or if it's DONE.
|
|
|
|
*/
|
|
|
|
#define CONTINUE 1
|
|
|
|
#define DONE 0
|
2004-12-16 16:14:16 +00:00
|
|
|
|
|
|
|
/* targets we're working on */
|
|
|
|
static Lst targets = Lst_Initializer(targets);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
static Boolean inLine; /* true if currently in a dependency
|
|
|
|
* line or its commands */
|
|
|
|
static int fatals = 0;
|
|
|
|
|
|
|
|
static GNode *mainNode; /* The main target to create. This is the
|
|
|
|
* first target on the first dependency
|
|
|
|
* line in the first makefile */
|
|
|
|
|
2004-07-20 07:42:06 +00:00
|
|
|
IFile curFile; /* current makefile */
|
2004-03-10 21:51:06 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
/* stack of IFiles generated by * #includes */
|
|
|
|
static Lst includes = Lst_Initializer(includes);
|
|
|
|
|
|
|
|
/* list of directories for "..." includes */
|
|
|
|
Lst parseIncPath = Lst_Initializer(parseIncPath);
|
|
|
|
|
|
|
|
/* list of directories for <...> includes */
|
|
|
|
Lst sysIncPath = Lst_Initializer(sysIncPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* specType contains the SPECial TYPE of the current target. It is
|
|
|
|
* Not if the target is unspecial. If it *is* special, however, the children
|
|
|
|
* are linked as children of the parent but not vice versa. This variable is
|
|
|
|
* set in ParseDoDependency
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
Begin, /* .BEGIN */
|
|
|
|
Default, /* .DEFAULT */
|
|
|
|
End, /* .END */
|
|
|
|
Ignore, /* .IGNORE */
|
|
|
|
Includes, /* .INCLUDES */
|
|
|
|
Interrupt, /* .INTERRUPT */
|
|
|
|
Libs, /* .LIBS */
|
|
|
|
MFlags, /* .MFLAGS or .MAKEFLAGS */
|
|
|
|
Main, /* .MAIN and we don't have anything user-specified to
|
|
|
|
* make */
|
|
|
|
NoExport, /* .NOEXPORT */
|
|
|
|
Not, /* Not special */
|
|
|
|
NotParallel, /* .NOTPARALELL */
|
|
|
|
Null, /* .NULL */
|
|
|
|
Order, /* .ORDER */
|
1996-10-06 02:35:38 +00:00
|
|
|
Parallel, /* .PARALLEL */
|
1994-05-27 12:33:43 +00:00
|
|
|
ExPath, /* .PATH */
|
1996-10-06 02:35:38 +00:00
|
|
|
Phony, /* .PHONY */
|
1996-11-03 03:29:57 +00:00
|
|
|
Posix, /* .POSIX */
|
1994-05-27 12:33:43 +00:00
|
|
|
Precious, /* .PRECIOUS */
|
|
|
|
ExShell, /* .SHELL */
|
|
|
|
Silent, /* .SILENT */
|
|
|
|
SingleShell, /* .SINGLESHELL */
|
|
|
|
Suffixes, /* .SUFFIXES */
|
1996-10-06 02:35:38 +00:00
|
|
|
Wait, /* .WAIT */
|
1994-05-27 12:33:43 +00:00
|
|
|
Attribute /* Generic attribute */
|
|
|
|
} ParseSpecial;
|
|
|
|
|
|
|
|
static ParseSpecial specType;
|
1996-10-06 02:35:38 +00:00
|
|
|
static int waiting;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
2000-12-02 18:58:01 +00:00
|
|
|
* Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
|
1994-05-27 12:33:43 +00:00
|
|
|
* seen, then set to each successive source on the line.
|
|
|
|
*/
|
|
|
|
static GNode *predecessor;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The parseKeywords table is searched using binary search when deciding
|
|
|
|
* if a target or source is special. The 'spec' field is the ParseSpecial
|
|
|
|
* type of the keyword ("Not" if the keyword isn't special as a target) while
|
|
|
|
* the 'op' field is the operator to apply to the list of targets if the
|
|
|
|
* keyword is used as a source ("0" if the keyword isn't special as a source)
|
|
|
|
*/
|
|
|
|
static struct {
|
2005-02-04 07:51:00 +00:00
|
|
|
const char *name; /* Name of keyword */
|
1994-05-27 12:33:43 +00:00
|
|
|
ParseSpecial spec; /* Type when used as a target */
|
|
|
|
int op; /* Operator when used as a source */
|
|
|
|
} parseKeywords[] = {
|
|
|
|
{ ".BEGIN", Begin, 0 },
|
|
|
|
{ ".DEFAULT", Default, 0 },
|
|
|
|
{ ".END", End, 0 },
|
|
|
|
{ ".EXEC", Attribute, OP_EXEC },
|
|
|
|
{ ".IGNORE", Ignore, OP_IGNORE },
|
|
|
|
{ ".INCLUDES", Includes, 0 },
|
|
|
|
{ ".INTERRUPT", Interrupt, 0 },
|
|
|
|
{ ".INVISIBLE", Attribute, OP_INVISIBLE },
|
|
|
|
{ ".JOIN", Attribute, OP_JOIN },
|
|
|
|
{ ".LIBS", Libs, 0 },
|
|
|
|
{ ".MAIN", Main, 0 },
|
|
|
|
{ ".MAKE", Attribute, OP_MAKE },
|
|
|
|
{ ".MAKEFLAGS", MFlags, 0 },
|
|
|
|
{ ".MFLAGS", MFlags, 0 },
|
|
|
|
{ ".NOTMAIN", Attribute, OP_NOTMAIN },
|
|
|
|
{ ".NOTPARALLEL", NotParallel, 0 },
|
1996-10-06 02:35:38 +00:00
|
|
|
{ ".NO_PARALLEL", NotParallel, 0 },
|
1994-05-27 12:33:43 +00:00
|
|
|
{ ".NULL", Null, 0 },
|
1995-06-18 12:34:14 +00:00
|
|
|
{ ".OPTIONAL", Attribute, OP_OPTIONAL },
|
1994-05-27 12:33:43 +00:00
|
|
|
{ ".ORDER", Order, 0 },
|
1996-10-06 02:35:38 +00:00
|
|
|
{ ".PARALLEL", Parallel, 0 },
|
1994-05-27 12:33:43 +00:00
|
|
|
{ ".PATH", ExPath, 0 },
|
1996-10-06 02:35:38 +00:00
|
|
|
{ ".PHONY", Phony, OP_PHONY },
|
1996-11-03 03:29:57 +00:00
|
|
|
{ ".POSIX", Posix, 0 },
|
1994-05-27 12:33:43 +00:00
|
|
|
{ ".PRECIOUS", Precious, OP_PRECIOUS },
|
|
|
|
{ ".RECURSIVE", Attribute, OP_MAKE },
|
|
|
|
{ ".SHELL", ExShell, 0 },
|
|
|
|
{ ".SILENT", Silent, OP_SILENT },
|
|
|
|
{ ".SINGLESHELL", SingleShell, 0 },
|
|
|
|
{ ".SUFFIXES", Suffixes, 0 },
|
|
|
|
{ ".USE", Attribute, OP_USE },
|
1996-10-06 02:35:38 +00:00
|
|
|
{ ".WAIT", Wait, 0 },
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
2002-03-22 01:33:25 +00:00
|
|
|
static int ParseFindKeyword(char *);
|
|
|
|
static int ParseDoOp(void *, void *);
|
|
|
|
static int ParseAddDep(void *, void *);
|
2004-12-07 13:49:13 +00:00
|
|
|
static void ParseDoSrc(int, char *, Lst *);
|
2002-03-22 01:33:25 +00:00
|
|
|
static int ParseFindMain(void *, void *);
|
|
|
|
static int ParseAddDir(void *, void *);
|
|
|
|
static int ParseClearPath(void *, void *);
|
|
|
|
static void ParseDoDependency(char *);
|
|
|
|
static int ParseAddCmd(void *, void *);
|
|
|
|
static int ParseReadc(void);
|
|
|
|
static void ParseUnreadc(int);
|
|
|
|
static void ParseHasCommands(void *);
|
|
|
|
static void ParseDoInclude(char *);
|
|
|
|
static void ParseDoError(char *);
|
2004-04-12 17:57:51 +00:00
|
|
|
static void ParseDoWarning(char *);
|
1994-05-27 12:33:43 +00:00
|
|
|
#ifdef SYSVINCLUDE
|
2002-03-22 01:33:25 +00:00
|
|
|
static void ParseTraditionalInclude(char *);
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif
|
2002-03-22 01:33:25 +00:00
|
|
|
static int ParseEOF(int);
|
|
|
|
static char *ParseReadLine(void);
|
2004-03-10 21:51:06 +00:00
|
|
|
static char *ParseSkipLine(int, int);
|
2002-03-22 01:33:25 +00:00
|
|
|
static void ParseFinishLine(void);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
* ParseFindKeyword --
|
|
|
|
* Look in the table of keywords for one matching the given string.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The index of the keyword, or -1 if it isn't there.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseFindKeyword(char *str)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-13 10:05:30 +00:00
|
|
|
int start,
|
1994-05-27 12:33:43 +00:00
|
|
|
end,
|
|
|
|
cur;
|
2002-04-13 10:05:30 +00:00
|
|
|
int diff;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
start = 0;
|
2004-11-30 17:46:29 +00:00
|
|
|
end = (sizeof(parseKeywords) / sizeof(parseKeywords[0])) - 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
cur = start + ((end - start) / 2);
|
2004-11-30 17:46:29 +00:00
|
|
|
diff = strcmp(str, parseKeywords[cur].name);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (diff == 0) {
|
|
|
|
return (cur);
|
|
|
|
} else if (diff < 0) {
|
|
|
|
end = cur - 1;
|
|
|
|
} else {
|
|
|
|
start = cur + 1;
|
|
|
|
}
|
|
|
|
} while (start <= end);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Parse_Error --
|
|
|
|
* Error message abort function for parsing. Prints out the context
|
|
|
|
* of the error (line number and file) as well as the message with
|
|
|
|
* two optional arguments.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* "fatals" is incremented if the level is PARSE_FATAL.
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
|
|
|
void
|
2002-06-12 04:11:01 +00:00
|
|
|
Parse_Error(int type, const char *fmt, ...)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2002-03-23 23:30:30 +00:00
|
|
|
va_start(ap, fmt);
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stderr, "\"%s\", line %d: ",
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.fname, curFile.lineno);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (type == PARSE_WARNING)
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stderr, "warning: ");
|
|
|
|
vfprintf(stderr, fmt, ap);
|
1994-05-27 12:33:43 +00:00
|
|
|
va_end(ap);
|
2004-11-30 17:46:29 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (type == PARSE_FATAL)
|
|
|
|
fatals += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseLinkSrc --
|
2005-03-03 10:07:28 +00:00
|
|
|
* Link the parent nodes to their new child. Used by
|
1994-05-27 12:33:43 +00:00
|
|
|
* ParseDoDependency. If the specType isn't 'Not', the parent
|
|
|
|
* isn't linked as a parent of the child.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2005-03-03 10:07:28 +00:00
|
|
|
* New elements are added to the parents lists of cgn and the
|
1994-05-27 12:33:43 +00:00
|
|
|
* children list of cgn. the unmade field of pgn is updated
|
|
|
|
* to reflect the additional child.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
2005-03-02 12:00:21 +00:00
|
|
|
static void
|
|
|
|
ParseLinkSrc(Lst *parents, GNode *cgn)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2005-03-02 12:00:21 +00:00
|
|
|
LstNode *ln;
|
|
|
|
GNode *pgn;
|
|
|
|
|
|
|
|
LST_FOREACH(ln, parents) {
|
|
|
|
pgn = Lst_Datum(ln);
|
|
|
|
if (Lst_Member(&pgn->children, cgn) == NULL) {
|
|
|
|
Lst_AtEnd(&pgn->children, cgn);
|
|
|
|
if (specType == Not) {
|
|
|
|
Lst_AtEnd(&cgn->parents, pgn);
|
|
|
|
}
|
|
|
|
pgn->unmade += 1;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoOp --
|
|
|
|
* Apply the parsed operator to the given target node. Used in a
|
|
|
|
* Lst_ForEach call by ParseDoDependency once all targets have
|
|
|
|
* been found and their operator parsed. If the previous and new
|
|
|
|
* operators are incompatible, a major error is taken.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Always 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The type field of the node is altered to reflect any new bits in
|
|
|
|
* the op.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseDoOp(void *gnp, void *opp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
GNode *gn = gnp;
|
|
|
|
int op = *(int *)opp;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If the dependency mask of the operator and the node don't match and
|
|
|
|
* the node has actually had an operator applied to it before, and
|
1995-05-30 06:41:30 +00:00
|
|
|
* the operator actually has some dependency information in it, complain.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) &&
|
|
|
|
!OP_NOP(gn->type) && !OP_NOP(op))
|
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name);
|
1994-05-27 12:33:43 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) {
|
|
|
|
/*
|
|
|
|
* If the node was the object of a :: operator, we need to create a
|
|
|
|
* new instance of it for the children and commands on this dependency
|
|
|
|
* line. The new instance is placed on the 'cohorts' list of the
|
|
|
|
* initial one (note the initial one is not on its own cohorts list)
|
|
|
|
* and the new instance is linked to all parents of the initial
|
|
|
|
* instance.
|
|
|
|
*/
|
2004-12-07 13:49:13 +00:00
|
|
|
GNode *cohort;
|
|
|
|
LstNode *ln;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
cohort = Targ_NewGN(gn->name);
|
|
|
|
/*
|
|
|
|
* Duplicate links to parents so graph traversal is simple. Perhaps
|
|
|
|
* some type bits should be duplicated?
|
|
|
|
*
|
|
|
|
* Make the cohort invisible as well to avoid duplicating it into
|
|
|
|
* other variables. True, parents of this target won't tend to do
|
|
|
|
* anything with their local variables, but better safe than
|
|
|
|
* sorry.
|
|
|
|
*/
|
2005-03-02 12:00:21 +00:00
|
|
|
ParseLinkSrc(&gn->parents, cohort);
|
1994-05-27 12:33:43 +00:00
|
|
|
cohort->type = OP_DOUBLEDEP|OP_INVISIBLE;
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&gn->cohorts, cohort);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace the node in the targets list with the new copy
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
ln = Lst_Member(&targets, gn);
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_Replace(ln, cohort);
|
1994-05-27 12:33:43 +00:00
|
|
|
gn = cohort;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We don't want to nuke any previous flags (whatever they were) so we
|
1995-05-30 06:41:30 +00:00
|
|
|
* just OR the new operator into the old
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
gn->type |= op;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseAddDep --
|
|
|
|
* Check if the pair of GNodes given needs to be synchronized.
|
|
|
|
* This has to be when two nodes are on different sides of a
|
|
|
|
* .WAIT directive.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Returns 1 if the two targets need to be ordered, 0 otherwise.
|
|
|
|
* If it returns 1, the search can stop
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A dependency can be added between the two nodes.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
1999-08-17 00:39:26 +00:00
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseAddDep(void *pp, void *sp)
|
1996-10-06 02:35:38 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
GNode *p = pp;
|
|
|
|
GNode *s = sp;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
if (p->order < s->order) {
|
|
|
|
/*
|
|
|
|
* XXX: This can cause loops, and loops can cause unmade targets,
|
|
|
|
* but checking is tedious, and the debugging output can show the
|
|
|
|
* problem
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&p->successors, s);
|
|
|
|
Lst_AtEnd(&s->preds, p);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
else
|
2004-11-30 17:46:29 +00:00
|
|
|
return (1);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoSrc --
|
|
|
|
* Given the name of a source, figure out if it is an attribute
|
|
|
|
* and apply it to the targets if it is. Else decide if there is
|
|
|
|
* some attribute which should be applied *to* the source because
|
|
|
|
* of some special target and apply it if so. Otherwise, make the
|
|
|
|
* source be a child of the targets in the list 'targets'
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Operator bits may be added to the list of targets or to the source.
|
|
|
|
* The targets may have a new source added to their lists of children.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2004-12-07 13:49:13 +00:00
|
|
|
ParseDoSrc(int tOp, char *src, Lst *allsrc)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-10-06 02:35:38 +00:00
|
|
|
GNode *gn = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-06-20 19:45:44 +00:00
|
|
|
if (*src == '.' && isupper ((unsigned char) src[1])) {
|
1994-05-27 12:33:43 +00:00
|
|
|
int keywd = ParseFindKeyword(src);
|
|
|
|
if (keywd != -1) {
|
1996-10-06 02:35:38 +00:00
|
|
|
int op = parseKeywords[keywd].op;
|
|
|
|
if (op != 0) {
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&targets, ParseDoOp, &op);
|
1996-10-06 02:35:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parseKeywords[keywd].spec == Wait) {
|
|
|
|
waiting++;
|
|
|
|
return;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
switch (specType) {
|
|
|
|
case Main:
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If we have noted the existence of a .MAIN, it means we need
|
|
|
|
* to add the sources of said target to the list of things
|
|
|
|
* to create. The string 'src' is likely to be free, so we
|
|
|
|
* must make a new copy of it. Note that this will only be
|
|
|
|
* invoked if the user didn't specify a target on the command
|
|
|
|
* line. This is to allow #ifmake's to succeed, or something...
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&create, estrdup(src));
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Add the name to the .TARGETS variable as well, so the user cna
|
|
|
|
* employ that, if desired.
|
|
|
|
*/
|
|
|
|
Var_Append(".TARGETS", src, VAR_GLOBAL);
|
1996-10-06 02:35:38 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case Order:
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Create proper predecessor/successor links between the previous
|
|
|
|
* source and the current one.
|
|
|
|
*/
|
|
|
|
gn = Targ_FindNode(src, TARG_CREATE);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (predecessor != NULL) {
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&predecessor->successors, gn);
|
|
|
|
Lst_AtEnd(&gn->preds, predecessor);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The current source now becomes the predecessor for the next one.
|
|
|
|
*/
|
|
|
|
predecessor = gn;
|
1996-10-06 02:35:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If the source is not an attribute, we need to find/create
|
|
|
|
* a node for it. After that we can apply any operator to it
|
|
|
|
* from a special target or link it to its parents, as
|
|
|
|
* appropriate.
|
|
|
|
*
|
|
|
|
* In the case of a source that was the object of a :: operator,
|
|
|
|
* the attribute is applied to all of its instances (as kept in
|
|
|
|
* the 'cohorts' list of the node) or all the cohorts are linked
|
|
|
|
* to all the targets.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
gn = Targ_FindNode(src, TARG_CREATE);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (tOp) {
|
|
|
|
gn->type |= tOp;
|
|
|
|
} else {
|
2005-03-02 12:00:21 +00:00
|
|
|
ParseLinkSrc(&targets, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
|
2002-04-13 10:05:30 +00:00
|
|
|
GNode *cohort;
|
2004-12-07 13:49:13 +00:00
|
|
|
LstNode *ln;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
for (ln = Lst_First(&gn->cohorts); ln != NULL; ln = Lst_Succ(ln)) {
|
2004-12-01 10:29:20 +00:00
|
|
|
cohort = Lst_Datum(ln);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (tOp) {
|
|
|
|
cohort->type |= tOp;
|
|
|
|
} else {
|
2005-03-02 12:00:21 +00:00
|
|
|
ParseLinkSrc(&targets, cohort);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-10-06 02:35:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gn->order = waiting;
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(allsrc, gn);
|
1996-10-06 02:35:38 +00:00
|
|
|
if (waiting) {
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_ForEach(allsrc, ParseAddDep, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseFindMain --
|
|
|
|
* Find a real target in the list and set it to be the main one.
|
|
|
|
* Called by ParseDoDependency when a main target hasn't been found
|
|
|
|
* yet.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* 0 if main not found yet, 1 if it is.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* mainNode is changed and Targ_SetMain is called.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseFindMain(void *gnp, void *dummy __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
GNode *gn = gnp;
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
if ((gn->type & (OP_NOTMAIN | OP_USE | OP_EXEC | OP_TRANSFORM)) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
mainNode = gn;
|
|
|
|
Targ_SetMain(gn);
|
2002-10-09 03:42:10 +00:00
|
|
|
return (1);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2002-10-09 03:42:10 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseAddDir --
|
|
|
|
* Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* === 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* See Dir_AddDir.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseAddDir(void *path, void *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
Dir_AddDir(path, name);
|
1994-05-27 12:33:43 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseClearPath --
|
|
|
|
* Front-end for Dir_ClearPath to make sure Lst_ForEach keeps going
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* === 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* See Dir_ClearPath
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseClearPath(void *path, void *dummy __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
Dir_ClearPath(path);
|
2002-10-09 03:42:10 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoDependency --
|
|
|
|
* Parse the dependency line in line.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The nodes of the sources are linked as children to the nodes of the
|
|
|
|
* targets. Some nodes may be created.
|
|
|
|
*
|
|
|
|
* We parse a dependency line by first extracting words from the line and
|
|
|
|
* finding nodes in the list of all targets with that name. This is done
|
|
|
|
* until a character is encountered which is an operator character. Currently
|
|
|
|
* these are only ! and :. At this point the operator is parsed and the
|
|
|
|
* pointer into the line advanced until the first source is encountered.
|
|
|
|
* The parsed operator is applied to each node in the 'targets' list,
|
|
|
|
* which is where the nodes found for the targets are kept, by means of
|
|
|
|
* the ParseDoOp function.
|
|
|
|
* The sources are read in much the same way as the targets were except
|
|
|
|
* that now they are expanded using the wildcarding scheme of the C-Shell
|
|
|
|
* and all instances of the resulting words in the list of all targets
|
|
|
|
* are found. Each of the resulting nodes is then linked to each of the
|
|
|
|
* targets as one of its children.
|
|
|
|
* Certain targets are handled specially. These are the ones detailed
|
|
|
|
* by the specType variable.
|
|
|
|
* The storing of transformation rules is also taken care of here.
|
|
|
|
* A target is recognized as a transformation rule by calling
|
|
|
|
* Suff_IsTransform. If it is a transformation rule, its node is gotten
|
|
|
|
* from the suffix module via Suff_AddTransform rather than the standard
|
|
|
|
* Targ_FindNode in the target module.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-04 12:38:57 +00:00
|
|
|
ParseDoDependency(char *line)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1995-01-23 21:03:17 +00:00
|
|
|
char *cp; /* our current position */
|
|
|
|
GNode *gn; /* a general purpose temporary node */
|
|
|
|
int op; /* the operator on the line */
|
1994-05-27 12:33:43 +00:00
|
|
|
char savec; /* a place to save a character */
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst paths; /* Search paths to alter when parsing a list of .PATH targets */
|
1994-05-27 12:33:43 +00:00
|
|
|
int tOp; /* operator from special target */
|
|
|
|
|
|
|
|
tOp = 0;
|
|
|
|
|
|
|
|
specType = Not;
|
1996-10-06 02:35:38 +00:00
|
|
|
waiting = 0;
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Init(&paths);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
do {
|
|
|
|
for (cp = line;
|
2004-12-01 10:29:20 +00:00
|
|
|
*cp && !isspace((unsigned char)*cp) && *cp != '(';
|
|
|
|
cp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
if (*cp == '$') {
|
|
|
|
/*
|
|
|
|
* Must be a dynamic source (would have been expanded
|
|
|
|
* otherwise), so call the Var module to parse the puppy
|
|
|
|
* so we can safely advance beyond it...There should be
|
|
|
|
* no errors in this, as they would have been discovered
|
|
|
|
* in the initial Var_Subst and we wouldn't be here.
|
|
|
|
*/
|
2005-03-01 17:52:18 +00:00
|
|
|
size_t length = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
Boolean freeIt;
|
|
|
|
char *result;
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
result = Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (freeIt) {
|
|
|
|
free(result);
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
cp += length - 1;
|
2002-08-20 12:50:32 +00:00
|
|
|
} else if (*cp == '!' || *cp == ':') {
|
|
|
|
/*
|
|
|
|
* We don't want to end a word on ':' or '!' if there is a
|
2002-11-28 12:47:56 +00:00
|
|
|
* better match later on in the string (greedy matching).
|
|
|
|
* This allows the user to have targets like:
|
2002-08-20 12:50:32 +00:00
|
|
|
* fie::fi:fo: fum
|
2002-11-28 12:47:56 +00:00
|
|
|
* foo::bar:
|
|
|
|
* where "fie::fi:fo" and "foo::bar" are the targets. In
|
|
|
|
* real life this is used for perl5 library man pages where
|
|
|
|
* "::" separates an object from its class.
|
|
|
|
* Ie: "File::Spec::Unix". This behaviour is also consistent
|
|
|
|
* with other versions of make.
|
2002-08-20 12:50:32 +00:00
|
|
|
*/
|
|
|
|
char *p = cp + 1;
|
|
|
|
|
2002-09-26 06:44:30 +00:00
|
|
|
if (*cp == ':' && *p == ':')
|
2002-08-20 12:50:32 +00:00
|
|
|
p++;
|
|
|
|
|
|
|
|
/* Found the best match already. */
|
|
|
|
if (*p == '\0' || isspace(*p))
|
|
|
|
break;
|
|
|
|
|
2002-11-28 12:47:56 +00:00
|
|
|
p += strcspn(p, "!:");
|
2002-08-20 12:50:32 +00:00
|
|
|
|
|
|
|
/* No better match later on... */
|
|
|
|
if (*p == '\0')
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp == '(') {
|
|
|
|
/*
|
|
|
|
* Archives must be handled specially to make sure the OP_ARCHV
|
|
|
|
* flag is set in their 'type' field, for one thing, and because
|
|
|
|
* things like "archive(file1.o file2.o file3.o)" are permissible.
|
|
|
|
* Arch_ParseArchive will set 'line' to be the first non-blank
|
|
|
|
* after the archive-spec. It creates/finds nodes for the members
|
|
|
|
* and places them on the given list, returning SUCCESS if all
|
|
|
|
* went well and FAILURE if there was an error in the
|
|
|
|
* specification. On error, line should remain untouched.
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
if (Arch_ParseArchive(&line, &targets, VAR_CMD) != SUCCESS) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Error in archive specification: \"%s\"", line);
|
|
|
|
return;
|
|
|
|
} else {
|
2005-03-03 10:09:39 +00:00
|
|
|
cp = line;
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
savec = *cp;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!*cp) {
|
|
|
|
/*
|
|
|
|
* Ending a dependency line without an operator is a Bozo
|
2002-06-20 19:44:34 +00:00
|
|
|
* no-no. As a heuristic, this is also often triggered by
|
|
|
|
* undetected conflicts from cvs/rcs merges.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2002-06-20 19:44:34 +00:00
|
|
|
if ((strncmp(line, "<<<<<<", 6) == 0) ||
|
|
|
|
(strncmp(line, "======", 6) == 0) ||
|
|
|
|
(strncmp(line, ">>>>>>", 6) == 0))
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
2002-06-20 19:44:34 +00:00
|
|
|
"Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
|
|
|
|
else
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Need an operator");
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
/*
|
|
|
|
* Have a word in line. See if it's a special target and set
|
|
|
|
* specType to match it.
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
if (*line == '.' && isupper((unsigned char)line[1])) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* See if the target is a special target that must have it
|
1995-05-30 06:41:30 +00:00
|
|
|
* or its sources handled specially.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int keywd = ParseFindKeyword(line);
|
|
|
|
if (keywd != -1) {
|
|
|
|
if (specType == ExPath && parseKeywords[keywd].spec != ExPath) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Mismatched special targets");
|
|
|
|
return;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
specType = parseKeywords[keywd].spec;
|
|
|
|
tOp = parseKeywords[keywd].op;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Certain special targets have special semantics:
|
|
|
|
* .PATH Have to set the dirSearchPath
|
|
|
|
* variable too
|
|
|
|
* .MAIN Its sources are only used if
|
|
|
|
* nothing has been specified to
|
|
|
|
* create.
|
|
|
|
* .DEFAULT Need to create a node to hang
|
|
|
|
* commands on, but we don't want
|
|
|
|
* it in the graph, nor do we want
|
|
|
|
* it to be the Main Target, so we
|
|
|
|
* create it, set OP_NOTMAIN and
|
|
|
|
* add it to the list, setting
|
|
|
|
* DEFAULT to the new node for
|
|
|
|
* later use. We claim the node is
|
|
|
|
* A transformation rule to make
|
|
|
|
* life easier later, when we'll
|
|
|
|
* use Make_HandleUse to actually
|
|
|
|
* apply the .DEFAULT commands.
|
1996-10-06 02:35:38 +00:00
|
|
|
* .PHONY The list of targets
|
1994-05-27 12:33:43 +00:00
|
|
|
* .BEGIN
|
|
|
|
* .END
|
|
|
|
* .INTERRUPT Are not to be considered the
|
|
|
|
* main target.
|
|
|
|
* .NOTPARALLEL Make only one target at a time.
|
|
|
|
* .SINGLESHELL Create a shell for each command.
|
2000-12-02 18:58:01 +00:00
|
|
|
* .ORDER Must set initial predecessor to NULL
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
switch (specType) {
|
|
|
|
case ExPath:
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&paths, &dirSearchPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Main:
|
2004-12-16 16:14:16 +00:00
|
|
|
if (!Lst_IsEmpty(&create)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
specType = Not;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case Interrupt:
|
|
|
|
gn = Targ_FindNode(line, TARG_CREATE);
|
|
|
|
gn->type |= OP_NOTMAIN;
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&targets, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Default:
|
|
|
|
gn = Targ_NewGN(".DEFAULT");
|
|
|
|
gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&targets, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
DEFAULT = gn;
|
|
|
|
break;
|
|
|
|
case NotParallel:
|
|
|
|
{
|
|
|
|
maxJobs = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SingleShell:
|
|
|
|
compatMake = 1;
|
|
|
|
break;
|
|
|
|
case Order:
|
2000-12-02 18:58:01 +00:00
|
|
|
predecessor = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
} else if (strncmp(line, ".PATH", 5) == 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* .PATH<suffix> has to be handled specially.
|
|
|
|
* Call on the suffix module to give us a path to
|
|
|
|
* modify.
|
|
|
|
*/
|
2004-12-07 13:49:13 +00:00
|
|
|
Lst *path;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
specType = ExPath;
|
2004-11-30 17:46:29 +00:00
|
|
|
path = Suff_GetPath(&line[5]);
|
2000-12-02 18:58:01 +00:00
|
|
|
if (path == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Suffix '%s' not defined (yet)",
|
|
|
|
&line[5]);
|
|
|
|
return;
|
2004-12-16 16:14:16 +00:00
|
|
|
} else
|
|
|
|
Lst_AtEnd(&paths, path);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Have word in line. Get or create its node and stick it at
|
1995-05-30 06:41:30 +00:00
|
|
|
* the end of the targets list
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
if ((specType == Not) && (*line != '\0')) {
|
2004-12-16 16:14:16 +00:00
|
|
|
/* target names to be found and added to targets list */
|
|
|
|
Lst curTargs = Lst_Initializer(curTargs);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (Dir_HasWildcards(line)) {
|
|
|
|
/*
|
|
|
|
* Targets are to be sought only in the current directory,
|
|
|
|
* so create an empty path for the thing. Note we need to
|
|
|
|
* use Dir_Destroy in the destruction of the path as the
|
|
|
|
* Dir module could have added a directory to the path...
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst emptyPath = Lst_Initializer(emptyPath);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Dir_Expand(line, &emptyPath, &curTargs);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&emptyPath, Dir_Destroy);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No wildcards, but we want to avoid code duplication,
|
|
|
|
* so create a list with the word on it.
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&curTargs, line);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
while (!Lst_IsEmpty(&curTargs)) {
|
|
|
|
char *targName = Lst_DeQueue(&curTargs);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!Suff_IsTransform (targName)) {
|
2004-11-30 17:46:29 +00:00
|
|
|
gn = Targ_FindNode(targName, TARG_CREATE);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
gn = Suff_AddTransform(targName);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&targets, gn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} else if (specType == ExPath && *line != '.' && *line != '\0') {
|
|
|
|
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp = savec;
|
|
|
|
/*
|
|
|
|
* If it is a special type and not .PATH, it's the only target we
|
|
|
|
* allow on this line...
|
|
|
|
*/
|
|
|
|
if (specType != Not && specType != ExPath) {
|
2005-02-04 07:51:00 +00:00
|
|
|
Boolean warnFlag = FALSE;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
while ((*cp != '!') && (*cp != ':') && *cp) {
|
|
|
|
if (*cp != ' ' && *cp != '\t') {
|
2005-02-04 07:51:00 +00:00
|
|
|
warnFlag = TRUE;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
2005-02-04 07:51:00 +00:00
|
|
|
if (warnFlag) {
|
1994-05-27 12:33:43 +00:00
|
|
|
Parse_Error(PARSE_WARNING, "Extra target ignored");
|
|
|
|
}
|
|
|
|
} else {
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
} while ((*line != '!') && (*line != ':') && *line);
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
if (!Lst_IsEmpty(&targets)) {
|
2004-12-01 10:29:20 +00:00
|
|
|
switch (specType) {
|
1994-05-27 12:33:43 +00:00
|
|
|
default:
|
|
|
|
Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored");
|
|
|
|
break;
|
|
|
|
case Default:
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case Interrupt:
|
|
|
|
/*
|
|
|
|
* These four create nodes on which to hang commands, so
|
|
|
|
* targets shouldn't be empty...
|
|
|
|
*/
|
|
|
|
case Not:
|
|
|
|
/*
|
|
|
|
* Nothing special here -- targets can be empty if it wants.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Have now parsed all the target names. Must parse the operator next. The
|
|
|
|
* result is left in op .
|
|
|
|
*/
|
|
|
|
if (*cp == '!') {
|
|
|
|
op = OP_FORCE;
|
|
|
|
} else if (*cp == ':') {
|
|
|
|
if (cp[1] == ':') {
|
|
|
|
op = OP_DOUBLEDEP;
|
|
|
|
cp++;
|
|
|
|
} else {
|
|
|
|
op = OP_DEPENDS;
|
|
|
|
}
|
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Missing dependency operator");
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp++; /* Advance beyond operator */
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&targets, ParseDoOp, &op);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Get to the first source
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Several special targets take different actions if present with no
|
|
|
|
* sources:
|
|
|
|
* a .SUFFIXES line with no sources clears out all old suffixes
|
|
|
|
* a .PRECIOUS line makes all targets precious
|
|
|
|
* a .IGNORE line ignores errors for all targets
|
|
|
|
* a .SILENT line creates silence when making all targets
|
|
|
|
* a .PATH removes all directories from the search path(s).
|
|
|
|
*/
|
|
|
|
if (!*line) {
|
|
|
|
switch (specType) {
|
|
|
|
case Suffixes:
|
2004-11-30 17:46:29 +00:00
|
|
|
Suff_ClearSuffixes();
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Precious:
|
|
|
|
allPrecious = TRUE;
|
|
|
|
break;
|
|
|
|
case Ignore:
|
|
|
|
ignoreErrors = TRUE;
|
|
|
|
break;
|
|
|
|
case Silent:
|
|
|
|
beSilent = TRUE;
|
|
|
|
break;
|
|
|
|
case ExPath:
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&paths, ParseClearPath, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
1996-11-03 03:29:57 +00:00
|
|
|
case Posix:
|
|
|
|
Var_Set("%POSIX", "1003.2", VAR_GLOBAL);
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (specType == MFlags) {
|
|
|
|
/*
|
|
|
|
* Call on functions in main.c to deal with these arguments and
|
|
|
|
* set the initial character to a null-character so the loop to
|
|
|
|
* get sources won't get anything
|
|
|
|
*/
|
2005-01-26 18:19:39 +00:00
|
|
|
Main_ParseArgLine(line, 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
*line = '\0';
|
|
|
|
} else if (specType == ExShell) {
|
2004-11-30 17:46:29 +00:00
|
|
|
if (Job_ParseShell(line) != SUCCESS) {
|
|
|
|
Parse_Error(PARSE_FATAL, "improper shell specification");
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*line = '\0';
|
|
|
|
} else if ((specType == NotParallel) || (specType == SingleShell)) {
|
|
|
|
*line = '\0';
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* NOW GO FOR THE SOURCES
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
if ((specType == Suffixes) || (specType == ExPath) ||
|
|
|
|
(specType == Includes) || (specType == Libs) ||
|
|
|
|
(specType == Null))
|
|
|
|
{
|
|
|
|
while (*line) {
|
|
|
|
/*
|
|
|
|
* If the target was one that doesn't take files as its sources
|
|
|
|
* but takes something like suffixes, we take each
|
|
|
|
* space-separated word on the line as a something and deal
|
|
|
|
* with it accordingly.
|
|
|
|
*
|
|
|
|
* If the target was .SUFFIXES, we take each source as a
|
|
|
|
* suffix and add it to the list of suffixes maintained by the
|
|
|
|
* Suff module.
|
|
|
|
*
|
|
|
|
* If the target was a .PATH, we add the source as a directory
|
|
|
|
* to search on the search path.
|
|
|
|
*
|
|
|
|
* If it was .INCLUDES, the source is taken to be the suffix of
|
|
|
|
* files which will be #included and whose search path should
|
|
|
|
* be present in the .INCLUDES variable.
|
|
|
|
*
|
|
|
|
* If it was .LIBS, the source is taken to be the suffix of
|
|
|
|
* files which are considered libraries and whose search path
|
|
|
|
* should be present in the .LIBS variable.
|
|
|
|
*
|
|
|
|
* If it was .NULL, the source is the suffix to use when a file
|
|
|
|
* has no valid suffix.
|
|
|
|
*/
|
2002-09-28 23:35:07 +00:00
|
|
|
char savech;
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && !isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
2002-09-28 23:35:07 +00:00
|
|
|
savech = *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp = '\0';
|
|
|
|
switch (specType) {
|
|
|
|
case Suffixes:
|
2004-11-30 17:46:29 +00:00
|
|
|
Suff_AddSuffix(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case ExPath:
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&paths, ParseAddDir, line);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Includes:
|
2004-11-30 17:46:29 +00:00
|
|
|
Suff_AddInclude(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Libs:
|
2004-11-30 17:46:29 +00:00
|
|
|
Suff_AddLib(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case Null:
|
2004-11-30 17:46:29 +00:00
|
|
|
Suff_SetNull(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2002-09-28 23:35:07 +00:00
|
|
|
*cp = savech;
|
|
|
|
if (savech != '\0') {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
}
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&paths, NOFREE);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst curSrcs = Lst_Initializer(curSrc); /* list of sources in order */
|
2005-02-04 12:38:57 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
while (*line) {
|
|
|
|
/*
|
|
|
|
* The targets take real sources, so we must beware of archive
|
|
|
|
* specifications (i.e. things with left parentheses in them)
|
|
|
|
* and handle them accordingly.
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && !isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if ((*cp == '(') && (cp > line) && (cp[-1] != '$')) {
|
|
|
|
/*
|
|
|
|
* Only stop for a left parenthesis if it isn't at the
|
|
|
|
* start of a word (that'll be for variable changes
|
|
|
|
* later) and isn't preceded by a dollar sign (a dynamic
|
|
|
|
* source).
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cp == '(') {
|
2002-09-28 23:35:07 +00:00
|
|
|
GNode *gnp;
|
2004-12-16 16:14:16 +00:00
|
|
|
/* list of archive source names after expansion */
|
|
|
|
Lst sources = Lst_Initializer(sources);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
if (Arch_ParseArchive(&line, &sources, VAR_CMD) != SUCCESS) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Error in source archive spec \"%s\"", line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
while (!Lst_IsEmpty(&sources)) {
|
|
|
|
gnp = Lst_DeQueue(&sources);
|
|
|
|
ParseDoSrc(tOp, gnp->name, &curSrcs);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cp = line;
|
|
|
|
} else {
|
|
|
|
if (*cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp += 1;
|
|
|
|
}
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
ParseDoSrc(tOp, line, &curSrcs);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-12-01 10:29:20 +00:00
|
|
|
while (*cp && isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
}
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&curSrcs, NOFREE);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if (mainNode == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If we have yet to decide on a main target to make, in the
|
|
|
|
* absence of any user input, we want the first target on
|
|
|
|
* the first dependency line that is actually a real target
|
|
|
|
* (i.e. isn't a .USE or .EXEC rule) to be made.
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&targets, ParseFindMain, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_IsVar --
|
|
|
|
* Return TRUE if the passed line is a variable assignment. A variable
|
|
|
|
* assignment consists of a single word followed by optional whitespace
|
|
|
|
* followed by either a += or an = operator.
|
|
|
|
* This function is used both by the Parse_File function and main when
|
|
|
|
* parsing the command-line arguments.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE if it is. FALSE if it ain't
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* none
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_IsVar(char *line)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-13 10:05:30 +00:00
|
|
|
Boolean wasSpace = FALSE; /* set TRUE if found a space */
|
|
|
|
Boolean haveName = FALSE; /* Set TRUE if have a variable name */
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
int level = 0;
|
2002-09-17 21:29:06 +00:00
|
|
|
#define ISEQOPERATOR(c) \
|
1996-10-06 02:35:38 +00:00
|
|
|
(((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to variable name
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
for (; (*line == ' ') || (*line == '\t'); line++)
|
1996-10-06 02:35:38 +00:00
|
|
|
continue;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
for (; *line != '=' || level != 0; line++)
|
|
|
|
switch (*line) {
|
|
|
|
case '\0':
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* end-of-line -- can't be a variable assignment.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* there can be as much white space as desired so long as there is
|
1995-05-30 06:41:30 +00:00
|
|
|
* only one word before the operator
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
wasSpace = TRUE;
|
1996-10-06 02:35:38 +00:00
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
case '(':
|
|
|
|
case '{':
|
|
|
|
level++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '}':
|
|
|
|
case ')':
|
|
|
|
level--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (wasSpace && haveName) {
|
|
|
|
if (ISEQOPERATOR(*line)) {
|
|
|
|
/*
|
|
|
|
* We must have a finished word
|
|
|
|
*/
|
|
|
|
if (level != 0)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When an = operator [+?!:] is found, the next
|
|
|
|
* character must be an = or it ain't a valid
|
|
|
|
* assignment.
|
|
|
|
*/
|
|
|
|
if (line[1] == '=')
|
2004-11-30 17:46:29 +00:00
|
|
|
return (haveName);
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef SUNSHCMD
|
|
|
|
/*
|
|
|
|
* This is a shell command
|
|
|
|
*/
|
|
|
|
if (strncmp(line, ":sh", 3) == 0)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (haveName);
|
1996-10-06 02:35:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* This is the start of another word, so not assignment.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
return (FALSE);
|
1996-10-06 02:35:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
haveName = TRUE;
|
|
|
|
wasSpace = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
return (haveName);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_DoVar --
|
|
|
|
* Take the variable assignment in the passed line and do it in the
|
|
|
|
* global context.
|
|
|
|
*
|
|
|
|
* Note: There is a lexical ambiguity with assignment modifier characters
|
|
|
|
* in variable names. This routine interprets the character before the =
|
|
|
|
* as a modifier. Therefore, an assignment like
|
|
|
|
* C++=/usr/bin/CC
|
|
|
|
* is interpreted as "C+ +=" instead of "C++ =".
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* the variable structure of the given variable name is altered in the
|
|
|
|
* global context.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_DoVar(char *line, GNode *ctxt)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1995-01-23 21:03:17 +00:00
|
|
|
char *cp; /* pointer into line */
|
1994-05-27 12:33:43 +00:00
|
|
|
enum {
|
|
|
|
VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL
|
|
|
|
} type; /* Type of assignment */
|
1995-05-30 06:41:30 +00:00
|
|
|
char *opc; /* ptr to operator character to
|
1994-05-27 12:33:43 +00:00
|
|
|
* null-terminate the variable name */
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
|
|
|
|
1995-05-30 06:41:30 +00:00
|
|
|
/*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Avoid clobbered variable warnings by forcing the compiler
|
|
|
|
* to ``unregister'' variables
|
1995-01-23 21:03:17 +00:00
|
|
|
*/
|
1994-05-27 12:33:43 +00:00
|
|
|
#if __GNUC__
|
2004-11-30 17:46:29 +00:00
|
|
|
(void)&cp;
|
|
|
|
(void)&line;
|
1995-01-23 21:03:17 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to variable name
|
|
|
|
*/
|
|
|
|
while ((*line == ' ') || (*line == '\t')) {
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to operator character, nulling out whitespace as we go
|
|
|
|
*/
|
|
|
|
for (cp = line + 1; *cp != '='; cp++) {
|
2004-12-01 10:29:20 +00:00
|
|
|
if (isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
opc = cp - 1; /* operator is the previous character */
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp++ = '\0'; /* nuke the = */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check operator type
|
|
|
|
*/
|
|
|
|
switch (*opc) {
|
|
|
|
case '+':
|
|
|
|
type = VAR_APPEND;
|
|
|
|
*opc = '\0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
/*
|
|
|
|
* If the variable already has a value, we don't do anything.
|
|
|
|
*/
|
|
|
|
*opc = '\0';
|
|
|
|
if (Var_Exists(line, ctxt)) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
type = VAR_NORMAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ':':
|
|
|
|
type = VAR_SUBST;
|
|
|
|
*opc = '\0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '!':
|
|
|
|
type = VAR_SHELL;
|
|
|
|
*opc = '\0';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1996-10-06 02:35:38 +00:00
|
|
|
#ifdef SUNSHCMD
|
|
|
|
while (*opc != ':')
|
1999-01-08 18:37:34 +00:00
|
|
|
if (opc == line)
|
1996-10-06 02:35:38 +00:00
|
|
|
break;
|
1999-01-08 18:37:34 +00:00
|
|
|
else
|
|
|
|
--opc;
|
1996-10-06 02:35:38 +00:00
|
|
|
|
|
|
|
if (strncmp(opc, ":sh", 3) == 0) {
|
|
|
|
type = VAR_SHELL;
|
|
|
|
*opc = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
type = VAR_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
while (isspace((unsigned char)*cp)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == VAR_APPEND) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Var_Append(line, cp, ctxt);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (type == VAR_SUBST) {
|
|
|
|
/*
|
|
|
|
* Allow variables in the old value to be undefined, but leave their
|
|
|
|
* invocation alone -- this is done by forcing oldVars to be false.
|
|
|
|
* XXX: This can cause recursive variables, but that's not hard to do,
|
|
|
|
* and this allows someone to do something like
|
|
|
|
*
|
|
|
|
* CFLAGS = $(.INCLUDES)
|
|
|
|
* CFLAGS := -I.. $(CFLAGS)
|
|
|
|
*
|
|
|
|
* And not get an error.
|
|
|
|
*/
|
|
|
|
Boolean oldOldVars = oldVars;
|
|
|
|
|
|
|
|
oldVars = FALSE;
|
2002-06-20 19:51:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure that we set the variable the first time to nothing
|
|
|
|
* so that it gets substituted!
|
|
|
|
*/
|
|
|
|
if (!Var_Exists(line, ctxt))
|
|
|
|
Var_Set(line, "", ctxt);
|
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, cp, ctxt, FALSE);
|
|
|
|
cp = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
oldVars = oldOldVars;
|
|
|
|
|
|
|
|
Var_Set(line, cp, ctxt);
|
|
|
|
free(cp);
|
|
|
|
} else if (type == VAR_SHELL) {
|
1996-10-06 02:35:38 +00:00
|
|
|
Boolean freeCmd = FALSE; /* TRUE if the command needs to be freed, i.e.
|
|
|
|
* if any variable expansion was performed */
|
2005-02-07 11:27:47 +00:00
|
|
|
Buffer *buf;
|
2005-02-04 07:51:00 +00:00
|
|
|
const char *error;
|
1995-01-23 21:03:17 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (strchr(cp, '$') != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* There's a dollar sign in the command, so perform variable
|
|
|
|
* expansion on the whole thing. The resulting string will need
|
|
|
|
* freeing when we're done, so set freeCmd to TRUE.
|
|
|
|
*/
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, cp, VAR_CMD, TRUE);
|
|
|
|
cp = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
freeCmd = TRUE;
|
|
|
|
}
|
|
|
|
|
2005-02-07 11:27:47 +00:00
|
|
|
buf = Cmd_Exec(cp, &error);
|
|
|
|
Var_Set(line, Buf_GetAll(buf, NULL), ctxt);
|
|
|
|
Buf_Destroy(buf, TRUE);
|
1996-09-12 03:03:25 +00:00
|
|
|
|
2002-09-28 23:35:07 +00:00
|
|
|
if (error)
|
|
|
|
Parse_Error(PARSE_WARNING, error, cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
if (freeCmd)
|
|
|
|
free(cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Normal assignment -- just do it.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
Var_Set(line, cp, ctxt);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* ParseAddCmd --
|
|
|
|
* Lst_ForEach function to add a command line to all targets
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Always 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A new element is added to the commands list of the node.
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseAddCmd(void *gnp, void *cmd)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
GNode *gn = gnp;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
/* if target already supplied, ignore commands */
|
|
|
|
if (!(gn->type & OP_HAS_COMMANDS))
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtEnd(&gn->commands, cmd);
|
2002-07-28 03:52:41 +00:00
|
|
|
else
|
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"duplicate script for target \"%s\" ignored",
|
|
|
|
gn->name);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseHasCommands --
|
|
|
|
* Callback procedure for Parse_File when destroying the list of
|
|
|
|
* targets on the last dependency line. Marks a target as already
|
|
|
|
* having commands if it does, to keep from having shell commands
|
|
|
|
* on multiple dependency lines.
|
|
|
|
*
|
|
|
|
* Results:
|
1995-01-23 21:03:17 +00:00
|
|
|
* None
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* OP_HAS_COMMANDS may be set for the target.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
1995-01-23 21:03:17 +00:00
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseHasCommands(void *gnp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-12-01 10:29:20 +00:00
|
|
|
GNode *gn = gnp;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
if (!Lst_IsEmpty(&gn->commands)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
gn->type |= OP_HAS_COMMANDS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Parse_AddIncludeDir --
|
|
|
|
* Add a directory to the path searched for included makefiles
|
|
|
|
* bracketed by double-quotes. Used by functions in main.c
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The directory is appended to the list.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_AddIncludeDir(char *dir)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Dir_AddDir(&parseIncPath, dir);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1998-05-25 03:28:37 +00:00
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
* ParseDoError --
|
|
|
|
* Handle error directive
|
|
|
|
*
|
|
|
|
* The input is the line minus the ".error". We substitute variables,
|
|
|
|
* print the message and exit(1) or just print a warning if the ".error"
|
|
|
|
* directive is malformed.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseDoError(char *errmsg)
|
1998-05-25 03:28:37 +00:00
|
|
|
{
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
|
|
|
if (!isspace((unsigned char)*errmsg)) {
|
1998-05-25 03:28:37 +00:00
|
|
|
Parse_Error(PARSE_WARNING, "invalid syntax: .error%s", errmsg);
|
|
|
|
return;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
|
|
|
|
while (isspace((unsigned char)*errmsg))
|
1998-05-25 03:28:37 +00:00
|
|
|
errmsg++;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, errmsg, VAR_GLOBAL, FALSE);
|
|
|
|
errmsg = Buf_GetAll(buf, NULL);
|
1998-05-25 03:28:37 +00:00
|
|
|
|
2004-04-12 17:57:51 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "%s", errmsg);
|
2005-02-25 13:16:56 +00:00
|
|
|
Buf_Destroy(buf, TRUE);
|
|
|
|
|
2004-04-12 17:57:51 +00:00
|
|
|
/* Terminate immediately. */
|
1998-05-25 03:28:37 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-04-12 17:57:51 +00:00
|
|
|
/*---------------------------------------------------------------------
|
|
|
|
* ParseDoWarning --
|
|
|
|
* Handle warning directive
|
|
|
|
*
|
|
|
|
* The input is the line minus the ".warning". We substitute variables
|
|
|
|
* and print the message or just print a warning if the ".warning"
|
|
|
|
* directive is malformed.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ParseDoWarning(char *warnmsg)
|
|
|
|
{
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
|
|
|
if (!isspace((unsigned char)*warnmsg)) {
|
2004-04-12 17:57:51 +00:00
|
|
|
Parse_Error(PARSE_WARNING, "invalid syntax: .warning%s",
|
|
|
|
warnmsg);
|
|
|
|
return;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
|
|
|
|
while (isspace((unsigned char)*warnmsg))
|
2004-04-12 17:57:51 +00:00
|
|
|
warnmsg++;
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, warnmsg, VAR_GLOBAL, FALSE);
|
|
|
|
warnmsg = Buf_GetAll(buf, NULL);
|
2004-04-12 17:57:51 +00:00
|
|
|
|
|
|
|
Parse_Error(PARSE_WARNING, "%s", warnmsg);
|
2005-02-25 13:16:56 +00:00
|
|
|
Buf_Destroy(buf, TRUE);
|
2004-04-12 17:57:51 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoInclude --
|
|
|
|
* Push to another file.
|
1995-05-30 06:41:30 +00:00
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* The input is the line minus the #include. A file spec is a string
|
|
|
|
* enclosed in <> or "". The former is looked for only in sysIncPath.
|
|
|
|
* The latter in . and the directories specified by -I command line
|
|
|
|
* options
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2004-03-10 21:51:06 +00:00
|
|
|
* A structure is added to the includes Lst and readProc, curFile.lineno,
|
|
|
|
* curFile.fname and curFile.F are altered for the new file
|
1994-05-27 12:33:43 +00:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-04 12:38:57 +00:00
|
|
|
ParseDoInclude(char *file)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *fullname; /* full pathname of file */
|
|
|
|
IFile *oldFile; /* state associated with current file */
|
|
|
|
char endc; /* the character which ends the file spec */
|
|
|
|
char *cp; /* current position in file spec */
|
|
|
|
Boolean isSystem; /* TRUE if makefile is a system makefile */
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to delimiter character so we know where to look
|
|
|
|
*/
|
|
|
|
while ((*file == ' ') || (*file == '\t')) {
|
|
|
|
file++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*file != '"') && (*file != '<')) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
".include filename must be delimited by '\"' or '<'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the search path on which to find the include file based on the
|
|
|
|
* characters which bracket its name. Angle-brackets imply it's
|
|
|
|
* a system Makefile while double-quotes imply it's a user makefile
|
|
|
|
*/
|
|
|
|
if (*file == '<') {
|
|
|
|
isSystem = TRUE;
|
|
|
|
endc = '>';
|
|
|
|
} else {
|
|
|
|
isSystem = FALSE;
|
|
|
|
endc = '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to matching delimiter
|
|
|
|
*/
|
|
|
|
for (cp = ++file; *cp && *cp != endc; cp++) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cp != endc) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Unclosed %cinclude filename. '%c' expected",
|
|
|
|
'.', endc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
|
|
|
file = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we know the file's name and its search path, we attempt to
|
|
|
|
* find the durn thing. A return of NULL indicates the file don't
|
|
|
|
* exist.
|
|
|
|
*/
|
|
|
|
if (!isSystem) {
|
|
|
|
/*
|
|
|
|
* Include files contained in double-quotes are first searched for
|
|
|
|
* relative to the including file's location. We don't want to
|
|
|
|
* cd there, of course, so we just tack on the old file's
|
|
|
|
* leading path components and call Dir_FindFile to see if
|
|
|
|
* we can locate the beast.
|
|
|
|
*/
|
1996-10-06 02:35:38 +00:00
|
|
|
char *prefEnd, *Fname;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-10-06 02:35:38 +00:00
|
|
|
/* Make a temporary copy of this, to be safe. */
|
2004-03-10 21:51:06 +00:00
|
|
|
Fname = estrdup(curFile.fname);
|
1996-10-06 02:35:38 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
prefEnd = strrchr(Fname, '/');
|
1994-05-27 12:33:43 +00:00
|
|
|
if (prefEnd != (char *)NULL) {
|
|
|
|
char *newName;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
*prefEnd = '\0';
|
1995-01-23 21:03:17 +00:00
|
|
|
if (file[0] == '/')
|
1996-10-06 02:35:38 +00:00
|
|
|
newName = estrdup(file);
|
1995-01-23 21:03:17 +00:00
|
|
|
else
|
2004-11-30 17:46:29 +00:00
|
|
|
newName = str_concat(Fname, file, STR_ADDSLASH);
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(newName, &parseIncPath);
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(newName, &dirSearchPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
free(newName);
|
1994-05-27 12:33:43 +00:00
|
|
|
*prefEnd = '/';
|
|
|
|
} else {
|
2004-12-01 10:29:20 +00:00
|
|
|
fullname = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
free(Fname);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
2004-12-01 10:29:20 +00:00
|
|
|
fullname = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* System makefile or makefile wasn't found in same directory as
|
|
|
|
* included makefile. Search for it first on the -I search path,
|
|
|
|
* then on the .PATH search path, if not found in a -I directory.
|
|
|
|
* XXX: Suffix specific?
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &parseIncPath);
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &dirSearchPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Still haven't found the makefile. Look for it on the system
|
|
|
|
* path as a last resort.
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &sysIncPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp = endc;
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Could not find %s", file);
|
2005-02-25 13:16:56 +00:00
|
|
|
/* XXXHB free(file) */
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
free(file);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Once we find the absolute path to the file, we get to save all the
|
|
|
|
* state from the current file before we can start reading this
|
|
|
|
* include file. The state is stored in an IFile structure which
|
|
|
|
* is placed on a list with other IFile structures. The list makes
|
|
|
|
* a very nice stack to track how we got here...
|
|
|
|
*/
|
2005-02-04 12:38:57 +00:00
|
|
|
oldFile = emalloc(sizeof(IFile));
|
2004-12-01 10:29:20 +00:00
|
|
|
memcpy(oldFile, &curFile, sizeof(IFile));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtFront(&includes, oldFile);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Once the previous state has been saved, we can get down to reading
|
|
|
|
* the new file. We set up the name of the file to be the absolute
|
|
|
|
* name of the include file so error messages refer to the right
|
|
|
|
* place. Naturally enough, we start reading at line number 0.
|
|
|
|
*/
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.fname = fullname;
|
|
|
|
curFile.lineno = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
curFile.F = fopen(fullname, "r");
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.p = NULL;
|
2004-12-01 10:29:20 +00:00
|
|
|
if (curFile.F == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Pop to previous file
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseEOF(0);
|
2004-07-02 12:30:28 +00:00
|
|
|
} else {
|
|
|
|
Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_FromString --
|
|
|
|
* Start Parsing from the given string
|
1995-05-30 06:41:30 +00:00
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2004-03-10 21:51:06 +00:00
|
|
|
* A structure is added to the includes Lst and readProc, curFile.lineno,
|
|
|
|
* curFile.fname and curFile.F are altered for the new file
|
1994-05-27 12:33:43 +00:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-03-10 21:51:06 +00:00
|
|
|
Parse_FromString(char *str, int lineno)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
IFile *oldFile; /* state associated with this file */
|
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
DEBUGF(FOR, ("%s\n---- at line %d\n", str, lineno));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
oldFile = emalloc(sizeof(IFile));
|
2004-11-30 17:46:29 +00:00
|
|
|
memcpy(oldFile, &curFile, sizeof(IFile));
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtFront(&includes, oldFile);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.F = NULL;
|
2005-02-04 12:38:57 +00:00
|
|
|
curFile.p = emalloc(sizeof(PTR));
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.p->str = curFile.p->ptr = str;
|
|
|
|
curFile.lineno = lineno;
|
|
|
|
curFile.fname = estrdup(curFile.fname);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SYSVINCLUDE
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseTraditionalInclude --
|
|
|
|
* Push to another file.
|
1995-05-30 06:41:30 +00:00
|
|
|
*
|
1994-05-27 12:33:43 +00:00
|
|
|
* The input is the line minus the "include". The file name is
|
|
|
|
* the string following the "include".
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2004-03-10 21:51:06 +00:00
|
|
|
* A structure is added to the includes Lst and readProc, curFile.lineno,
|
|
|
|
* curFile.fname and curFile.F are altered for the new file
|
1994-05-27 12:33:43 +00:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2005-02-04 12:38:57 +00:00
|
|
|
ParseTraditionalInclude(char *file)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *fullname; /* full pathname of file */
|
|
|
|
IFile *oldFile; /* state associated with current file */
|
|
|
|
char *cp; /* current position in file spec */
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over whitespace
|
|
|
|
*/
|
|
|
|
while ((*file == ' ') || (*file == '\t')) {
|
|
|
|
file++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*file == '\0') {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Filename missing from \"include\"");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to end of line or next whitespace
|
|
|
|
*/
|
|
|
|
for (cp = file; *cp && *cp != '\n' && *cp != '\t' && *cp != ' '; cp++) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
|
|
|
file = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we know the file's name, we attempt to find the durn thing.
|
2002-10-23 01:57:33 +00:00
|
|
|
* Search for it first on the -I search path, then on the .PATH
|
|
|
|
* search path, if not found in a -I directory.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &parseIncPath);
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &dirSearchPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Still haven't found the makefile. Look for it on the system
|
|
|
|
* path as a last resort.
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
fullname = Dir_FindFile(file, &sysIncPath);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 10:29:20 +00:00
|
|
|
if (fullname == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Could not find %s", file);
|
2005-02-25 13:16:56 +00:00
|
|
|
/* XXXHB free(file) */
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
/* XXXHB free(file) */
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Once we find the absolute path to the file, we get to save all the
|
|
|
|
* state from the current file before we can start reading this
|
|
|
|
* include file. The state is stored in an IFile structure which
|
|
|
|
* is placed on a list with other IFile structures. The list makes
|
|
|
|
* a very nice stack to track how we got here...
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
oldFile = emalloc(sizeof(IFile));
|
2004-11-30 17:46:29 +00:00
|
|
|
memcpy(oldFile, &curFile, sizeof(IFile));
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_AtFront(&includes, oldFile);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Once the previous state has been saved, we can get down to reading
|
|
|
|
* the new file. We set up the name of the file to be the absolute
|
|
|
|
* name of the include file so error messages refer to the right
|
|
|
|
* place. Naturally enough, we start reading at line number 0.
|
|
|
|
*/
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.fname = fullname;
|
|
|
|
curFile.lineno = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
curFile.F = fopen(fullname, "r");
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.p = NULL;
|
2004-12-01 10:29:20 +00:00
|
|
|
if (curFile.F == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Pop to previous file
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseEOF(1);
|
2004-07-02 12:30:28 +00:00
|
|
|
} else {
|
|
|
|
Var_Append(".MAKEFILE_LIST", fullname, VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseEOF --
|
|
|
|
* Called when EOF is reached in the current file. If we were reading
|
|
|
|
* an include file, the includes stack is popped and things set up
|
|
|
|
* to go back to reading the previous file at the previous location.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* CONTINUE if there's more to do. DONE if not.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2004-03-10 21:51:06 +00:00
|
|
|
* The old curFile.F is closed. The includes list is shortened.
|
|
|
|
* curFile.lineno, curFile.F, and curFile.fname are changed if
|
|
|
|
* CONTINUE is returned.
|
1994-05-27 12:33:43 +00:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseEOF(int opened)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
IFile *ifile; /* the state on the top of the includes stack */
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
if (Lst_IsEmpty(&includes)) {
|
2004-07-02 12:30:28 +00:00
|
|
|
Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
return (DONE);
|
|
|
|
}
|
|
|
|
|
2004-12-16 16:14:16 +00:00
|
|
|
ifile = Lst_DeQueue(&includes);
|
2004-11-30 17:46:29 +00:00
|
|
|
free(curFile.fname);
|
2004-07-02 12:30:28 +00:00
|
|
|
if (opened && curFile.F) {
|
2004-11-30 17:46:29 +00:00
|
|
|
fclose(curFile.F);
|
2004-07-02 12:30:28 +00:00
|
|
|
Var_Append(".MAKEFILE_LIST", "..", VAR_GLOBAL);
|
|
|
|
}
|
2004-03-10 21:51:06 +00:00
|
|
|
if (curFile.p) {
|
|
|
|
free(curFile.p->str);
|
|
|
|
free(curFile.p);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
memcpy(&curFile, ifile, sizeof(IFile));
|
|
|
|
free(ifile);
|
1994-05-27 12:33:43 +00:00
|
|
|
return (CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseReadc --
|
1995-05-30 06:41:30 +00:00
|
|
|
* Read a character from the current file
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The character that was read
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseReadc(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
if (curFile.F)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (fgetc(curFile.F));
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
if (curFile.p && *curFile.p->ptr)
|
2004-11-30 17:46:29 +00:00
|
|
|
return (*curFile.p->ptr++);
|
|
|
|
return (EOF);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseUnreadc --
|
1995-05-30 06:41:30 +00:00
|
|
|
* Put back a character to the current file
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseUnreadc(int c)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
if (curFile.F) {
|
|
|
|
ungetc(c, curFile.F);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-10 21:51:06 +00:00
|
|
|
if (curFile.p) {
|
|
|
|
*--(curFile.p->ptr) = c;
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ParseSkipLine():
|
2002-10-09 03:42:10 +00:00
|
|
|
* Grab the next line unless it begins with a dot (`.') and we're told to
|
|
|
|
* ignore such lines.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
static char *
|
2004-03-10 21:51:06 +00:00
|
|
|
ParseSkipLine(int skip, int keep_newline)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *line;
|
2004-12-03 12:55:57 +00:00
|
|
|
int c, lastc;
|
2005-02-02 07:36:18 +00:00
|
|
|
Buffer *buf;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-09-22 02:28:36 +00:00
|
|
|
buf = Buf_Init(MAKE_BSIZE);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1996-09-22 02:28:36 +00:00
|
|
|
do {
|
2005-02-04 13:34:16 +00:00
|
|
|
Buf_Clear(buf);
|
1996-09-22 02:28:36 +00:00
|
|
|
lastc = '\0';
|
|
|
|
|
|
|
|
while (((c = ParseReadc()) != '\n' || lastc == '\\')
|
|
|
|
&& c != EOF) {
|
2004-07-22 11:12:01 +00:00
|
|
|
if (skip && c == '#' && lastc != '\\') {
|
|
|
|
/* let a comment be terminated even by an escaped \n.
|
|
|
|
* This is consistent to comment handling in ParseReadLine */
|
|
|
|
while ((c = ParseReadc()) != '\n' && c != EOF)
|
|
|
|
;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-15 10:22:50 +00:00
|
|
|
if (c == '\n') {
|
2004-03-10 21:51:06 +00:00
|
|
|
if (keep_newline)
|
|
|
|
Buf_AddByte(buf, (Byte)c);
|
|
|
|
else
|
|
|
|
Buf_ReplaceLastByte(buf, (Byte)' ');
|
|
|
|
curFile.lineno++;
|
1996-09-22 02:28:36 +00:00
|
|
|
|
2002-09-28 20:03:26 +00:00
|
|
|
while ((c = ParseReadc()) == ' ' || c == '\t')
|
|
|
|
continue;
|
1996-09-22 02:28:36 +00:00
|
|
|
|
2001-03-15 10:22:50 +00:00
|
|
|
if (c == EOF)
|
|
|
|
break;
|
2001-03-15 02:51:11 +00:00
|
|
|
}
|
2001-03-15 10:22:50 +00:00
|
|
|
|
|
|
|
Buf_AddByte(buf, (Byte)c);
|
|
|
|
lastc = c;
|
1996-09-22 02:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == EOF) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop");
|
|
|
|
Buf_Destroy(buf, TRUE);
|
2004-12-01 10:29:20 +00:00
|
|
|
return (NULL);
|
1996-09-22 02:28:36 +00:00
|
|
|
}
|
|
|
|
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.lineno++;
|
1996-09-22 02:28:36 +00:00
|
|
|
Buf_AddByte(buf, (Byte)'\0');
|
2005-02-04 16:53:35 +00:00
|
|
|
line = (char *)Buf_GetAll(buf, NULL);
|
1996-09-22 02:28:36 +00:00
|
|
|
} while (skip == 1 && line[0] != '.');
|
|
|
|
|
|
|
|
Buf_Destroy(buf, FALSE);
|
2004-11-30 17:46:29 +00:00
|
|
|
return (line);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseReadLine --
|
|
|
|
* Read an entire line from the input file. Called only by Parse_File.
|
|
|
|
* To facilitate escaped newlines and what have you, a character is
|
|
|
|
* buffered in 'lastc', which is '\0' when no characters have been
|
|
|
|
* read. When we break out of the loop, c holds the terminating
|
|
|
|
* character and lastc holds a character that should be added to
|
|
|
|
* the line (unless we don't read anything but a terminator).
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* A line w/o its newline
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Only those associated with reading a character
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static char *
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseReadLine(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2005-02-02 07:36:18 +00:00
|
|
|
Buffer *buf; /* Buffer for current line */
|
2002-04-13 10:05:30 +00:00
|
|
|
int c; /* the current character */
|
|
|
|
int lastc; /* The most-recent character */
|
1994-05-27 12:33:43 +00:00
|
|
|
Boolean semiNL; /* treat semi-colons as newlines */
|
|
|
|
Boolean ignDepOp; /* TRUE if should ignore dependency operators
|
|
|
|
* for the purposes of setting semiNL */
|
|
|
|
Boolean ignComment; /* TRUE if should ignore comments (in a
|
|
|
|
* shell command */
|
1995-01-23 21:03:17 +00:00
|
|
|
char *line; /* Result */
|
|
|
|
char *ep; /* to strip trailing blanks */
|
2004-03-10 21:51:06 +00:00
|
|
|
int lineno; /* Saved line # */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
semiNL = FALSE;
|
|
|
|
ignDepOp = FALSE;
|
|
|
|
ignComment = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle special-characters at the beginning of the line. Either a
|
|
|
|
* leading tab (shell command) or pound-sign (possible conditional)
|
|
|
|
* forces us to ignore comments and dependency operators and treat
|
|
|
|
* semi-colons as semi-colons (by leaving semiNL FALSE). This also
|
|
|
|
* discards completely blank lines.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
c = ParseReadc();
|
|
|
|
|
|
|
|
if (c == '\t') {
|
|
|
|
ignComment = ignDepOp = TRUE;
|
|
|
|
break;
|
|
|
|
} else if (c == '\n') {
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.lineno++;
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (c == '#') {
|
|
|
|
ParseUnreadc(c);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Anything else breaks out without doing anything
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (c != EOF) {
|
|
|
|
lastc = c;
|
|
|
|
buf = Buf_Init(MAKE_BSIZE);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
while (((c = ParseReadc()) != '\n' || (lastc == '\\')) &&
|
1994-05-27 12:33:43 +00:00
|
|
|
(c != EOF))
|
|
|
|
{
|
|
|
|
test_char:
|
2004-11-30 17:46:29 +00:00
|
|
|
switch (c) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case '\n':
|
|
|
|
/*
|
|
|
|
* Escaped newline: read characters until a non-space or an
|
|
|
|
* unescaped newline and replace them all by a single space.
|
|
|
|
* This is done by storing the space over the backslash and
|
|
|
|
* dropping through with the next nonspace. If it is a
|
|
|
|
* semi-colon and semiNL is TRUE, it will be recognized as a
|
|
|
|
* newline in the code below this...
|
|
|
|
*/
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.lineno++;
|
1994-05-27 12:33:43 +00:00
|
|
|
lastc = ' ';
|
2004-11-30 17:46:29 +00:00
|
|
|
while ((c = ParseReadc()) == ' ' || c == '\t') {
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == EOF || c == '\n') {
|
|
|
|
goto line_read;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check for comments, semiNL's, etc. -- easier than
|
|
|
|
* ParseUnreadc(c); continue;
|
|
|
|
*/
|
|
|
|
goto test_char;
|
|
|
|
}
|
|
|
|
/*NOTREACHED*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ';':
|
|
|
|
/*
|
|
|
|
* Semi-colon: Need to see if it should be interpreted as a
|
|
|
|
* newline
|
|
|
|
*/
|
|
|
|
if (semiNL) {
|
|
|
|
/*
|
|
|
|
* To make sure the command that may be following this
|
|
|
|
* semi-colon begins with a tab, we push one back into the
|
|
|
|
* input stream. This will overwrite the semi-colon in the
|
|
|
|
* buffer. If there is no command following, this does no
|
|
|
|
* harm, since the newline remains in the buffer and the
|
|
|
|
* whole line is ignored.
|
|
|
|
*/
|
|
|
|
ParseUnreadc('\t');
|
|
|
|
goto line_read;
|
1995-05-30 06:41:30 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
if (!semiNL) {
|
|
|
|
/*
|
|
|
|
* Haven't seen a dependency operator before this, so this
|
|
|
|
* must be a variable assignment -- don't pay attention to
|
|
|
|
* dependency operators after this.
|
|
|
|
*/
|
|
|
|
ignDepOp = TRUE;
|
|
|
|
} else if (lastc == ':' || lastc == '!') {
|
|
|
|
/*
|
|
|
|
* Well, we've seen a dependency operator already, but it
|
|
|
|
* was the previous character, so this is really just an
|
|
|
|
* expanded variable assignment. Revert semi-colons to
|
|
|
|
* being just semi-colons again and ignore any more
|
|
|
|
* dependency operators.
|
|
|
|
*
|
|
|
|
* XXX: Note that a line like "foo : a:=b" will blow up,
|
|
|
|
* but who'd write a line like that anyway?
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
ignDepOp = TRUE;
|
|
|
|
semiNL = FALSE;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
if (!ignComment) {
|
2002-10-02 16:03:26 +00:00
|
|
|
if (lastc != '\\') {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* If the character is a hash mark and it isn't escaped
|
|
|
|
* (or we're being compatible), the thing is a comment.
|
|
|
|
* Skip to the end of the line.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
c = ParseReadc();
|
|
|
|
} while ((c != '\n') && (c != EOF));
|
|
|
|
goto line_read;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't add the backslash. Just let the # get copied
|
|
|
|
* over.
|
|
|
|
*/
|
|
|
|
lastc = c;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ':':
|
|
|
|
case '!':
|
|
|
|
if (!ignDepOp && (c == ':' || c == '!')) {
|
|
|
|
/*
|
|
|
|
* A semi-colon is recognized as a newline only on
|
|
|
|
* dependency lines. Dependency lines are lines with a
|
|
|
|
* colon or an exclamation point. Ergo...
|
|
|
|
*/
|
|
|
|
semiNL = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2002-09-28 20:03:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Copy in the previous character and save this one in lastc.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
Buf_AddByte(buf, (Byte)lastc);
|
1994-05-27 12:33:43 +00:00
|
|
|
lastc = c;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
line_read:
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.lineno++;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (lastc != '\0') {
|
2004-11-30 17:46:29 +00:00
|
|
|
Buf_AddByte(buf, (Byte)lastc);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
Buf_AddByte(buf, (Byte)'\0');
|
2005-02-04 16:53:35 +00:00
|
|
|
line = (char *)Buf_GetAll(buf, NULL);
|
2004-11-30 17:46:29 +00:00
|
|
|
Buf_Destroy(buf, FALSE);
|
1995-01-23 21:03:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip trailing blanks and tabs from the line.
|
2001-02-18 10:43:53 +00:00
|
|
|
* Do not strip a blank or tab that is preceded by
|
1995-01-23 21:03:17 +00:00
|
|
|
* a '\'
|
|
|
|
*/
|
|
|
|
ep = line;
|
|
|
|
while (*ep)
|
|
|
|
++ep;
|
1995-06-24 17:34:15 +00:00
|
|
|
while (ep > line + 1 && (ep[-1] == ' ' || ep[-1] == '\t')) {
|
1996-10-06 02:35:38 +00:00
|
|
|
if (ep > line + 1 && ep[-2] == '\\')
|
1995-06-18 12:34:14 +00:00
|
|
|
break;
|
1995-01-23 21:03:17 +00:00
|
|
|
--ep;
|
|
|
|
}
|
|
|
|
*ep = 0;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (line[0] == '.') {
|
|
|
|
/*
|
|
|
|
* The line might be a conditional. Ask the conditional module
|
|
|
|
* about it and act accordingly
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
switch (Cond_Eval(line)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case COND_SKIP:
|
|
|
|
/*
|
|
|
|
* Skip to next conditional that evaluates to COND_PARSE.
|
|
|
|
*/
|
|
|
|
do {
|
2004-11-30 17:46:29 +00:00
|
|
|
free(line);
|
2004-03-10 21:51:06 +00:00
|
|
|
line = ParseSkipLine(1, 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
} while (line && Cond_Eval(line) != COND_PARSE);
|
|
|
|
if (line == NULL)
|
|
|
|
break;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case COND_PARSE:
|
2004-11-30 17:46:29 +00:00
|
|
|
free(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
line = ParseReadLine();
|
|
|
|
break;
|
|
|
|
case COND_INVALID:
|
|
|
|
if (For_Eval(line)) {
|
|
|
|
int ok;
|
|
|
|
free(line);
|
2004-03-10 21:51:06 +00:00
|
|
|
lineno = curFile.lineno;
|
1994-05-27 12:33:43 +00:00
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Skip after the matching end
|
|
|
|
*/
|
2004-03-10 21:51:06 +00:00
|
|
|
line = ParseSkipLine(0, 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (line == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-05-27 12:33:43 +00:00
|
|
|
"Unexpected end of file in for loop.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ok = For_Eval(line);
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
while (ok);
|
|
|
|
if (line != NULL)
|
2004-03-10 21:51:06 +00:00
|
|
|
For_Run(lineno);
|
1994-05-27 12:33:43 +00:00
|
|
|
line = ParseReadLine();
|
|
|
|
}
|
|
|
|
break;
|
2002-09-28 20:03:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (line);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Hit end-of-file, so return a NULL line to indicate this.
|
|
|
|
*/
|
2004-12-01 10:29:20 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseFinishLine --
|
|
|
|
* Handle the end of a dependency group.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* inLine set FALSE. 'targets' list destroyed.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-10-09 03:42:10 +00:00
|
|
|
ParseFinishLine(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
if (inLine) {
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&targets, Suff_EndTransform, NULL);
|
|
|
|
Lst_Destroy(&targets, ParseHasCommands);
|
1994-05-27 12:33:43 +00:00
|
|
|
inLine = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_File --
|
|
|
|
* Parse a file into its component parts, incorporating it into the
|
|
|
|
* current dependency graph. This is the main function and controls
|
|
|
|
* almost every other function in this module
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* Loads. Nodes are added to the list of all targets, nodes and links
|
|
|
|
* are added to the dependency graph. etc. etc. etc.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-10-09 03:42:10 +00:00
|
|
|
Parse_File(char *name, FILE *stream)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-04-13 10:05:30 +00:00
|
|
|
char *cp, /* pointer into the line */
|
1994-05-27 12:33:43 +00:00
|
|
|
*line; /* the line we're working on */
|
2005-02-25 13:16:56 +00:00
|
|
|
Buffer *buf;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
inLine = FALSE;
|
2004-03-10 21:51:06 +00:00
|
|
|
curFile.fname = name;
|
|
|
|
curFile.F = stream;
|
|
|
|
curFile.lineno = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
fatals = 0;
|
|
|
|
|
2004-07-02 12:30:28 +00:00
|
|
|
Var_Append(".MAKEFILE_LIST", name, VAR_GLOBAL);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
do {
|
2004-11-30 17:46:29 +00:00
|
|
|
while ((line = ParseReadLine()) != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
if (*line == '.') {
|
|
|
|
/*
|
|
|
|
* Lines that begin with the special character are either
|
|
|
|
* include or undef directives.
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
for (cp = line + 1; isspace((unsigned char)*cp); cp++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-11-30 17:46:29 +00:00
|
|
|
if (strncmp(cp, "include", 7) == 0) {
|
2005-02-04 12:38:57 +00:00
|
|
|
ParseDoInclude(cp + 7);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto nextLine;
|
2004-11-30 17:46:29 +00:00
|
|
|
} else if (strncmp(cp, "error", 5) == 0) {
|
1998-05-25 03:28:37 +00:00
|
|
|
ParseDoError(cp + 5);
|
2004-11-30 17:46:29 +00:00
|
|
|
goto nextLine;
|
|
|
|
} else if (strncmp(cp, "warning", 7) == 0) {
|
2004-04-12 17:57:51 +00:00
|
|
|
ParseDoWarning(cp + 7);
|
2004-11-30 17:46:29 +00:00
|
|
|
goto nextLine;
|
1994-05-27 12:33:43 +00:00
|
|
|
} else if (strncmp(cp, "undef", 5) == 0) {
|
|
|
|
char *cp2;
|
2004-11-30 17:46:29 +00:00
|
|
|
for (cp += 5; isspace((unsigned char)*cp); cp++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
for (cp2 = cp; !isspace((unsigned char)*cp2) &&
|
1995-01-23 21:03:17 +00:00
|
|
|
(*cp2 != '\0'); cp2++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp2 = '\0';
|
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, cp, VAR_CMD, FALSE);
|
|
|
|
cp = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
Var_Delete(cp, VAR_GLOBAL);
|
|
|
|
goto nextLine;
|
|
|
|
}
|
|
|
|
}
|
1995-06-24 17:34:15 +00:00
|
|
|
if (*line == '#') {
|
1994-05-27 12:33:43 +00:00
|
|
|
/* If we're this far, the line must be a comment. */
|
|
|
|
goto nextLine;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1995-01-23 21:03:17 +00:00
|
|
|
if (*line == '\t') {
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
1995-01-23 21:03:17 +00:00
|
|
|
* If a line starts with a tab, it can only hope to be
|
|
|
|
* a creation command.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
for (cp = line + 1; isspace((unsigned char)*cp); cp++) {
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp) {
|
|
|
|
if (inLine) {
|
|
|
|
/*
|
|
|
|
* So long as it's not a blank line and we're actually
|
|
|
|
* in a dependency spec, add the command to the list of
|
1995-05-30 06:41:30 +00:00
|
|
|
* commands of all targets in the dependency spec
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_ForEach(&targets, ParseAddCmd, cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1996-10-06 02:35:38 +00:00
|
|
|
"Unassociated shell command \"%s\"",
|
1994-05-27 12:33:43 +00:00
|
|
|
cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef SYSVINCLUDE
|
2004-11-30 17:46:29 +00:00
|
|
|
} else if (strncmp(line, "include", 7) == 0 &&
|
|
|
|
isspace((unsigned char)line[7]) &&
|
1994-05-27 12:33:43 +00:00
|
|
|
strchr(line, ':') == NULL) {
|
|
|
|
/*
|
|
|
|
* It's an S3/S5-style "include".
|
|
|
|
*/
|
2004-11-30 17:46:29 +00:00
|
|
|
ParseTraditionalInclude(line + 7);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto nextLine;
|
|
|
|
#endif
|
2004-11-30 17:46:29 +00:00
|
|
|
} else if (Parse_IsVar(line)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
ParseFinishLine();
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_DoVar(line, VAR_GLOBAL);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We now know it's a dependency line so it needs to have all
|
|
|
|
* variables expanded before being parsed. Tell the variable
|
|
|
|
* module to complain if some variable is undefined...
|
|
|
|
* To make life easier on novices, if the line is indented we
|
|
|
|
* first make sure the line has a dependency operator in it.
|
|
|
|
* If it doesn't have an operator and we're in a dependency
|
|
|
|
* line's script, we assume it's actually a shell command
|
|
|
|
* and add it to the current list of targets.
|
|
|
|
*/
|
|
|
|
cp = line;
|
2004-11-30 17:46:29 +00:00
|
|
|
if (isspace((unsigned char)line[0])) {
|
|
|
|
while ((*cp != '\0') && isspace((unsigned char)*cp)) {
|
1995-01-23 21:03:17 +00:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (*cp == '\0') {
|
|
|
|
goto nextLine;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-17 11:32:46 +00:00
|
|
|
ParseFinishLine();
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2005-02-25 13:16:56 +00:00
|
|
|
buf = Var_Subst(NULL, line, VAR_CMD, TRUE);
|
|
|
|
cp = Buf_GetAll(buf, NULL);
|
|
|
|
Buf_Destroy(buf, FALSE);
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
free(line);
|
2004-11-17 11:32:46 +00:00
|
|
|
line = cp;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-11-17 11:32:46 +00:00
|
|
|
/*
|
|
|
|
* Need a non-circular list for the target nodes
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Destroy(&targets, NOFREE);
|
2004-11-17 11:32:46 +00:00
|
|
|
inLine = TRUE;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2005-02-04 12:38:57 +00:00
|
|
|
ParseDoDependency(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextLine:
|
|
|
|
|
2004-11-30 17:46:29 +00:00
|
|
|
free(line);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
/*
|
1995-05-30 06:41:30 +00:00
|
|
|
* Reached EOF, but it may be just EOF of an include file...
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
} while (ParseEOF(1) == CONTINUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure conditionals are clean
|
|
|
|
*/
|
|
|
|
Cond_End();
|
|
|
|
|
1997-07-24 06:58:08 +00:00
|
|
|
if (fatals)
|
|
|
|
errx(1, "fatal errors encountered -- cannot continue");
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_Init --
|
|
|
|
* initialize the parsing module
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* the parseIncPath list is initialized...
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2004-11-30 17:46:29 +00:00
|
|
|
Parse_Init(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-11-30 17:46:29 +00:00
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
mainNode = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* Parse_MainName --
|
|
|
|
* Return a Lst of the main target to create for main()'s sake. If
|
|
|
|
* no such target exists, we Punt with an obnoxious error message.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* A Lst of the single node to create.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
2004-12-16 16:14:16 +00:00
|
|
|
void
|
|
|
|
Parse_MainName(Lst *listmain)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
2000-12-02 18:58:01 +00:00
|
|
|
if (mainNode == NULL) {
|
2004-11-30 17:46:29 +00:00
|
|
|
Punt("no target to make.");
|
1994-05-27 12:33:43 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
} else if (mainNode->type & OP_DOUBLEDEP) {
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(listmain, mainNode);
|
2004-12-16 16:14:16 +00:00
|
|
|
Lst_Concat(listmain, &mainNode->cohorts, LST_CONCNEW);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
else
|
2004-12-01 10:29:20 +00:00
|
|
|
Lst_AtEnd(listmain, mainNode);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|