2003-08-07 15:13:06 +04:00
|
|
|
/* $NetBSD: parse.c,v 1.94 2003/08/07 11:14:56 agc Exp $ */
|
1995-06-14 19:18:37 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* Copyright (c) 1988, 1989, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
2003-08-07 15:13:06 +04:00
|
|
|
*
|
|
|
|
* 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. 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-28 07:30:58 +04:00
|
|
|
#ifdef MAKE_BOOTSTRAP
|
2003-08-07 15:13:06 +04:00
|
|
|
static char rcsid[] = "$NetBSD: parse.c,v 1.94 2003/08/07 11:14:56 agc Exp $";
|
1997-09-28 07:30:58 +04:00
|
|
|
#else
|
1997-07-02 01:17:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-06-14 19:18:37 +04:00
|
|
|
#if 0
|
1996-11-06 20:58:58 +03:00
|
|
|
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
|
1995-06-14 19:18:37 +04:00
|
|
|
#else
|
2003-08-07 15:13:06 +04:00
|
|
|
__RCSID("$NetBSD: parse.c,v 1.94 2003/08/07 11:14:56 agc Exp $");
|
1995-06-14 19:18:37 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
1997-09-28 07:30:58 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
|
|
|
* The variables 'fname' and '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.
|
|
|
|
*
|
|
|
|
* Interface:
|
|
|
|
* Parse_Init Initialization function which must be
|
|
|
|
* called before anything else in this module
|
|
|
|
* is used.
|
|
|
|
*
|
1994-06-07 02:45:17 +04:00
|
|
|
* Parse_End Cleanup the module
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "make.h"
|
1994-03-05 03:34:29 +03:00
|
|
|
#include "hash.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "job.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "buf.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
static Lst targets; /* targets we're working on */
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
1994-06-07 02:45:17 +04:00
|
|
|
static Lst targCmds; /* command lines for targets */
|
1999-09-15 12:43:21 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
static Boolean inLine; /* true if currently in a dependency
|
|
|
|
* line or its commands */
|
1994-03-05 03:34:29 +03:00
|
|
|
typedef struct {
|
|
|
|
char *str;
|
|
|
|
char *ptr;
|
|
|
|
} PTR;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
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 */
|
|
|
|
typedef struct IFile {
|
|
|
|
char *fname; /* name of previous file */
|
|
|
|
int lineno; /* saved line number */
|
1994-03-05 03:34:29 +03:00
|
|
|
FILE * F; /* the open stream */
|
2002-02-22 01:21:34 +03:00
|
|
|
PTR * P; /* the char pointer */
|
1994-03-05 03:34:29 +03:00
|
|
|
} IFile;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
static IFile curFile;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Definitions for handling #include specifications
|
|
|
|
*/
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
static Lst includes; /* stack of IFiles generated by
|
|
|
|
* #includes */
|
|
|
|
Lst parseIncPath; /* list of directories for "..." includes */
|
|
|
|
Lst sysIncPath; /* list of directories for <...> includes */
|
2001-10-31 04:15:57 +03:00
|
|
|
Lst defIncPath; /* default directories for <...> includes */
|
1993-03-21 12:45:37 +03: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 */
|
1994-03-05 03:34:29 +03:00
|
|
|
NoExport, /* .NOEXPORT */
|
1997-05-09 01:24:41 +04:00
|
|
|
NoPath, /* .NOPATH */
|
1993-03-21 12:45:37 +03:00
|
|
|
Not, /* Not special */
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
NotParallel, /* .NOTPARALLEL */
|
1993-03-21 12:45:37 +03:00
|
|
|
Null, /* .NULL */
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
ExObjdir, /* .OBJDIR */
|
1993-03-21 12:45:37 +03:00
|
|
|
Order, /* .ORDER */
|
1995-12-16 08:03:09 +03:00
|
|
|
Parallel, /* .PARALLEL */
|
1994-03-05 03:34:29 +03:00
|
|
|
ExPath, /* .PATH */
|
1996-03-16 00:52:32 +03:00
|
|
|
Phony, /* .PHONY */
|
2000-05-11 12:22:40 +04:00
|
|
|
#ifdef POSIX
|
|
|
|
Posix, /* .POSIX */
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
Precious, /* .PRECIOUS */
|
1994-03-05 03:34:29 +03:00
|
|
|
ExShell, /* .SHELL */
|
1993-03-21 12:45:37 +03:00
|
|
|
Silent, /* .SILENT */
|
|
|
|
SingleShell, /* .SINGLESHELL */
|
|
|
|
Suffixes, /* .SUFFIXES */
|
1995-12-16 08:03:09 +03:00
|
|
|
Wait, /* .WAIT */
|
1994-03-05 03:34:29 +03:00
|
|
|
Attribute /* Generic attribute */
|
1993-03-21 12:45:37 +03:00
|
|
|
} ParseSpecial;
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
static ParseSpecial specType;
|
1995-12-16 08:03:09 +03:00
|
|
|
static int waiting;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
#define LPAREN '('
|
|
|
|
#define RPAREN ')'
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Predecessor node for handling .ORDER. Initialized to NILGNODE when .ORDER
|
|
|
|
* 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 {
|
2003-07-14 22:19:11 +04:00
|
|
|
const char *name; /* Name of keyword */
|
1993-03-21 12:45:37 +03: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 },
|
1997-03-11 00:19:49 +03:00
|
|
|
{ ".MADE", Attribute, OP_MADE },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".MAIN", Main, 0 },
|
|
|
|
{ ".MAKE", Attribute, OP_MAKE },
|
|
|
|
{ ".MAKEFLAGS", MFlags, 0 },
|
|
|
|
{ ".MFLAGS", MFlags, 0 },
|
1997-05-09 01:24:41 +04:00
|
|
|
{ ".NOPATH", NoPath, OP_NOPATH },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".NOTMAIN", Attribute, OP_NOTMAIN },
|
|
|
|
{ ".NOTPARALLEL", NotParallel, 0 },
|
1995-12-16 08:03:09 +03:00
|
|
|
{ ".NO_PARALLEL", NotParallel, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".NULL", Null, 0 },
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
{ ".OBJDIR", ExObjdir, 0 },
|
1995-05-15 17:10:10 +04:00
|
|
|
{ ".OPTIONAL", Attribute, OP_OPTIONAL },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".ORDER", Order, 0 },
|
1995-12-16 08:03:09 +03:00
|
|
|
{ ".PARALLEL", Parallel, 0 },
|
1994-03-05 03:34:29 +03:00
|
|
|
{ ".PATH", ExPath, 0 },
|
1996-03-16 00:52:32 +03:00
|
|
|
{ ".PHONY", Phony, OP_PHONY },
|
2000-05-11 12:22:40 +04:00
|
|
|
#ifdef POSIX
|
|
|
|
{ ".POSIX", Posix, 0 },
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".PRECIOUS", Precious, OP_PRECIOUS },
|
|
|
|
{ ".RECURSIVE", Attribute, OP_MAKE },
|
1994-03-05 03:34:29 +03:00
|
|
|
{ ".SHELL", ExShell, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".SILENT", Silent, OP_SILENT },
|
|
|
|
{ ".SINGLESHELL", SingleShell, 0 },
|
|
|
|
{ ".SUFFIXES", Suffixes, 0 },
|
|
|
|
{ ".USE", Attribute, OP_USE },
|
2001-07-03 22:08:50 +04:00
|
|
|
{ ".USEBEFORE", Attribute, OP_USEBEFORE },
|
1995-12-16 08:03:09 +03:00
|
|
|
{ ".WAIT", Wait, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2003-03-21 18:52:57 +03:00
|
|
|
/*
|
|
|
|
* Used by ParseDoSpecialSrc()
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
int op;
|
|
|
|
char *src;
|
|
|
|
Lst allsrc;
|
|
|
|
} SpecialSrc;
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
static int ParseIsEscaped(const char *, const char *);
|
2003-07-14 22:19:11 +04:00
|
|
|
static void ParseErrorInternal(char *, size_t, int, const char *, ...)
|
2000-10-11 18:46:00 +04:00
|
|
|
__attribute__((__format__(__printf__, 4, 5)));
|
2003-07-14 22:19:11 +04:00
|
|
|
static void ParseVErrorInternal(char *, size_t, int, const char *, va_list)
|
2000-10-11 18:46:00 +04:00
|
|
|
__attribute__((__format__(__printf__, 4, 0)));
|
2002-06-15 22:24:55 +04:00
|
|
|
static int ParseFindKeyword(char *);
|
|
|
|
static int ParseLinkSrc(ClientData, ClientData);
|
|
|
|
static int ParseDoOp(ClientData, ClientData);
|
|
|
|
static int ParseAddDep(ClientData, ClientData);
|
2003-03-21 18:52:57 +03:00
|
|
|
static int ParseDoSpecialSrc(ClientData, ClientData);
|
|
|
|
static void ParseDoSrc(int, char *, Lst, Boolean);
|
2002-06-15 22:24:55 +04:00
|
|
|
static int ParseFindMain(ClientData, ClientData);
|
|
|
|
static int ParseAddDir(ClientData, ClientData);
|
|
|
|
static int ParseClearPath(ClientData, ClientData);
|
|
|
|
static void ParseDoDependency(char *);
|
|
|
|
static int ParseAddCmd(ClientData, ClientData);
|
|
|
|
static __inline int ParseReadc(void);
|
|
|
|
static void ParseUnreadc(int);
|
|
|
|
static void ParseHasCommands(ClientData);
|
|
|
|
static void ParseDoInclude(char *);
|
|
|
|
static void ParseSetParseFile(char *);
|
1994-03-05 03:34:29 +03:00
|
|
|
#ifdef SYSVINCLUDE
|
2002-06-15 22:24:55 +04:00
|
|
|
static void ParseTraditionalInclude(char *);
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
2002-06-15 22:24:55 +04:00
|
|
|
static int ParseEOF(int);
|
|
|
|
static char *ParseReadLine(void);
|
|
|
|
static char *ParseSkipLine(int);
|
|
|
|
static void ParseFinishLine(void);
|
|
|
|
static void ParseMark(GNode *);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2001-01-10 18:54:00 +03:00
|
|
|
extern int maxJobs;
|
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
* ParseIsEscaped --
|
|
|
|
* Check if the current character is escaped on the current line
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* 0 if the character is not backslash escaped, 1 otherwise
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseIsEscaped(const char *line, const char *c)
|
2002-01-26 23:42:14 +03:00
|
|
|
{
|
|
|
|
int active = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (line == c)
|
|
|
|
return active;
|
|
|
|
if (*--c != '\\')
|
|
|
|
return active;
|
|
|
|
active = !active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
* ParseFindKeyword --
|
|
|
|
* Look in the table of keywords for one matching the given string.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* str String to find
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* The index of the keyword, or -1 if it isn't there.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseFindKeyword(char *str)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
int start, end, cur;
|
|
|
|
int diff;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
start = 0;
|
|
|
|
end = (sizeof(parseKeywords)/sizeof(parseKeywords[0])) - 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
cur = start + ((end - start) / 2);
|
|
|
|
diff = strcmp (str, parseKeywords[cur].name);
|
|
|
|
|
|
|
|
if (diff == 0) {
|
|
|
|
return (cur);
|
|
|
|
} else if (diff < 0) {
|
|
|
|
end = cur - 1;
|
|
|
|
} else {
|
|
|
|
start = cur + 1;
|
|
|
|
}
|
|
|
|
} while (start <= end);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
1998-08-06 17:42:22 +04:00
|
|
|
* ParseVErrorInternal --
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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 */
|
1998-08-06 17:42:22 +04:00
|
|
|
static void
|
2003-07-14 22:19:11 +04:00
|
|
|
ParseVErrorInternal(char *cfname, size_t clineno, int type, const char *fmt,
|
1998-08-06 17:42:22 +04:00
|
|
|
va_list ap)
|
|
|
|
{
|
2001-01-10 18:54:00 +03:00
|
|
|
static Boolean fatal_warning_error_printed = FALSE;
|
|
|
|
|
2001-02-24 00:11:38 +03:00
|
|
|
(void)fprintf(stderr, "%s: \"", progname);
|
|
|
|
|
2001-01-07 09:08:33 +03:00
|
|
|
if (*cfname != '/') {
|
2003-07-14 22:19:11 +04:00
|
|
|
char *cp;
|
|
|
|
const char *dir;
|
2001-01-07 09:08:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing is more anoying than not knowing which Makefile
|
|
|
|
* is the culprit.
|
|
|
|
*/
|
|
|
|
dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
|
2001-02-24 00:11:38 +03:00
|
|
|
if (dir == NULL || *dir == '\0' ||
|
2001-01-07 09:08:33 +03:00
|
|
|
(*dir == '.' && dir[1] == '\0'))
|
|
|
|
dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
|
2001-02-24 00:11:38 +03:00
|
|
|
if (dir == NULL)
|
|
|
|
dir = ".";
|
2001-01-07 09:08:33 +03:00
|
|
|
|
2001-02-24 00:11:38 +03:00
|
|
|
(void)fprintf(stderr, "%s/%s", dir, cfname);
|
2001-01-07 09:08:33 +03:00
|
|
|
} else
|
2001-02-24 00:11:38 +03:00
|
|
|
(void)fprintf(stderr, "%s", cfname);
|
|
|
|
|
|
|
|
(void)fprintf(stderr, "\" line %d: ", (int)clineno);
|
1998-08-06 17:42:22 +04:00
|
|
|
if (type == PARSE_WARNING)
|
|
|
|
(void)fprintf(stderr, "warning: ");
|
|
|
|
(void)vfprintf(stderr, fmt, ap);
|
|
|
|
(void)fprintf(stderr, "\n");
|
|
|
|
(void)fflush(stderr);
|
2001-01-10 18:54:00 +03:00
|
|
|
if (type == PARSE_FATAL || parseWarnFatal)
|
1998-08-06 17:42:22 +04:00
|
|
|
fatals += 1;
|
2001-01-10 18:54:00 +03:00
|
|
|
if (parseWarnFatal && !fatal_warning_error_printed) {
|
|
|
|
Error("parsing warnings being treated as errors");
|
|
|
|
fatal_warning_error_printed = TRUE;
|
|
|
|
}
|
1998-08-06 17:42:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* ParseErrorInternal --
|
|
|
|
* Error function
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
|
|
|
static void
|
2003-07-14 22:19:11 +04:00
|
|
|
ParseErrorInternal(char *cfname, size_t clineno, int type, const char *fmt, ...)
|
1998-08-06 17:42:22 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
va_start(ap, fmt);
|
1998-08-06 17:42:22 +04:00
|
|
|
ParseVErrorInternal(cfname, clineno, type, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Parse_Error --
|
|
|
|
* External interface to ParseErrorInternal; uses the default filename
|
|
|
|
* Line number.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*/
|
|
|
|
/* VARARGS */
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
2003-07-14 22:19:11 +04:00
|
|
|
Parse_Error(int type, const char *fmt, ...)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
va_start(ap, fmt);
|
2002-02-22 01:21:34 +03:00
|
|
|
ParseVErrorInternal(curFile.fname, curFile.lineno, type, fmt, ap);
|
1993-03-21 12:45:37 +03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseLinkSrc --
|
|
|
|
* Link the parent node to its new child. Used in a Lst_ForEach by
|
|
|
|
* ParseDoDependency. If the specType isn't 'Not', the parent
|
|
|
|
* isn't linked as a parent of the child.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* pgnp The parent node
|
|
|
|
* cgpn The child node
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* Always = 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* New elements are added to the parents list of cgn and the
|
|
|
|
* children list of cgn. the unmade field of pgn is updated
|
|
|
|
* to reflect the additional child.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseLinkSrc(ClientData pgnp, ClientData cgnp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
GNode *pgn = (GNode *) pgnp;
|
|
|
|
GNode *cgn = (GNode *) cgnp;
|
2000-06-11 11:39:52 +04:00
|
|
|
|
1999-09-16 04:54:14 +04:00
|
|
|
if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (pgn->cohorts))
|
1999-09-15 14:47:37 +04:00
|
|
|
pgn = (GNode *) Lst_Datum (Lst_Last (pgn->cohorts));
|
2000-06-11 11:39:52 +04:00
|
|
|
(void)Lst_AtEnd (pgn->children, (ClientData)cgn);
|
|
|
|
if (specType == Not)
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)Lst_AtEnd (cgn->parents, (ClientData)pgn);
|
2000-06-11 11:39:52 +04:00
|
|
|
pgn->unmade += 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* 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.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* gnp The node to which the operator is to be applied
|
|
|
|
* opp The operator to apply
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* Always 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The type field of the node is altered to reflect any new bits in
|
|
|
|
* the op.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseDoOp(ClientData gnp, ClientData opp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
GNode *gn = (GNode *) gnp;
|
|
|
|
int op = *(int *) opp;
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
* the operator actually has some dependency information in it, complain.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
if (((op & OP_OPMASK) != (gn->type & OP_OPMASK)) &&
|
|
|
|
!OP_NOP(gn->type) && !OP_NOP(op))
|
|
|
|
{
|
|
|
|
Parse_Error (PARSE_FATAL, "Inconsistent operator for %s", gn->name);
|
|
|
|
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.
|
|
|
|
*/
|
2002-06-15 22:24:55 +04:00
|
|
|
GNode *cohort;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1997-05-09 08:08:26 +04:00
|
|
|
/*
|
1999-09-15 14:47:37 +04:00
|
|
|
* Propagate copied bits to the initial node. They'll be propagated
|
|
|
|
* back to the rest of the cohorts later.
|
1997-05-09 08:08:26 +04:00
|
|
|
*/
|
1999-09-15 14:47:37 +04:00
|
|
|
gn->type |= op & ~OP_OPMASK;
|
1997-05-09 08:08:26 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
cohort = Targ_NewGN(gn->name);
|
|
|
|
/*
|
|
|
|
* 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
|
1999-09-15 14:47:37 +04:00
|
|
|
* sorry. (I think this is pointless now, since the relevant list
|
|
|
|
* traversals will no longer see this node anyway. -mycroft)
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1999-09-15 14:47:37 +04:00
|
|
|
cohort->type = op | OP_INVISIBLE;
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)Lst_AtEnd(gn->cohorts, (ClientData)cohort);
|
2002-03-20 21:10:30 +03:00
|
|
|
cohort->centurion = gn;
|
|
|
|
gn->unmade_cohorts += 1;
|
1999-09-15 14:47:37 +04:00
|
|
|
} else {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1999-09-15 14:47:37 +04:00
|
|
|
* We don't want to nuke any previous flags (whatever they were) so we
|
|
|
|
* just OR the new operator into the old
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1999-09-15 14:47:37 +04:00
|
|
|
gn->type |= op;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-05-09 08:08:26 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
/*-
|
1995-12-16 08:03:09 +03: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.
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
1995-12-16 08:03:09 +03:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
1996-12-31 20:55:28 +03:00
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseAddDep(ClientData pp, ClientData sp)
|
1995-12-16 08:03:09 +03:00
|
|
|
{
|
|
|
|
GNode *p = (GNode *) pp;
|
|
|
|
GNode *s = (GNode *) sp;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
(void)Lst_AtEnd(p->successors, (ClientData)s);
|
|
|
|
(void)Lst_AtEnd(s->preds, (ClientData)p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-03-21 18:52:57 +03:00
|
|
|
/* -
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoSpecialSrc --
|
|
|
|
* ParseDoSrc struck an unexpanded variable in a src.
|
|
|
|
* The most likely reason is a src that refers to .TARGET or
|
|
|
|
* .PREFIX so we get called to set those for each target
|
|
|
|
* and then call ParseDoSrc again to do the real work.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* tp A target GNode *
|
|
|
|
* sp A SpecialSrc * which contains the args we need
|
|
|
|
* for ParseDoSrc.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Goodness
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The target GNode will have .TARGET and .PREFIX set, this seems
|
|
|
|
* harmless.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ParseDoSpecialSrc(ClientData tp, ClientData sp)
|
|
|
|
{
|
|
|
|
GNode *tn = (GNode *) tp;
|
2003-03-23 02:41:02 +03:00
|
|
|
GNode *gn;
|
2003-03-21 18:52:57 +03:00
|
|
|
SpecialSrc *ss = (SpecialSrc *) sp;
|
|
|
|
char *cp;
|
|
|
|
char *cp2;
|
|
|
|
char *pref;
|
|
|
|
|
2003-03-21 22:14:53 +03:00
|
|
|
/*
|
|
|
|
* If the target is a suffix rule, leave it alone.
|
|
|
|
*/
|
|
|
|
if (Suff_IsTransform(tn->name)) {
|
|
|
|
ParseDoSrc(ss->op, ss->src, ss->allsrc, FALSE); /* don't come back */
|
|
|
|
return 0;
|
|
|
|
}
|
2003-03-21 18:52:57 +03:00
|
|
|
Var_Set(TARGET, tn->name, tn, 0);
|
|
|
|
if ((pref = strrchr(tn->name, '/')))
|
|
|
|
pref++;
|
|
|
|
else
|
|
|
|
pref = tn->name;
|
2003-03-21 19:48:21 +03:00
|
|
|
if ((cp2 = strchr(pref, '.')) > pref) {
|
2003-03-21 18:52:57 +03:00
|
|
|
cp = estrdup(pref);
|
|
|
|
cp[cp2 - pref] = '\0';
|
|
|
|
Var_Set(PREFIX, cp, tn, 0);
|
|
|
|
free(cp);
|
|
|
|
} else
|
|
|
|
Var_Set(PREFIX, pref, tn, 0);
|
|
|
|
cp = Var_Subst(NULL, ss->src, tn, FALSE);
|
2003-03-23 02:41:02 +03:00
|
|
|
if (strchr(cp, '$')) {
|
2003-03-21 18:52:57 +03:00
|
|
|
Parse_Error(PARSE_WARNING, "Cannot resolve '%s' here", ss->src);
|
2003-03-23 02:41:02 +03:00
|
|
|
ParseDoSrc(ss->op, ss->src, ss->allsrc, FALSE); /* don't come back */
|
|
|
|
return 1; /* stop list traversal */
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We don't want to make every target dependent on sources for
|
|
|
|
* other targets. This is the bit of ParseDoSrc which is relevant.
|
2003-03-24 01:48:35 +03:00
|
|
|
* The main difference is we don't link the resolved src to all targets.
|
2003-03-23 02:41:02 +03:00
|
|
|
*/
|
|
|
|
gn = Targ_FindNode (cp, TARG_CREATE);
|
|
|
|
if (ss->op) {
|
|
|
|
gn->type |= ss->op;
|
|
|
|
} else {
|
|
|
|
ParseLinkSrc((ClientData)tn, (ClientData)gn);
|
|
|
|
}
|
|
|
|
gn->order = waiting;
|
|
|
|
(void)Lst_AtEnd(ss->allsrc, (ClientData)gn);
|
|
|
|
if (waiting) {
|
2003-03-23 08:11:22 +03:00
|
|
|
Lst_ForEach(ss->allsrc, ParseAddDep, (ClientData)gn);
|
2003-03-23 02:41:02 +03:00
|
|
|
}
|
2003-03-21 18:52:57 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-12-16 08:03:09 +03:00
|
|
|
|
1993-03-21 12:45:37 +03: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'
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* tOp operator (if any) from special targets
|
|
|
|
* src name of the source to handle
|
|
|
|
* allsrc List of all sources to wait for
|
2003-03-21 18:52:57 +03:00
|
|
|
* resolve boolean - should we try and resolve .TARGET refs.
|
2002-06-15 22:24:55 +04:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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
|
2003-03-21 18:52:57 +03:00
|
|
|
ParseDoSrc(int tOp, char *src, Lst allsrc, Boolean resolve)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-12-16 08:03:09 +03:00
|
|
|
GNode *gn = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-11-07 02:31:09 +03:00
|
|
|
if (*src == '.' && isupper ((unsigned char)src[1])) {
|
1993-03-21 12:45:37 +03:00
|
|
|
int keywd = ParseFindKeyword(src);
|
|
|
|
if (keywd != -1) {
|
1995-12-16 08:03:09 +03:00
|
|
|
int op = parseKeywords[keywd].op;
|
|
|
|
if (op != 0) {
|
|
|
|
Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parseKeywords[keywd].spec == Wait) {
|
|
|
|
waiting++;
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
|
|
|
|
switch (specType) {
|
|
|
|
case Main:
|
1993-03-21 12:45:37 +03: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...
|
|
|
|
*/
|
1996-08-13 20:42:00 +04:00
|
|
|
(void) Lst_AtEnd (create, (ClientData)estrdup(src));
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Add the name to the .TARGETS variable as well, so the user cna
|
|
|
|
* employ that, if desired.
|
|
|
|
*/
|
|
|
|
Var_Append(".TARGETS", src, VAR_GLOBAL);
|
1995-12-16 08:03:09 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
case Order:
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Create proper predecessor/successor links between the previous
|
|
|
|
* source and the current one.
|
|
|
|
*/
|
|
|
|
gn = Targ_FindNode(src, TARG_CREATE);
|
|
|
|
if (predecessor != NILGNODE) {
|
|
|
|
(void)Lst_AtEnd(predecessor->successors, (ClientData)gn);
|
|
|
|
(void)Lst_AtEnd(gn->preds, (ClientData)predecessor);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The current source now becomes the predecessor for the next one.
|
|
|
|
*/
|
|
|
|
predecessor = gn;
|
1995-12-16 08:03:09 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
2003-03-21 18:52:57 +03:00
|
|
|
if (resolve && strchr(src, '$')) {
|
|
|
|
SpecialSrc ss;
|
|
|
|
|
|
|
|
ss.op = tOp;
|
|
|
|
ss.src = src;
|
|
|
|
ss.allsrc = allsrc;
|
|
|
|
|
|
|
|
/*
|
2003-03-24 01:48:35 +03:00
|
|
|
* If src cannot be fully resolved, we'll be called again
|
|
|
|
* with resolve==FALSE.
|
2003-03-21 18:52:57 +03:00
|
|
|
*/
|
|
|
|
Lst_ForEach(targets, ParseDoSpecialSrc, (ClientData)&ss);
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
gn = Targ_FindNode (src, TARG_CREATE);
|
|
|
|
if (tOp) {
|
|
|
|
gn->type |= tOp;
|
|
|
|
} else {
|
|
|
|
Lst_ForEach (targets, ParseLinkSrc, (ClientData)gn);
|
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gn->order = waiting;
|
|
|
|
(void)Lst_AtEnd(allsrc, (ClientData)gn);
|
|
|
|
if (waiting) {
|
|
|
|
Lst_ForEach(allsrc, ParseAddDep, (ClientData)gn);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* gnp Node to examine
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* 0 if main not found yet, 1 if it is.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* mainNode is changed and Targ_SetMain is called.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseFindMain(ClientData gnp, ClientData dummy)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
GNode *gn = (GNode *) gnp;
|
1997-05-02 18:24:27 +04:00
|
|
|
if ((gn->type & OP_NOTARGET) == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
mainNode = gn;
|
|
|
|
Targ_SetMain(gn);
|
1994-06-07 02:45:17 +04:00
|
|
|
return (dummy ? 1 : 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
1994-06-07 02:45:17 +04:00
|
|
|
return (dummy ? 0 : 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseAddDir --
|
|
|
|
* Front-end for Dir_AddDir to make sure Lst_ForEach keeps going
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* === 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* See Dir_AddDir.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseAddDir(ClientData path, ClientData name)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-05-09 01:24:41 +04:00
|
|
|
(void) Dir_AddDir((Lst) path, (char *) name);
|
1993-03-21 12:45:37 +03: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-06-15 22:24:55 +04:00
|
|
|
ParseClearPath(ClientData path, ClientData dummy)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
Dir_ClearPath((Lst) path);
|
|
|
|
return(dummy ? 0 : 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoDependency --
|
|
|
|
* Parse the dependency line in line.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* line the line to parse
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseDoDependency(char *line)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
char *cp; /* our current position */
|
|
|
|
GNode *gn; /* a general purpose temporary node */
|
|
|
|
int op; /* the operator on the line */
|
1993-03-21 12:45:37 +03:00
|
|
|
char savec; /* a place to save a character */
|
|
|
|
Lst paths; /* List of search paths to alter when parsing
|
|
|
|
* a list of .PATH targets */
|
|
|
|
int tOp; /* operator from special target */
|
1995-12-16 08:03:09 +03:00
|
|
|
Lst sources; /* list of archive source names after
|
|
|
|
* expansion */
|
1993-03-21 12:45:37 +03:00
|
|
|
Lst curTargs; /* list of target names to be found and added
|
|
|
|
* to the targets list */
|
1995-12-16 08:03:09 +03:00
|
|
|
Lst curSrcs; /* list of sources in order */
|
2002-01-26 23:42:14 +03:00
|
|
|
char *lstart = line;
|
2003-03-23 02:41:02 +03:00
|
|
|
Boolean hasWait; /* is .WAIT present in srcs */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
tOp = 0;
|
|
|
|
|
|
|
|
specType = Not;
|
1995-12-16 08:03:09 +03:00
|
|
|
waiting = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
paths = (Lst)NULL;
|
|
|
|
|
|
|
|
curTargs = Lst_Init(FALSE);
|
1995-12-16 08:03:09 +03:00
|
|
|
curSrcs = Lst_Init(FALSE);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
|
|
|
for (cp = line;
|
2002-01-26 23:42:14 +03:00
|
|
|
*cp && (ParseIsEscaped(lstart, cp) ||
|
|
|
|
(!isspace ((unsigned char)*cp) &&
|
|
|
|
(*cp != '!') && (*cp != ':') && (*cp != LPAREN)));
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
int length;
|
|
|
|
Boolean freeIt;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
result=Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt);
|
|
|
|
|
|
|
|
if (freeIt) {
|
|
|
|
free(result);
|
|
|
|
}
|
|
|
|
cp += length-1;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2002-01-26 23:42:14 +03:00
|
|
|
if (!ParseIsEscaped(lstart, cp) && *cp == LPAREN) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (Arch_ParseArchive (&line, targets, VAR_CMD) != SUCCESS) {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
|
|
|
"Error in archive specification: \"%s\"", line);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
savec = *cp;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!*cp) {
|
|
|
|
/*
|
|
|
|
* Ending a dependency line without an operator is a Bozo
|
2001-06-02 18:25:23 +04:00
|
|
|
* no-no. As a heuristic, this is also often triggered by
|
|
|
|
* undetected conflicts from cvs/rcs merges.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2001-06-02 18:25:23 +04:00
|
|
|
if ((strncmp(line, "<<<<<<", 6) == 0) ||
|
|
|
|
(strncmp(line, "======", 6) == 0) ||
|
|
|
|
(strncmp(line, ">>>>>>", 6) == 0))
|
2001-06-02 20:17:08 +04:00
|
|
|
Parse_Error (PARSE_FATAL,
|
2001-06-02 22:04:44 +04:00
|
|
|
"Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
|
2001-06-02 18:25:23 +04:00
|
|
|
else
|
|
|
|
Parse_Error (PARSE_FATAL, "Need an operator");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
/*
|
|
|
|
* Have a word in line. See if it's a special target and set
|
|
|
|
* specType to match it.
|
|
|
|
*/
|
1998-11-07 02:31:09 +03:00
|
|
|
if (*line == '.' && isupper ((unsigned char)line[1])) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* See if the target is a special target that must have it
|
1996-11-06 20:58:58 +03:00
|
|
|
* or its sources handled specially.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
int keywd = ParseFindKeyword(line);
|
|
|
|
if (keywd != -1) {
|
1994-03-05 03:34:29 +03:00
|
|
|
if (specType == ExPath && parseKeywords[keywd].spec != ExPath) {
|
1993-03-21 12:45:37 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Mismatched special targets");
|
|
|
|
return;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03: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-03-16 00:52:32 +03:00
|
|
|
* .PHONY The list of targets
|
1997-05-09 01:24:41 +04:00
|
|
|
* .NOPATH Don't search for file in the path
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
* .ORDER Must set initial predecessor to NIL
|
|
|
|
*/
|
|
|
|
switch (specType) {
|
1994-03-05 03:34:29 +03:00
|
|
|
case ExPath:
|
1993-03-21 12:45:37 +03:00
|
|
|
if (paths == NULL) {
|
|
|
|
paths = Lst_Init(FALSE);
|
|
|
|
}
|
|
|
|
(void)Lst_AtEnd(paths, (ClientData)dirSearchPath);
|
|
|
|
break;
|
|
|
|
case Main:
|
|
|
|
if (!Lst_IsEmpty(create)) {
|
|
|
|
specType = Not;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case Interrupt:
|
|
|
|
gn = Targ_FindNode(line, TARG_CREATE);
|
|
|
|
gn->type |= OP_NOTMAIN;
|
|
|
|
(void)Lst_AtEnd(targets, (ClientData)gn);
|
|
|
|
break;
|
|
|
|
case Default:
|
|
|
|
gn = Targ_NewGN(".DEFAULT");
|
|
|
|
gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
|
|
|
|
(void)Lst_AtEnd(targets, (ClientData)gn);
|
|
|
|
DEFAULT = gn;
|
|
|
|
break;
|
|
|
|
case NotParallel:
|
|
|
|
{
|
|
|
|
maxJobs = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SingleShell:
|
2000-12-05 20:07:01 +03:00
|
|
|
compatMake = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case Order:
|
|
|
|
predecessor = NILGNODE;
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
default:
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
} else if (strncmp (line, ".PATH", 5) == 0) {
|
|
|
|
/*
|
|
|
|
* .PATH<suffix> has to be handled specially.
|
|
|
|
* Call on the suffix module to give us a path to
|
|
|
|
* modify.
|
|
|
|
*/
|
|
|
|
Lst path;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
specType = ExPath;
|
1993-03-21 12:45:37 +03:00
|
|
|
path = Suff_GetPath (&line[5]);
|
|
|
|
if (path == NILLST) {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
|
|
|
"Suffix '%s' not defined (yet)",
|
|
|
|
&line[5]);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (paths == (Lst)NULL) {
|
|
|
|
paths = Lst_Init(FALSE);
|
|
|
|
}
|
|
|
|
(void)Lst_AtEnd(paths, (ClientData)path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Have word in line. Get or create its node and stick it at
|
1996-11-06 20:58:58 +03:00
|
|
|
* the end of the targets list
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
if ((specType == Not) && (*line != '\0')) {
|
|
|
|
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...
|
|
|
|
*/
|
|
|
|
Lst emptyPath = Lst_Init(FALSE);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
Dir_Expand(line, emptyPath, curTargs);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
Lst_Destroy(emptyPath, Dir_Destroy);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No wildcards, but we want to avoid code duplication,
|
|
|
|
* so create a list with the word on it.
|
|
|
|
*/
|
|
|
|
(void)Lst_AtEnd(curTargs, (ClientData)line);
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
while(!Lst_IsEmpty(curTargs)) {
|
|
|
|
char *targName = (char *)Lst_DeQueue(curTargs);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!Suff_IsTransform (targName)) {
|
|
|
|
gn = Targ_FindNode (targName, TARG_CREATE);
|
|
|
|
} else {
|
|
|
|
gn = Suff_AddTransform (targName);
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)Lst_AtEnd (targets, (ClientData)gn);
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
} else if (specType == ExPath && *line != '.' && *line != '\0') {
|
1993-03-21 12:45:37 +03:00
|
|
|
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = savec;
|
|
|
|
/*
|
|
|
|
* If it is a special type and not .PATH, it's the only target we
|
|
|
|
* allow on this line...
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
if (specType != Not && specType != ExPath) {
|
1993-03-21 12:45:37 +03:00
|
|
|
Boolean warn = FALSE;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
while (*cp && (ParseIsEscaped(lstart, cp) ||
|
|
|
|
((*cp != '!') && (*cp != ':')))) {
|
|
|
|
if (ParseIsEscaped(lstart, cp) ||
|
|
|
|
(*cp != ' ' && *cp != '\t')) {
|
1993-03-21 12:45:37 +03:00
|
|
|
warn = TRUE;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (warn) {
|
|
|
|
Parse_Error(PARSE_WARNING, "Extra target ignored");
|
|
|
|
}
|
|
|
|
} else {
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = cp;
|
2002-01-26 23:42:14 +03:00
|
|
|
} while (*line && (ParseIsEscaped(lstart, line) ||
|
|
|
|
((*line != '!') && (*line != ':'))));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't need the list of target names anymore...
|
|
|
|
*/
|
|
|
|
Lst_Destroy(curTargs, NOFREE);
|
|
|
|
|
|
|
|
if (!Lst_IsEmpty(targets)) {
|
|
|
|
switch(specType) {
|
|
|
|
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 {
|
|
|
|
Parse_Error (PARSE_FATAL, "Missing dependency operator");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cp++; /* Advance beyond operator */
|
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_ForEach (targets, ParseDoOp, (ClientData)&op);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* Get to the first source
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03: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:
|
|
|
|
Suff_ClearSuffixes ();
|
|
|
|
break;
|
|
|
|
case Precious:
|
|
|
|
allPrecious = TRUE;
|
|
|
|
break;
|
|
|
|
case Ignore:
|
|
|
|
ignoreErrors = TRUE;
|
|
|
|
break;
|
|
|
|
case Silent:
|
|
|
|
beSilent = TRUE;
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case ExPath:
|
1993-03-21 12:45:37 +03:00
|
|
|
Lst_ForEach(paths, ParseClearPath, (ClientData)NULL);
|
2002-11-26 09:12:59 +03:00
|
|
|
Dir_SetPATH();
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2000-05-11 12:22:40 +04:00
|
|
|
#ifdef POSIX
|
|
|
|
case Posix:
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set("%POSIX", "1003.2", VAR_GLOBAL, 0);
|
2000-05-11 12:22:40 +04:00
|
|
|
break;
|
|
|
|
#endif
|
1994-03-05 03:34:29 +03:00
|
|
|
default:
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
} 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
|
|
|
|
*/
|
|
|
|
Main_ParseArgLine (line);
|
|
|
|
*line = '\0';
|
1994-03-05 03:34:29 +03:00
|
|
|
} else if (specType == ExShell) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (Job_ParseShell (line) != SUCCESS) {
|
|
|
|
Parse_Error (PARSE_FATAL, "improper shell specification");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*line = '\0';
|
|
|
|
} else if ((specType == NotParallel) || (specType == SingleShell)) {
|
|
|
|
*line = '\0';
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* NOW GO FOR THE SOURCES
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
if ((specType == Suffixes) || (specType == ExPath) ||
|
1993-03-21 12:45:37 +03:00
|
|
|
(specType == Includes) || (specType == Libs) ||
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
(specType == Null) || (specType == ExObjdir))
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
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.
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
*
|
|
|
|
* If it was .OBJDIR, the source is a new definition for .OBJDIR,
|
|
|
|
* and will cause make to do a new chdir to that path.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && !isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
savec = *cp;
|
|
|
|
*cp = '\0';
|
|
|
|
switch (specType) {
|
|
|
|
case Suffixes:
|
1997-05-02 18:24:27 +04:00
|
|
|
Suff_AddSuffix (line, &mainNode);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case ExPath:
|
1993-03-21 12:45:37 +03:00
|
|
|
Lst_ForEach(paths, ParseAddDir, (ClientData)line);
|
|
|
|
break;
|
|
|
|
case Includes:
|
|
|
|
Suff_AddInclude (line);
|
|
|
|
break;
|
|
|
|
case Libs:
|
|
|
|
Suff_AddLib (line);
|
|
|
|
break;
|
|
|
|
case Null:
|
|
|
|
Suff_SetNull (line);
|
|
|
|
break;
|
Overhaul the initialization and handling of .OBJDIR:
* Replace chdir_verify_path() with Main_SetObjdir(), which can be called
externally, and can take a "const char *". (There's a lot of non-const
"char *" passing around in var.c of what should be const strings....)
* Rewrite the initial "find my .OBJDIR" code to make use of the new
function. This still functions as it had in the past, but the comment
above this block was changed to reflect reality: if MAKEOBJDIRPREFIX
or MAKEOBJDIR are set in the environment, then *only that value* is
tried; make does not fall back to obj.MACHINE, obj, and /usr/obj/`pwd`
as it would without these env vars set.
* Add a new special target, .OBJDIR:, which when parsed will cause make to
change to a new object directory and reset .OBJDIR, and PWD in the
environment. This will allow some makefiles (mainly, src/tools)
to override the default objdir semantics in order to add custom logic.
2001-10-31 06:59:42 +03:00
|
|
|
case ExObjdir:
|
|
|
|
Main_SetObjdir(line);
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
default:
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
*cp = savec;
|
|
|
|
if (savec != '\0') {
|
|
|
|
cp++;
|
|
|
|
}
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
}
|
|
|
|
if (paths) {
|
|
|
|
Lst_Destroy(paths, NOFREE);
|
|
|
|
}
|
2002-11-26 09:12:59 +03:00
|
|
|
if (specType == ExPath)
|
|
|
|
Dir_SetPATH();
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2003-03-23 02:41:02 +03:00
|
|
|
/*
|
|
|
|
* We don't need ParseDoSpecialSrc unless .WAIT is present.
|
|
|
|
*/
|
|
|
|
hasWait = (strstr(line, ".WAIT") != NULL);
|
|
|
|
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && !isspace ((unsigned char)*cp)) {
|
2002-01-26 23:42:14 +03:00
|
|
|
if ((*cp == LPAREN) && (cp > line) && (cp[-1] != '$')) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
if (*cp == LPAREN) {
|
1993-03-21 12:45:37 +03:00
|
|
|
sources = Lst_Init (FALSE);
|
|
|
|
if (Arch_ParseArchive (&line, sources, VAR_CMD) != SUCCESS) {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
|
|
|
"Error in source archive spec \"%s\"", line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!Lst_IsEmpty (sources)) {
|
|
|
|
gn = (GNode *) Lst_DeQueue (sources);
|
2003-03-23 02:41:02 +03:00
|
|
|
ParseDoSrc (tOp, gn->name, curSrcs, hasWait);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
Lst_Destroy (sources, NOFREE);
|
|
|
|
cp = line;
|
|
|
|
} else {
|
|
|
|
if (*cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp += 1;
|
|
|
|
}
|
|
|
|
|
2003-03-23 02:41:02 +03:00
|
|
|
ParseDoSrc (tOp, line, curSrcs, hasWait);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-11-07 02:31:09 +03:00
|
|
|
while (*cp && isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (mainNode == NILGNODE) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
Lst_ForEach (targets, ParseFindMain, (ClientData)0);
|
|
|
|
}
|
|
|
|
|
1995-12-16 08:03:09 +03:00
|
|
|
/*
|
|
|
|
* Finally, destroy the list of sources
|
|
|
|
*/
|
|
|
|
Lst_Destroy(curSrcs, NOFREE);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* line the line to check
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* TRUE if it is. FALSE if it ain't
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* none
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Boolean
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_IsVar(char *line)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
Boolean wasSpace = FALSE; /* set TRUE if found a space */
|
|
|
|
Boolean haveName = FALSE; /* Set TRUE if have a variable name */
|
1995-09-10 07:58:16 +04:00
|
|
|
int level = 0;
|
|
|
|
#define ISEQOPERATOR(c) \
|
|
|
|
(((c) == '+') || ((c) == ':') || ((c) == '?') || ((c) == '!'))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to variable name
|
|
|
|
*/
|
1996-11-06 20:58:58 +03:00
|
|
|
for (;(*line == ' ') || (*line == '\t'); line++)
|
1995-09-10 07:58:16 +04:00
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-09-10 07:58:16 +04:00
|
|
|
for (; *line != '=' || level != 0; line++)
|
|
|
|
switch (*line) {
|
|
|
|
case '\0':
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* end-of-line -- can't be a variable assignment.
|
|
|
|
*/
|
1995-09-10 07:58:16 +04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* there can be as much white space as desired so long as there is
|
1996-11-06 20:58:58 +03:00
|
|
|
* only one word before the operator
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
wasSpace = TRUE;
|
1995-09-10 07:58:16 +04:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
case LPAREN:
|
1995-09-10 07:58:16 +04:00
|
|
|
case '{':
|
|
|
|
level++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '}':
|
2002-01-26 23:42:14 +03:00
|
|
|
case RPAREN:
|
1995-09-10 07:58:16 +04:00
|
|
|
level--;
|
|
|
|
break;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1995-09-10 07:58:16 +04:00
|
|
|
default:
|
|
|
|
if (wasSpace && haveName) {
|
|
|
|
if (ISEQOPERATOR(*line)) {
|
1996-05-29 03:34:35 +04:00
|
|
|
/*
|
|
|
|
* We must have a finished word
|
|
|
|
*/
|
|
|
|
if (level != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
1995-09-10 07:58:16 +04:00
|
|
|
/*
|
|
|
|
* When an = operator [+?!:] is found, the next
|
1996-05-29 03:34:35 +04:00
|
|
|
* character must be an = or it ain't a valid
|
1995-09-10 07:58:16 +04:00
|
|
|
* assignment.
|
|
|
|
*/
|
1996-05-29 03:34:35 +04:00
|
|
|
if (line[1] == '=')
|
1995-09-10 07:58:16 +04:00
|
|
|
return haveName;
|
1996-05-29 03:34:35 +04:00
|
|
|
#ifdef SUNSHCMD
|
1995-09-10 07:58:16 +04:00
|
|
|
/*
|
1996-05-29 03:34:35 +04:00
|
|
|
* This is a shell command
|
1995-09-10 07:58:16 +04:00
|
|
|
*/
|
1996-05-29 03:34:35 +04:00
|
|
|
if (strncmp(line, ":sh", 3) == 0)
|
|
|
|
return haveName;
|
|
|
|
#endif
|
1995-09-10 07:58:16 +04:00
|
|
|
}
|
1996-05-29 03:34:35 +04:00
|
|
|
/*
|
|
|
|
* This is the start of another word, so not assignment.
|
|
|
|
*/
|
|
|
|
return FALSE;
|
1995-09-10 07:58:16 +04:00
|
|
|
}
|
|
|
|
else {
|
1996-11-06 20:58:58 +03:00
|
|
|
haveName = TRUE;
|
1995-09-10 07:58:16 +04:00
|
|
|
wasSpace = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1995-09-10 07:58:16 +04:00
|
|
|
return haveName;
|
1993-03-21 12:45:37 +03: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++ =".
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* line a line guaranteed to be a variable assignment.
|
|
|
|
* This reduces error checks
|
|
|
|
* ctxt Context in which to do the assignment
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* the variable structure of the given variable name is altered in the
|
|
|
|
* global context.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_DoVar(char *line, GNode *ctxt)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-03-08 01:22:01 +03:00
|
|
|
char *cp; /* pointer into line */
|
1993-03-21 12:45:37 +03:00
|
|
|
enum {
|
|
|
|
VAR_SUBST, VAR_APPEND, VAR_SHELL, VAR_NORMAL
|
|
|
|
} type; /* Type of assignment */
|
1996-11-06 20:58:58 +03:00
|
|
|
char *opc; /* ptr to operator character to
|
1993-03-21 12:45:37 +03:00
|
|
|
* null-terminate the variable name */
|
2002-12-01 08:53:30 +03:00
|
|
|
Boolean freeCp = FALSE; /* TRUE if cp needs to be freed,
|
|
|
|
* i.e. if any variable expansion was
|
|
|
|
* performed */
|
1996-11-06 20:58:58 +03:00
|
|
|
/*
|
1994-03-08 01:22:01 +03:00
|
|
|
* Avoid clobbered variable warnings by forcing the compiler
|
|
|
|
* to ``unregister'' variables
|
|
|
|
*/
|
|
|
|
#if __GNUC__
|
|
|
|
(void) &cp;
|
|
|
|
(void) &line;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03: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++) {
|
1998-11-07 02:31:09 +03:00
|
|
|
if (isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opc = cp-1; /* operator is the previous character */
|
|
|
|
*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-05-29 03:34:35 +04:00
|
|
|
#ifdef SUNSHCMD
|
1998-09-19 00:15:36 +04:00
|
|
|
while (opc > line && *opc != ':')
|
|
|
|
opc--;
|
1996-05-29 03:34:35 +04:00
|
|
|
|
|
|
|
if (strncmp(opc, ":sh", 3) == 0) {
|
|
|
|
type = VAR_SHELL;
|
|
|
|
*opc = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
type = VAR_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-11-07 02:31:09 +03:00
|
|
|
while (isspace ((unsigned char)*cp)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == VAR_APPEND) {
|
|
|
|
Var_Append (line, cp, ctxt);
|
|
|
|
} 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;
|
1999-06-02 22:47:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure that we set the variable the first time to nothing
|
|
|
|
* so that it gets substituted!
|
|
|
|
*/
|
|
|
|
if (!Var_Exists(line, ctxt))
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(line, "", ctxt, 0);
|
1999-06-02 22:47:11 +04:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
cp = Var_Subst(NULL, cp, ctxt, FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
oldVars = oldOldVars;
|
2002-12-01 08:53:30 +03:00
|
|
|
freeCp = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(line, cp, ctxt, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (type == VAR_SHELL) {
|
2003-07-14 22:19:11 +04:00
|
|
|
char *res;
|
|
|
|
const char *err;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
if (strchr(cp, '$') != NULL) {
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
1996-05-29 03:34:35 +04:00
|
|
|
cp = Var_Subst(NULL, cp, VAR_CMD, TRUE);
|
2002-12-01 08:53:30 +03:00
|
|
|
freeCp = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
res = Cmd_Exec(cp, &err);
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(line, res, ctxt, 0);
|
1996-05-29 03:34:35 +04:00
|
|
|
free(res);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
if (err)
|
|
|
|
Parse_Error(PARSE_WARNING, err, cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Normal assignment -- just do it.
|
|
|
|
*/
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(line, cp, ctxt, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2001-06-10 06:31:00 +04:00
|
|
|
if (strcmp(line, MAKEOVERRIDES) == 0)
|
2001-10-31 04:15:57 +03:00
|
|
|
Main_ExportMAKEFLAGS(FALSE); /* re-export MAKEFLAGS */
|
2002-11-26 09:12:59 +03:00
|
|
|
else if (strcmp(line, ".CURDIR") == 0) {
|
|
|
|
/*
|
|
|
|
* Somone is being (too?) clever...
|
|
|
|
* Let's pretend they know what they are doing and
|
|
|
|
* re-initialize the 'cur' Path.
|
|
|
|
*/
|
|
|
|
Dir_InitCur(cp);
|
|
|
|
Dir_SetPATH();
|
|
|
|
}
|
2002-12-01 08:53:30 +03:00
|
|
|
if (freeCp)
|
|
|
|
free(cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-05-29 03:34:35 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
* ParseAddCmd --
|
|
|
|
* Lst_ForEach function to add a command line to all targets
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* gnp the node to which the command is to be added
|
|
|
|
* cmd the command to add
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* Always 0
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A new element is added to the commands list of the node.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseAddCmd(ClientData gnp, ClientData cmd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
GNode *gn = (GNode *) gnp;
|
|
|
|
/* if target already supplied, ignore commands */
|
1999-09-16 04:54:14 +04:00
|
|
|
if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
|
1999-09-15 14:47:37 +04:00
|
|
|
gn = (GNode *) Lst_Datum (Lst_Last (gn->cohorts));
|
2001-01-14 08:34:06 +03:00
|
|
|
if (!(gn->type & OP_HAS_COMMANDS)) {
|
|
|
|
(void)Lst_AtEnd(gn->commands, cmd);
|
|
|
|
ParseMark(gn);
|
|
|
|
} else {
|
2001-01-14 08:41:08 +03:00
|
|
|
#ifdef notyet
|
|
|
|
/* XXX: We cannot do this until we fix the tree */
|
1994-06-07 02:45:17 +04:00
|
|
|
(void)Lst_AtEnd(gn->commands, cmd);
|
2001-01-10 18:54:00 +03:00
|
|
|
Parse_Error (PARSE_WARNING,
|
2001-01-14 09:02:25 +03:00
|
|
|
"overriding commands for target \"%s\"; "
|
|
|
|
"previous commands defined at %s: %d ignored",
|
2001-01-14 08:34:06 +03:00
|
|
|
gn->name, gn->fname, gn->lineno);
|
2001-01-14 08:41:08 +03:00
|
|
|
#else
|
|
|
|
Parse_Error (PARSE_WARNING,
|
2001-01-14 23:54:16 +03:00
|
|
|
"duplicate script for target \"%s\" ignored",
|
|
|
|
gn->name);
|
|
|
|
ParseErrorInternal (gn->fname, gn->lineno, PARSE_WARNING,
|
|
|
|
"using previous script for \"%s\" defined here",
|
|
|
|
gn->name);
|
2001-01-14 08:41:08 +03:00
|
|
|
#endif
|
2001-01-14 08:34:06 +03:00
|
|
|
}
|
1994-06-07 02:45:17 +04:00
|
|
|
return(0);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* gnp Node to examine
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
1994-06-07 02:45:17 +04:00
|
|
|
* None
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* OP_HAS_COMMANDS may be set for the target.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
1994-06-07 02:45:17 +04:00
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseHasCommands(ClientData gnp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
GNode *gn = (GNode *) gnp;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!Lst_IsEmpty(gn->commands)) {
|
|
|
|
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
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* dir The name of the directory to add
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The directory is appended to the list.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_AddIncludeDir(char *dir)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-05-09 01:24:41 +04:00
|
|
|
(void) Dir_AddDir (parseIncPath, dir);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseDoInclude --
|
|
|
|
* Push to another file.
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
1998-08-06 17:42:22 +04:00
|
|
|
* The input is the line minus the `.'. A file spec is a string
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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:
|
|
|
|
* A structure is added to the includes Lst and readProc, lineno,
|
|
|
|
* fname and curFILE are altered for the new file
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseDoInclude(char *line)
|
1993-03-21 12:45:37 +03: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 */
|
1998-08-06 17:42:22 +04:00
|
|
|
int silent = (*line != 'i') ? 1 : 0;
|
|
|
|
char *file = &line[7 + silent];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to delimiter character so we know where to look
|
|
|
|
*/
|
|
|
|
while ((*file == ' ') || (*file == '\t')) {
|
|
|
|
file++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*file != '"') && (*file != '<')) {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
|
|
|
".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) {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
1994-03-05 03:34:29 +03:00
|
|
|
"Unclosed %cinclude filename. '%c' expected",
|
|
|
|
'.', endc);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
file = Var_Subst (NULL, file, VAR_CMD, FALSE);
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*/
|
2002-01-24 04:39:03 +03:00
|
|
|
fullname = (char *)NULL;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
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-02-08 02:04:04 +03:00
|
|
|
char *prefEnd, *Fname;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-02-08 02:04:04 +03:00
|
|
|
/* Make a temporary copy of this, to be safe. */
|
2002-02-22 01:21:34 +03:00
|
|
|
Fname = estrdup(curFile.fname);
|
1996-02-08 02:04:04 +03:00
|
|
|
|
|
|
|
prefEnd = strrchr (Fname, '/');
|
1993-03-21 12:45:37 +03:00
|
|
|
if (prefEnd != (char *)NULL) {
|
|
|
|
char *newName;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
*prefEnd = '\0';
|
1994-06-07 02:45:17 +04:00
|
|
|
if (file[0] == '/')
|
1996-08-13 20:42:00 +04:00
|
|
|
newName = estrdup(file);
|
1994-06-07 02:45:17 +04:00
|
|
|
else
|
1996-02-08 02:04:04 +03:00
|
|
|
newName = str_concat (Fname, file, STR_ADDSLASH);
|
1993-03-21 12:45:37 +03:00
|
|
|
fullname = Dir_FindFile (newName, parseIncPath);
|
|
|
|
if (fullname == (char *)NULL) {
|
|
|
|
fullname = Dir_FindFile(newName, dirSearchPath);
|
|
|
|
}
|
|
|
|
free (newName);
|
|
|
|
*prefEnd = '/';
|
|
|
|
} else {
|
|
|
|
fullname = (char *)NULL;
|
|
|
|
}
|
1996-02-08 02:04:04 +03:00
|
|
|
free (Fname);
|
2002-01-24 04:39:03 +03:00
|
|
|
if (fullname == (char *)NULL) {
|
|
|
|
/*
|
|
|
|
* 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?
|
|
|
|
*/
|
|
|
|
fullname = Dir_FindFile (file, parseIncPath);
|
|
|
|
if (fullname == (char *)NULL) {
|
|
|
|
fullname = Dir_FindFile(file, dirSearchPath);
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2002-01-24 04:39:03 +03:00
|
|
|
/* Looking for a system file or file still not found */
|
1993-03-21 12:45:37 +03:00
|
|
|
if (fullname == (char *)NULL) {
|
|
|
|
/*
|
2002-01-24 04:39:03 +03:00
|
|
|
* Look for it on the system path
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2001-10-31 04:15:57 +03:00
|
|
|
fullname = Dir_FindFile(file, Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fullname == (char *) NULL) {
|
|
|
|
*cp = endc;
|
1998-08-06 17:42:22 +04:00
|
|
|
if (!silent)
|
|
|
|
Parse_Error (PARSE_FATAL, "Could not find %s", file);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
free(file);
|
|
|
|
|
1993-03-21 12:45:37 +03: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...
|
|
|
|
*/
|
|
|
|
oldFile = (IFile *) emalloc (sizeof (IFile));
|
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
memcpy(oldFile, &curFile, sizeof (IFile));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
(void) Lst_AtFront (includes, (ClientData)oldFile);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.fname = fullname;
|
|
|
|
curFile.lineno = 0;
|
|
|
|
|
|
|
|
ParseSetParseFile(curFile.fname);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.F = fopen (fullname, "r");
|
|
|
|
curFile.P = NULL;
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.F == (FILE * ) NULL) {
|
1998-08-06 17:42:22 +04:00
|
|
|
if (!silent)
|
|
|
|
Parse_Error (PARSE_FATAL, "Cannot open %s", fullname);
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Pop to previous file
|
|
|
|
*/
|
|
|
|
(void) ParseEOF(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1999-08-10 01:06:28 +04:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseSetParseFile --
|
|
|
|
* Set the .PARSEDIR and .PARSEFILE variables to the dirname and
|
|
|
|
* basename of the given filename
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The .PARSEDIR and .PARSEFILE variables are overwritten by the
|
|
|
|
* dirname and basename of the given filename.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseSetParseFile(char *filename)
|
1999-08-10 01:06:28 +04:00
|
|
|
{
|
|
|
|
char *slash;
|
|
|
|
|
2002-01-27 04:50:54 +03:00
|
|
|
slash = strrchr(filename, '/');
|
1999-08-10 01:06:28 +04:00
|
|
|
if (slash == 0) {
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(".PARSEDIR", ".", VAR_GLOBAL, 0);
|
2002-01-27 04:50:54 +03:00
|
|
|
Var_Set(".PARSEFILE", filename, VAR_GLOBAL, 0);
|
1999-08-10 01:06:28 +04:00
|
|
|
} else {
|
|
|
|
*slash = '\0';
|
2002-01-27 04:50:54 +03:00
|
|
|
Var_Set(".PARSEDIR", filename, VAR_GLOBAL, 0);
|
2001-06-13 03:36:17 +04:00
|
|
|
Var_Set(".PARSEFILE", slash+1, VAR_GLOBAL, 0);
|
1999-08-10 01:06:28 +04:00
|
|
|
*slash = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_FromString --
|
|
|
|
* Start Parsing from the given string
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
1994-03-05 03:34:29 +03:00
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A structure is added to the includes Lst and readProc, lineno,
|
|
|
|
* fname and curFILE are altered for the new file
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_FromString(char *str)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
|
|
|
IFile *oldFile; /* state associated with this file */
|
|
|
|
|
|
|
|
if (DEBUG(FOR))
|
|
|
|
(void) fprintf(stderr, "%s\n----\n", str);
|
|
|
|
|
|
|
|
oldFile = (IFile *) emalloc (sizeof (IFile));
|
2002-02-22 01:21:34 +03:00
|
|
|
memcpy(oldFile, &curFile, sizeof (IFile));
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
(void) Lst_AtFront (includes, (ClientData)oldFile);
|
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.F = NULL;
|
|
|
|
curFile.P = (PTR *) emalloc (sizeof (PTR));
|
|
|
|
curFile.P->str = curFile.P->ptr = str;
|
|
|
|
curFile.lineno = 0;
|
|
|
|
curFile.fname = estrdup(curFile.fname);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SYSVINCLUDE
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseTraditionalInclude --
|
|
|
|
* Push to another file.
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
1998-08-06 17:42:22 +04:00
|
|
|
* The input is the current line. The file name(s) are
|
|
|
|
* following the "include".
|
1994-03-05 03:34:29 +03:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* A structure is added to the includes Lst and readProc, lineno,
|
|
|
|
* fname and curFILE are altered for the new file
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseTraditionalInclude(char *line)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
|
|
|
char *fullname; /* full pathname of file */
|
|
|
|
IFile *oldFile; /* state associated with current file */
|
|
|
|
char *cp; /* current position in file spec */
|
|
|
|
char *prefEnd;
|
1998-08-06 17:42:22 +04:00
|
|
|
int done = 0;
|
|
|
|
int silent = (line[0] != 'i') ? 1 : 0;
|
|
|
|
char *file = &line[silent + 7];
|
2002-02-22 01:21:34 +03:00
|
|
|
char *cfname;
|
|
|
|
size_t clineno;
|
1998-08-06 17:42:22 +04:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
cfname = curFile.fname;
|
|
|
|
clineno = curFile.lineno;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over whitespace
|
|
|
|
*/
|
1998-08-06 17:42:22 +04:00
|
|
|
while (isspace((unsigned char)*file))
|
1994-03-05 03:34:29 +03:00
|
|
|
file++;
|
|
|
|
|
|
|
|
if (*file == '\0') {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
|
|
|
"Filename missing from \"include\"");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
for (; !done; file = cp + 1) {
|
|
|
|
/*
|
|
|
|
* Skip to end of line or next whitespace
|
|
|
|
*/
|
|
|
|
for (cp = file; *cp && !isspace((unsigned char) *cp); cp++)
|
|
|
|
continue;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
if (*cp)
|
|
|
|
*cp = '\0';
|
|
|
|
else
|
|
|
|
done = 1;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
|
|
|
file = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
/*
|
|
|
|
* Now we know the file's name, we attempt to find the durn thing.
|
|
|
|
* A return of NULL indicates the file don't exist.
|
|
|
|
*
|
|
|
|
* Include files 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.
|
|
|
|
* XXX - this *does* search in the current directory, right?
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
prefEnd = strrchr(cfname, '/');
|
|
|
|
if (prefEnd != NULL) {
|
|
|
|
char *newName;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
*prefEnd = '\0';
|
|
|
|
newName = str_concat(cfname, file, STR_ADDSLASH);
|
|
|
|
fullname = Dir_FindFile(newName, parseIncPath);
|
|
|
|
if (fullname == NULL) {
|
|
|
|
fullname = Dir_FindFile(newName, dirSearchPath);
|
|
|
|
}
|
|
|
|
free (newName);
|
|
|
|
*prefEnd = '/';
|
|
|
|
} else {
|
|
|
|
fullname = NULL;
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
if (fullname == NULL) {
|
|
|
|
/*
|
|
|
|
* 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?
|
|
|
|
*/
|
|
|
|
fullname = Dir_FindFile(file, parseIncPath);
|
|
|
|
if (fullname == NULL) {
|
|
|
|
fullname = Dir_FindFile(file, dirSearchPath);
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
if (fullname == NULL) {
|
|
|
|
/*
|
|
|
|
* Still haven't found the makefile. Look for it on the system
|
|
|
|
* path as a last resort.
|
|
|
|
*/
|
2001-10-31 04:15:57 +03:00
|
|
|
fullname = Dir_FindFile(file,
|
|
|
|
Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
|
1998-08-06 17:42:22 +04:00
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
if (fullname == NULL) {
|
|
|
|
if (!silent)
|
|
|
|
ParseErrorInternal(cfname, clineno, PARSE_FATAL,
|
|
|
|
"Could not find %s", file);
|
|
|
|
free(file);
|
|
|
|
continue;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
free(file);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04: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...
|
|
|
|
*/
|
|
|
|
oldFile = (IFile *) emalloc(sizeof(IFile));
|
2002-02-22 01:21:34 +03:00
|
|
|
memcpy(oldFile, &curFile, sizeof (IFile));
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1998-08-06 17:42:22 +04:00
|
|
|
(void) Lst_AtFront(includes, (ClientData)oldFile);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
|
|
|
/*
|
1998-08-06 17:42:22 +04: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.
|
1994-03-05 03:34:29 +03:00
|
|
|
*/
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.fname = fullname;
|
|
|
|
curFile.lineno = 0;
|
|
|
|
|
|
|
|
curFile.F = fopen(fullname, "r");
|
|
|
|
curFile.P = NULL;
|
1998-08-06 17:42:22 +04:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.F == NULL) {
|
1998-08-06 17:42:22 +04:00
|
|
|
if (!silent)
|
|
|
|
ParseErrorInternal(cfname, clineno, PARSE_FATAL,
|
|
|
|
"Cannot open %s", fullname);
|
|
|
|
/*
|
|
|
|
* Pop to previous file
|
|
|
|
*/
|
|
|
|
(void) ParseEOF(1);
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* 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:
|
|
|
|
* The old curFILE, is closed. The includes list is shortened.
|
|
|
|
* lineno, curFILE, and fname are changed if CONTINUE is returned.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseEOF(int opened)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
IFile *ifile; /* the state on the top of the includes stack */
|
|
|
|
|
|
|
|
if (Lst_IsEmpty (includes)) {
|
1999-08-10 01:06:28 +04:00
|
|
|
Var_Delete(".PARSEDIR", VAR_GLOBAL);
|
|
|
|
Var_Delete(".PARSEFILE", VAR_GLOBAL);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ifile = (IFile *) Lst_DeQueue (includes);
|
2002-02-22 01:21:34 +03:00
|
|
|
|
|
|
|
/* XXX dispose of curFile info */
|
|
|
|
free ((Address) curFile.fname);
|
|
|
|
if (opened && curFile.F)
|
|
|
|
(void) fclose (curFile.F);
|
|
|
|
if (curFile.P) {
|
|
|
|
free((Address) curFile.P->str);
|
|
|
|
free((Address) curFile.P);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
2002-02-22 01:21:34 +03:00
|
|
|
|
|
|
|
memcpy(&curFile, ifile, sizeof (IFile));
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
free ((Address)ifile);
|
1999-08-10 01:06:28 +04:00
|
|
|
|
|
|
|
/* pop the PARSEDIR/PARSEFILE variables */
|
2002-02-22 01:21:34 +03:00
|
|
|
ParseSetParseFile(curFile.fname);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseReadc --
|
1996-11-06 20:58:58 +03:00
|
|
|
* Read a character from the current file
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The character that was read
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
1999-08-04 06:54:56 +04:00
|
|
|
static __inline int
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseReadc(void)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.F)
|
|
|
|
return fgetc(curFile.F);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.P && *curFile.P->ptr)
|
|
|
|
return *curFile.P->ptr++;
|
1994-03-05 03:34:29 +03:00
|
|
|
return EOF;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseUnreadc --
|
1996-11-06 20:58:58 +03:00
|
|
|
* Put back a character to the current file
|
1994-03-05 03:34:29 +03:00
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseUnreadc(int c)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.F) {
|
|
|
|
ungetc(c, curFile.F);
|
1994-03-05 03:34:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-02-22 01:21:34 +03:00
|
|
|
if (curFile.P) {
|
|
|
|
*--(curFile.P->ptr) = c;
|
1994-03-05 03:34:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ParseSkipLine():
|
|
|
|
* Grab the next line
|
2002-06-15 22:24:55 +04:00
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* skip Skip lines that don't start with .
|
|
|
|
*
|
1994-03-05 03:34:29 +03:00
|
|
|
*/
|
|
|
|
static char *
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseSkipLine(int skip)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
|
|
|
char *line;
|
1996-11-06 20:58:58 +03:00
|
|
|
int c, lastc, lineLength = 0;
|
1994-03-05 03:34:29 +03:00
|
|
|
Buffer buf;
|
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
buf = Buf_Init(MAKE_BSIZE);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1996-11-06 20:58:58 +03:00
|
|
|
do {
|
|
|
|
Buf_Discard(buf, lineLength);
|
|
|
|
lastc = '\0';
|
|
|
|
|
|
|
|
while (((c = ParseReadc()) != '\n' || lastc == '\\')
|
|
|
|
&& c != EOF) {
|
|
|
|
if (c == '\n') {
|
|
|
|
Buf_ReplaceLastByte(buf, (Byte)' ');
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.lineno++;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
|
|
|
while ((c = ParseReadc()) == ' ' || c == '\t');
|
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buf_AddByte(buf, (Byte)c);
|
|
|
|
lastc = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == EOF) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Unclosed conditional/for loop");
|
|
|
|
Buf_Destroy(buf, TRUE);
|
|
|
|
return((char *)NULL);
|
|
|
|
}
|
|
|
|
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.lineno++;
|
1996-11-06 20:58:58 +03:00
|
|
|
Buf_AddByte(buf, (Byte)'\0');
|
|
|
|
line = (char *)Buf_GetAll(buf, &lineLength);
|
|
|
|
} while (skip == 1 && line[0] != '.');
|
|
|
|
|
|
|
|
Buf_Destroy(buf, FALSE);
|
1994-03-05 03:34:29 +03:00
|
|
|
return line;
|
|
|
|
}
|
1993-03-21 12:45:37 +03: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 *
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseReadLine(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
Buffer buf; /* Buffer for current line */
|
2002-06-15 22:24:55 +04:00
|
|
|
int c; /* the current character */
|
|
|
|
int lastc; /* The most-recent character */
|
1993-03-21 12:45:37 +03: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 */
|
1994-06-07 02:45:17 +04:00
|
|
|
char *line; /* Result */
|
1995-01-06 22:57:27 +03:00
|
|
|
char *ep; /* to strip trailing blanks */
|
1993-03-21 12:45:37 +03:00
|
|
|
int lineLength; /* Length of result */
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
for (;;) {
|
1993-03-21 12:45:37 +03:00
|
|
|
c = ParseReadc();
|
|
|
|
|
|
|
|
if (c == '\t') {
|
|
|
|
ignComment = ignDepOp = TRUE;
|
|
|
|
break;
|
|
|
|
} else if (c == '\n') {
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.lineno++;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (c == '#') {
|
1994-03-05 03:34:29 +03:00
|
|
|
ParseUnreadc(c);
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Anything else breaks out without doing anything
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (c != EOF) {
|
|
|
|
lastc = c;
|
1994-03-05 03:34:29 +03:00
|
|
|
buf = Buf_Init(MAKE_BSIZE);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
while (((c = ParseReadc ()) != '\n' || (lastc == '\\')) &&
|
|
|
|
(c != EOF))
|
|
|
|
{
|
|
|
|
test_char:
|
|
|
|
switch(c) {
|
|
|
|
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...
|
|
|
|
*/
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.lineno++;
|
1993-03-21 12:45:37 +03:00
|
|
|
lastc = ' ';
|
|
|
|
while ((c = ParseReadc ()) == ' ' || c == '\t') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == EOF || c == '\n') {
|
|
|
|
goto line_read;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check for comments, semiNL's, etc. -- easier than
|
1994-03-05 03:34:29 +03:00
|
|
|
* ParseUnreadc(c); continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
goto test_char;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
/*NOTREACHED*/
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
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.
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
ParseUnreadc('\t');
|
1993-03-21 12:45:37 +03:00
|
|
|
goto line_read;
|
1996-11-06 20:58:58 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03: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?
|
|
|
|
*/
|
|
|
|
ignDepOp = TRUE; semiNL = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
if (!ignComment) {
|
1995-11-03 02:54:35 +03:00
|
|
|
if (
|
|
|
|
#if 0
|
|
|
|
compatMake &&
|
|
|
|
#endif
|
|
|
|
(lastc != '\\')) {
|
1993-03-21 12:45:37 +03: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;
|
1994-03-05 03:34:29 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Don't add the backslash. Just let the # get copied
|
|
|
|
* over.
|
|
|
|
*/
|
|
|
|
lastc = c;
|
|
|
|
continue;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Copy in the previous character and save this one in lastc.
|
|
|
|
*/
|
|
|
|
Buf_AddByte (buf, (Byte)lastc);
|
|
|
|
lastc = c;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
line_read:
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.lineno++;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (lastc != '\0') {
|
|
|
|
Buf_AddByte (buf, (Byte)lastc);
|
|
|
|
}
|
|
|
|
Buf_AddByte (buf, (Byte)'\0');
|
|
|
|
line = (char *)Buf_GetAll (buf, &lineLength);
|
|
|
|
Buf_Destroy (buf, FALSE);
|
1995-01-06 22:57:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip trailing blanks and tabs from the line.
|
2001-08-20 16:00:46 +04:00
|
|
|
* Do not strip a blank or tab that is preceded by
|
1995-01-06 22:57:27 +03:00
|
|
|
* a '\'
|
|
|
|
*/
|
|
|
|
ep = line;
|
|
|
|
while (*ep)
|
|
|
|
++ep;
|
1996-11-06 20:58:58 +03:00
|
|
|
while (ep > line + 1 && (ep[-1] == ' ' || ep[-1] == '\t')) {
|
1995-01-06 22:57:27 +03:00
|
|
|
if (ep > line + 1 && ep[-2] == '\\')
|
|
|
|
break;
|
|
|
|
--ep;
|
|
|
|
}
|
|
|
|
*ep = 0;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (line[0] == '.') {
|
|
|
|
/*
|
|
|
|
* The line might be a conditional. Ask the conditional module
|
|
|
|
* about it and act accordingly
|
|
|
|
*/
|
|
|
|
switch (Cond_Eval (line)) {
|
|
|
|
case COND_SKIP:
|
1994-03-05 03:34:29 +03:00
|
|
|
/*
|
|
|
|
* Skip to next conditional that evaluates to COND_PARSE.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
|
|
|
free (line);
|
1994-03-05 03:34:29 +03:00
|
|
|
line = ParseSkipLine(1);
|
|
|
|
} while (line && Cond_Eval(line) != COND_PARSE);
|
|
|
|
if (line == NULL)
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
/*FALLTHRU*/
|
|
|
|
case COND_PARSE:
|
1994-03-05 03:34:29 +03:00
|
|
|
free ((Address) line);
|
1993-03-21 12:45:37 +03:00
|
|
|
line = ParseReadLine();
|
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case COND_INVALID:
|
|
|
|
if (For_Eval(line)) {
|
|
|
|
int ok;
|
|
|
|
free(line);
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* Skip after the matching end
|
|
|
|
*/
|
|
|
|
line = ParseSkipLine(0);
|
|
|
|
if (line == NULL) {
|
1996-11-06 20:58:58 +03:00
|
|
|
Parse_Error (PARSE_FATAL,
|
1994-03-05 03:34:29 +03:00
|
|
|
"Unexpected end of file in for loop.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ok = For_Eval(line);
|
|
|
|
free(line);
|
|
|
|
}
|
|
|
|
while (ok);
|
|
|
|
if (line != NULL)
|
|
|
|
For_Run();
|
|
|
|
line = ParseReadLine();
|
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (line);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Hit end-of-file, so return a NULL line to indicate this.
|
|
|
|
*/
|
|
|
|
return((char *)NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseFinishLine --
|
|
|
|
* Handle the end of a dependency group.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* Nothing.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* inLine set FALSE. 'targets' list destroyed.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseFinishLine(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (inLine) {
|
|
|
|
Lst_ForEach(targets, Suff_EndTransform, (ClientData)NULL);
|
|
|
|
Lst_Destroy (targets, ParseHasCommands);
|
1994-06-07 02:45:17 +04:00
|
|
|
targets = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
inLine = FALSE;
|
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03: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
|
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
|
|
|
* name the name of the file being read
|
|
|
|
* stream Stream open to makefile to parse
|
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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
|
2003-07-14 22:19:11 +04:00
|
|
|
Parse_File(const char *name, FILE *stream)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-06-15 22:24:55 +04:00
|
|
|
char *cp, /* pointer into the line */
|
1993-03-21 12:45:37 +03:00
|
|
|
*line; /* the line we're working on */
|
|
|
|
|
|
|
|
inLine = FALSE;
|
|
|
|
fatals = 0;
|
|
|
|
|
2003-07-14 22:19:11 +04:00
|
|
|
curFile.fname = UNCONST(name);
|
2002-02-22 01:21:34 +03:00
|
|
|
curFile.F = stream;
|
|
|
|
curFile.lineno = 0;
|
|
|
|
|
|
|
|
ParseSetParseFile(curFile.fname);
|
1999-08-10 01:06:28 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
1994-03-05 03:34:29 +03:00
|
|
|
while ((line = ParseReadLine ()) != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*line == '.') {
|
|
|
|
/*
|
|
|
|
* Lines that begin with the special character are either
|
|
|
|
* include or undef directives.
|
|
|
|
*/
|
1998-11-07 02:31:09 +03:00
|
|
|
for (cp = line + 1; isspace ((unsigned char)*cp); cp++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
1998-08-06 17:42:22 +04:00
|
|
|
if (strncmp(cp, "include", 7) == 0 ||
|
|
|
|
((cp[0] == 's' || cp[0] == '-') &&
|
1998-11-18 02:56:23 +03:00
|
|
|
strncmp(&cp[1], "include", 7) == 0)) {
|
1998-08-06 17:42:22 +04:00
|
|
|
ParseDoInclude (cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
goto nextLine;
|
|
|
|
} else if (strncmp(cp, "undef", 5) == 0) {
|
|
|
|
char *cp2;
|
1994-06-07 02:45:17 +04:00
|
|
|
for (cp += 5; isspace((unsigned char) *cp); cp++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
for (cp2 = cp; !isspace((unsigned char) *cp2) &&
|
|
|
|
(*cp2 != '\0'); cp2++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cp2 = '\0';
|
|
|
|
|
|
|
|
Var_Delete(cp, VAR_GLOBAL);
|
|
|
|
goto nextLine;
|
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
if (*line == '#') {
|
|
|
|
/* If we're this far, the line must be a comment. */
|
1993-03-21 12:45:37 +03:00
|
|
|
goto nextLine;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-03-05 04:58:23 +03:00
|
|
|
if (*line == '\t') {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-03-05 04:58:23 +03:00
|
|
|
* If a line starts with a tab, it can only hope to be
|
|
|
|
* a creation command.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-03-08 01:22:01 +03:00
|
|
|
#ifndef POSIX
|
1993-03-21 12:45:37 +03:00
|
|
|
shellCommand:
|
1994-03-08 01:22:01 +03:00
|
|
|
#endif
|
1998-11-07 02:31:09 +03:00
|
|
|
for (cp = line + 1; isspace ((unsigned char)*cp); cp++) {
|
1993-03-21 12:45:37 +03: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
|
1996-11-06 20:58:58 +03:00
|
|
|
* commands of all targets in the dependency spec
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_ForEach (targets, ParseAddCmd, cp);
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_AtEnd(targCmds, (ClientData) line);
|
1999-09-15 12:43:21 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
Parse_Error (PARSE_FATAL,
|
1996-09-13 08:22:09 +04:00
|
|
|
"Unassociated shell command \"%s\"",
|
1993-03-21 12:45:37 +03:00
|
|
|
cp);
|
|
|
|
}
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
#ifdef SYSVINCLUDE
|
1998-08-06 17:42:22 +04:00
|
|
|
} else if (((strncmp(line, "include", 7) == 0 &&
|
|
|
|
isspace((unsigned char) line[7])) ||
|
|
|
|
((line[0] == 's' || line[0] == '-') &&
|
|
|
|
strncmp(&line[1], "include", 7) == 0 &&
|
|
|
|
isspace((unsigned char) line[8]))) &&
|
|
|
|
strchr(line, ':') == NULL) {
|
1994-03-05 03:34:29 +03:00
|
|
|
/*
|
|
|
|
* It's an S3/S5-style "include".
|
|
|
|
*/
|
1998-08-06 17:42:22 +04:00
|
|
|
ParseTraditionalInclude (line);
|
1994-03-05 03:34:29 +03:00
|
|
|
goto nextLine;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (Parse_IsVar (line)) {
|
|
|
|
ParseFinishLine();
|
|
|
|
Parse_DoVar (line, VAR_GLOBAL);
|
|
|
|
} 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.
|
|
|
|
*/
|
1994-03-08 01:22:01 +03:00
|
|
|
#ifndef POSIX
|
1993-03-21 12:45:37 +03:00
|
|
|
Boolean nonSpace = FALSE;
|
1994-03-08 01:22:01 +03:00
|
|
|
#endif
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
cp = line;
|
1994-10-18 23:36:26 +03:00
|
|
|
if (isspace((unsigned char) line[0])) {
|
|
|
|
while ((*cp != '\0') && isspace((unsigned char) *cp)) {
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (*cp == '\0') {
|
|
|
|
goto nextLine;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef POSIX
|
2002-01-26 23:42:14 +03:00
|
|
|
while (*cp && (ParseIsEscaped(line, cp) ||
|
|
|
|
(*cp != ':') && (*cp != '!'))) {
|
1994-10-18 23:36:26 +03:00
|
|
|
nonSpace = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
cp++;
|
|
|
|
}
|
1994-10-18 23:36:26 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-10-18 23:36:26 +03:00
|
|
|
#ifndef POSIX
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*cp == '\0') {
|
|
|
|
if (inLine) {
|
|
|
|
Parse_Error (PARSE_WARNING,
|
|
|
|
"Shell command needs a leading tab");
|
|
|
|
goto shellCommand;
|
|
|
|
} else if (nonSpace) {
|
|
|
|
Parse_Error (PARSE_FATAL, "Missing operator");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
ParseFinishLine();
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
cp = Var_Subst (NULL, line, VAR_CMD, TRUE);
|
1993-03-21 12:45:37 +03:00
|
|
|
free (line);
|
|
|
|
line = cp;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* Need a non-circular list for the target nodes
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-06-07 02:45:17 +04:00
|
|
|
if (targets)
|
|
|
|
Lst_Destroy(targets, NOFREE);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
targets = Lst_Init (FALSE);
|
|
|
|
inLine = TRUE;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
ParseDoDependency (line);
|
|
|
|
#ifndef POSIX
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nextLine:
|
|
|
|
|
|
|
|
free (line);
|
|
|
|
}
|
|
|
|
/*
|
1996-11-06 20:58:58 +03:00
|
|
|
* Reached EOF, but it may be just EOF of an include file...
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
} while (ParseEOF(1) == CONTINUE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure conditionals are clean
|
|
|
|
*/
|
|
|
|
Cond_End();
|
|
|
|
|
|
|
|
if (fatals) {
|
2001-02-24 00:11:38 +03:00
|
|
|
(void)fprintf(stderr,
|
|
|
|
"%s: Fatal errors encountered -- cannot continue\n",
|
|
|
|
progname);
|
2001-06-02 00:33:37 +04:00
|
|
|
PrintOnError(NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* Parse_Init --
|
|
|
|
* initialize the parsing module
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* none
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* the parseIncPath list is initialized...
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_Init(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
mainNode = NILGNODE;
|
|
|
|
parseIncPath = Lst_Init (FALSE);
|
|
|
|
sysIncPath = Lst_Init (FALSE);
|
2001-10-31 04:15:57 +03:00
|
|
|
defIncPath = Lst_Init (FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
includes = Lst_Init (FALSE);
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
1994-06-07 02:45:17 +04:00
|
|
|
targCmds = Lst_Init (FALSE);
|
1999-09-15 12:43:21 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
void
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_End(void)
|
1994-06-07 02:45:17 +04:00
|
|
|
{
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
2002-06-15 22:24:55 +04:00
|
|
|
Lst_Destroy(targCmds, (void (*)(ClientData))) free;
|
1994-06-07 02:45:17 +04:00
|
|
|
if (targets)
|
|
|
|
Lst_Destroy(targets, NOFREE);
|
2001-10-31 04:15:57 +03:00
|
|
|
Lst_Destroy(defIncPath, Dir_Destroy);
|
1994-06-07 02:45:17 +04:00
|
|
|
Lst_Destroy(sysIncPath, Dir_Destroy);
|
|
|
|
Lst_Destroy(parseIncPath, Dir_Destroy);
|
|
|
|
Lst_Destroy(includes, NOFREE); /* Should be empty now */
|
1999-09-15 12:43:21 +04:00
|
|
|
#endif
|
1994-06-07 02:45:17 +04:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1994-06-07 02:45:17 +04:00
|
|
|
|
1993-03-21 12:45:37 +03: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.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Lst
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_MainName(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1998-03-23 11:52:48 +03:00
|
|
|
Lst mainList; /* result list */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-03-23 11:52:48 +03:00
|
|
|
mainList = Lst_Init (FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (mainNode == NILGNODE) {
|
1996-09-27 06:36:58 +04:00
|
|
|
Punt ("no target to make.");
|
1993-03-21 12:45:37 +03:00
|
|
|
/*NOTREACHED*/
|
|
|
|
} else if (mainNode->type & OP_DOUBLEDEP) {
|
1998-03-23 11:52:48 +03:00
|
|
|
(void) Lst_AtEnd (mainList, (ClientData)mainNode);
|
|
|
|
Lst_Concat(mainList, mainNode->cohorts, LST_CONCNEW);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
else
|
1998-03-23 11:52:48 +03:00
|
|
|
(void) Lst_AtEnd (mainList, (ClientData)mainNode);
|
2002-02-18 02:53:46 +03:00
|
|
|
Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
|
1998-03-23 11:52:48 +03:00
|
|
|
return (mainList);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2001-01-14 08:34:06 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* ParseMark --
|
|
|
|
* Add the filename and lineno to the GNode so that we remember
|
|
|
|
* where it was first defined.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseMark(GNode *gn)
|
2001-01-14 08:34:06 +03:00
|
|
|
{
|
2002-02-22 01:21:34 +03:00
|
|
|
gn->fname = strdup(curFile.fname);
|
|
|
|
gn->lineno = curFile.lineno;
|
2001-01-14 08:34:06 +03:00
|
|
|
}
|