2013-08-11 01:20:03 +04:00
|
|
|
/* $NetBSD: parse.c,v 1.190 2013/08/10 21:20:03 sjg 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.
|
|
|
|
*/
|
|
|
|
|
2004-05-07 04:04:38 +04:00
|
|
|
#ifndef MAKE_NATIVE
|
2013-08-11 01:20:03 +04:00
|
|
|
static char rcsid[] = "$NetBSD: parse.c,v 1.190 2013/08/10 21:20:03 sjg 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
|
2013-08-11 01:20:03 +04:00
|
|
|
__RCSID("$NetBSD: parse.c,v 1.190 2013/08/10 21:20:03 sjg 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
|
2006-12-08 00:07:01 +03:00
|
|
|
* the .include "..." function are kept in the 'parseIncPath' Lst, while
|
|
|
|
* those for the .include <...> are kept in the 'sysIncPath' Lst. The
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mman.h>
|
2010-12-25 20:19:04 +03:00
|
|
|
#include <sys/stat.h>
|
2010-12-25 07:57:07 +03:00
|
|
|
#include <assert.h>
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2006-12-16 11:59:29 +03:00
|
|
|
#include <fcntl.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-03-03 17:53:01 +03:00
|
|
|
#ifndef MAP_FILE
|
|
|
|
#define MAP_FILE 0
|
|
|
|
#endif
|
2010-12-25 07:57:07 +03:00
|
|
|
#ifndef MAP_COPY
|
|
|
|
#define MAP_COPY MAP_PRIVATE
|
|
|
|
#endif
|
|
|
|
|
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"
|
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// types and constants
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2010-12-13 06:32:25 +03:00
|
|
|
* Structure for a file being read ("included file")
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
typedef struct IFile {
|
2013-06-18 23:31:27 +04:00
|
|
|
char *fname; /* name of file */
|
2009-01-11 18:50:06 +03:00
|
|
|
int lineno; /* current line number in file */
|
|
|
|
int first_lineno; /* line number of start of text */
|
|
|
|
int cond_depth; /* 'if' nesting when file opened */
|
2006-12-08 00:07:01 +03:00
|
|
|
char *P_str; /* point to base of string buffer */
|
|
|
|
char *P_ptr; /* point to next char of string buffer */
|
2006-12-16 11:59:29 +03:00
|
|
|
char *P_end; /* point to the end of string buffer */
|
2010-12-25 07:57:07 +03:00
|
|
|
char *(*nextbuf)(void *, size_t *); /* Function to get more data */
|
2009-01-11 18:50:06 +03:00
|
|
|
void *nextbuf_arg; /* Opaque arg for nextbuf() */
|
2010-12-25 07:57:07 +03:00
|
|
|
struct loadedfile *lf; /* loadedfile object, if any */
|
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
|
|
|
|
|
|
|
/*
|
2010-12-13 06:32:25 +03:00
|
|
|
* These values are returned by ParseEOF to tell Parse_File whether to
|
|
|
|
* CONTINUE parsing, i.e. it had only reached the end of an include file,
|
|
|
|
* or if it's DONE.
|
2002-02-22 01:21:34 +03:00
|
|
|
*/
|
2010-12-13 06:32:25 +03:00
|
|
|
#define CONTINUE 1
|
|
|
|
#define DONE 0
|
2002-02-22 01:21:34 +03:00
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
/*
|
|
|
|
* Tokens for target attributes
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
Begin, /* .BEGIN */
|
|
|
|
Default, /* .DEFAULT */
|
|
|
|
End, /* .END */
|
2010-04-08 21:41:29 +04:00
|
|
|
dotError, /* .ERROR */
|
1993-03-21 12:45:37 +03:00
|
|
|
Ignore, /* .IGNORE */
|
|
|
|
Includes, /* .INCLUDES */
|
|
|
|
Interrupt, /* .INTERRUPT */
|
|
|
|
Libs, /* .LIBS */
|
2010-09-13 19:36:57 +04:00
|
|
|
Meta, /* .META */
|
1993-03-21 12:45:37 +03:00
|
|
|
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 */
|
2010-09-13 19:36:57 +04:00
|
|
|
NoMeta, /* .NOMETA */
|
|
|
|
NoMetaCmp, /* .NOMETA_CMP */
|
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 */
|
2013-03-06 02:01:43 +04:00
|
|
|
Stale, /* .STALE */
|
1993-03-21 12:45:37 +03:00
|
|
|
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;
|
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
/*
|
|
|
|
* Other tokens
|
|
|
|
*/
|
|
|
|
#define LPAREN '('
|
|
|
|
#define RPAREN ')'
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// result data
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The main target to create. This is the first target on the first
|
|
|
|
* dependency line in the first makefile.
|
|
|
|
*/
|
|
|
|
static GNode *mainNode;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// eval state
|
|
|
|
|
|
|
|
/* targets we're working on */
|
|
|
|
static Lst targets;
|
|
|
|
|
|
|
|
#ifdef CLEANUP
|
|
|
|
/* command lines for targets */
|
|
|
|
static Lst targCmds;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
1994-03-05 03:34:29 +03:00
|
|
|
static ParseSpecial specType;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
2008-12-13 18:19:29 +03:00
|
|
|
* Predecessor node for handling .ORDER. Initialized to NULL when .ORDER
|
1993-03-21 12:45:37 +03:00
|
|
|
* seen, then set to each successive source on the line.
|
|
|
|
*/
|
|
|
|
static GNode *predecessor;
|
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// parser state
|
|
|
|
|
|
|
|
/* true if currently in a dependency line or its commands */
|
|
|
|
static Boolean inLine;
|
|
|
|
|
|
|
|
/* number of fatal errors */
|
|
|
|
static int fatals = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variables for doing includes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* current file being read */
|
|
|
|
static IFile *curFile;
|
|
|
|
|
|
|
|
/* stack of IFiles generated by .includes */
|
|
|
|
static Lst includes;
|
|
|
|
|
|
|
|
/* include paths (lists of directories) */
|
|
|
|
Lst parseIncPath; /* dirs for "..." includes */
|
|
|
|
Lst sysIncPath; /* dirs for <...> includes */
|
|
|
|
Lst defIncPath; /* default for sysIncPath */
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// parser tables
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
2010-12-13 06:36:39 +03:00
|
|
|
static const 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 },
|
2010-04-08 21:41:29 +04:00
|
|
|
{ ".ERROR", dotError, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".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 },
|
2010-09-13 19:36:57 +04:00
|
|
|
{ ".META", Meta, OP_META },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".MFLAGS", MFlags, 0 },
|
2010-09-13 19:36:57 +04:00
|
|
|
{ ".NOMETA", NoMeta, OP_NOMETA },
|
|
|
|
{ ".NOMETA_CMP", NoMetaCmp, OP_NOMETA_CMP },
|
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 },
|
2013-03-06 02:01:43 +04:00
|
|
|
{ ".STALE", Stale, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ ".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
|
|
|
};
|
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// local functions
|
|
|
|
|
2002-06-15 22:24:55 +04:00
|
|
|
static int ParseIsEscaped(const char *, const char *);
|
2006-12-05 00:34:47 +03:00
|
|
|
static void ParseErrorInternal(const char *, size_t, int, const char *, ...)
|
2012-06-12 23:21:50 +04:00
|
|
|
MAKE_ATTR_PRINTFLIKE(4,5);
|
2007-01-02 00:47:32 +03:00
|
|
|
static void ParseVErrorInternal(FILE *, const char *, size_t, int, const char *, va_list)
|
2012-06-12 23:21:50 +04:00
|
|
|
MAKE_ATTR_PRINTFLIKE(5, 0);
|
2006-11-18 01:07:39 +03:00
|
|
|
static int ParseFindKeyword(const char *);
|
2009-01-24 00:26:30 +03:00
|
|
|
static int ParseLinkSrc(void *, void *);
|
|
|
|
static int ParseDoOp(void *, void *);
|
2006-11-18 01:07:39 +03:00
|
|
|
static void ParseDoSrc(int, const char *);
|
2009-01-24 00:26:30 +03:00
|
|
|
static int ParseFindMain(void *, void *);
|
|
|
|
static int ParseAddDir(void *, void *);
|
|
|
|
static int ParseClearPath(void *, void *);
|
2002-06-15 22:24:55 +04:00
|
|
|
static void ParseDoDependency(char *);
|
2009-01-24 00:26:30 +03:00
|
|
|
static int ParseAddCmd(void *, void *);
|
|
|
|
static void ParseHasCommands(void *);
|
2002-06-15 22:24:55 +04:00
|
|
|
static void ParseDoInclude(char *);
|
2006-12-05 00:34:47 +03:00
|
|
|
static void ParseSetParseFile(const 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
|
2012-03-31 04:12:24 +04:00
|
|
|
#ifdef GMAKEEXPORT
|
|
|
|
static void ParseGmakeExport(char *);
|
|
|
|
#endif
|
2006-12-08 00:07:01 +03:00
|
|
|
static int ParseEOF(void);
|
2002-06-15 22:24:55 +04:00
|
|
|
static char *ParseReadLine(void);
|
|
|
|
static void ParseFinishLine(void);
|
|
|
|
static void ParseMark(GNode *);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
2010-12-25 07:57:07 +03:00
|
|
|
// file loader
|
|
|
|
|
|
|
|
struct loadedfile {
|
|
|
|
const char *path; /* name, for error reports */
|
|
|
|
char *buf; /* contents buffer */
|
|
|
|
size_t len; /* length of contents */
|
|
|
|
size_t maplen; /* length of mmap area, or 0 */
|
|
|
|
Boolean used; /* XXX: have we used the data yet */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor/destructor for loadedfile
|
|
|
|
*/
|
|
|
|
static struct loadedfile *
|
|
|
|
loadedfile_create(const char *path)
|
|
|
|
{
|
|
|
|
struct loadedfile *lf;
|
|
|
|
|
|
|
|
lf = bmake_malloc(sizeof(*lf));
|
|
|
|
lf->path = (path == NULL ? "(stdin)" : path);
|
|
|
|
lf->buf = NULL;
|
|
|
|
lf->len = 0;
|
|
|
|
lf->maplen = 0;
|
|
|
|
lf->used = FALSE;
|
|
|
|
return lf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
loadedfile_destroy(struct loadedfile *lf)
|
|
|
|
{
|
|
|
|
if (lf->buf != NULL) {
|
|
|
|
if (lf->maplen > 0) {
|
|
|
|
munmap(lf->buf, lf->maplen);
|
|
|
|
} else {
|
|
|
|
free(lf->buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(lf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nextbuf() operation for loadedfile, as needed by the weird and twisted
|
|
|
|
* logic below. Once that's cleaned up, we can get rid of lf->used...
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
loadedfile_nextbuf(void *x, size_t *len)
|
|
|
|
{
|
|
|
|
struct loadedfile *lf = x;
|
|
|
|
|
|
|
|
if (lf->used) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
lf->used = TRUE;
|
|
|
|
*len = lf->len;
|
|
|
|
return lf->buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to get the size of a file.
|
|
|
|
*/
|
|
|
|
static ReturnStatus
|
|
|
|
load_getsize(int fd, size_t *ret)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat(fd, &st) < 0) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISREG(st.st_mode)) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* st_size is an off_t, which is 64 bits signed; *ret is
|
|
|
|
* size_t, which might be 32 bits unsigned or 64 bits
|
|
|
|
* unsigned. Rather than being elaborate, just punt on
|
|
|
|
* files that are more than 2^31 bytes. We should never
|
|
|
|
* see a makefile that size in practice...
|
|
|
|
*
|
|
|
|
* While we're at it reject negative sizes too, just in case.
|
|
|
|
*/
|
|
|
|
if (st.st_size < 0 || st.st_size > 0x7fffffff) {
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = (size_t) st.st_size;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in a file.
|
|
|
|
*
|
|
|
|
* Until the path search logic can be moved under here instead of
|
|
|
|
* being in the caller in another source file, we need to have the fd
|
|
|
|
* passed in already open. Bleh.
|
|
|
|
*
|
|
|
|
* If the path is NULL use stdin and (to insure against fd leaks)
|
|
|
|
* assert that the caller passed in -1.
|
|
|
|
*/
|
|
|
|
static struct loadedfile *
|
|
|
|
loadfile(const char *path, int fd)
|
|
|
|
{
|
|
|
|
struct loadedfile *lf;
|
|
|
|
long pagesize;
|
|
|
|
ssize_t result;
|
|
|
|
size_t bufpos;
|
|
|
|
|
|
|
|
lf = loadedfile_create(path);
|
|
|
|
|
|
|
|
if (path == NULL) {
|
|
|
|
assert(fd == -1);
|
|
|
|
fd = STDIN_FILENO;
|
|
|
|
} else {
|
|
|
|
#if 0 /* notyet */
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
...
|
|
|
|
Error("%s: %s", path, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (load_getsize(fd, &lf->len) == SUCCESS) {
|
|
|
|
/* found a size, try mmap */
|
|
|
|
pagesize = sysconf(_SC_PAGESIZE);
|
|
|
|
if (pagesize <= 0) {
|
|
|
|
pagesize = 0x1000;
|
|
|
|
}
|
|
|
|
/* round size up to a page */
|
|
|
|
lf->maplen = pagesize * ((lf->len + pagesize - 1)/pagesize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX hack for dealing with empty files; remove when
|
|
|
|
* we're no longer limited by interfacing to the old
|
|
|
|
* logic elsewhere in this file.
|
|
|
|
*/
|
|
|
|
if (lf->maplen == 0) {
|
|
|
|
lf->maplen = pagesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FUTURE: remove PROT_WRITE when the parser no longer
|
|
|
|
* needs to scribble on the input.
|
|
|
|
*/
|
|
|
|
lf->buf = mmap(NULL, lf->maplen, PROT_READ|PROT_WRITE,
|
|
|
|
MAP_FILE|MAP_COPY, fd, 0);
|
|
|
|
if (lf->buf != MAP_FAILED) {
|
|
|
|
/* succeeded */
|
2011-05-18 01:56:51 +04:00
|
|
|
if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') {
|
|
|
|
char *b = malloc(lf->len + 1);
|
|
|
|
b[lf->len] = '\n';
|
|
|
|
memcpy(b, lf->buf, lf->len++);
|
|
|
|
munmap(lf->buf, lf->maplen);
|
|
|
|
lf->maplen = 0;
|
|
|
|
lf->buf = b;
|
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cannot mmap; load the traditional way */
|
|
|
|
|
|
|
|
lf->maplen = 0;
|
|
|
|
lf->len = 1024;
|
|
|
|
lf->buf = bmake_malloc(lf->len);
|
|
|
|
|
|
|
|
bufpos = 0;
|
|
|
|
while (1) {
|
|
|
|
assert(bufpos <= lf->len);
|
|
|
|
if (bufpos == lf->len) {
|
|
|
|
lf->len *= 2;
|
|
|
|
lf->buf = bmake_realloc(lf->buf, lf->len);
|
|
|
|
}
|
|
|
|
result = read(fd, lf->buf + bufpos, lf->len - bufpos);
|
|
|
|
if (result < 0) {
|
|
|
|
Error("%s: read error: %s", path, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (result == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bufpos += result;
|
|
|
|
}
|
|
|
|
assert(bufpos <= lf->len);
|
2010-12-26 00:39:11 +03:00
|
|
|
lf->len = bufpos;
|
2010-12-25 07:57:07 +03:00
|
|
|
|
|
|
|
/* truncate malloc region to actual length (maybe not useful) */
|
2010-12-25 23:46:18 +03:00
|
|
|
if (lf->len > 0) {
|
|
|
|
lf->buf = bmake_realloc(lf->buf, lf->len);
|
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (path != NULL) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return lf;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// old code
|
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
|
2006-11-18 01:07:39 +03:00
|
|
|
ParseFindKeyword(const 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);
|
2005-07-26 02:55:58 +04:00
|
|
|
diff = strcmp(str, parseKeywords[cur].name);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
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
|
2007-01-02 00:47:32 +03:00
|
|
|
ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type,
|
2006-12-05 00:34:47 +03:00
|
|
|
const char *fmt, va_list ap)
|
1998-08-06 17:42:22 +04:00
|
|
|
{
|
2001-01-10 18:54:00 +03:00
|
|
|
static Boolean fatal_warning_error_printed = FALSE;
|
|
|
|
|
2008-10-29 18:37:08 +03:00
|
|
|
(void)fprintf(f, "%s: ", progname);
|
|
|
|
|
|
|
|
if (cfname != NULL) {
|
|
|
|
(void)fprintf(f, "\"");
|
|
|
|
if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
|
|
|
|
char *cp;
|
|
|
|
const char *dir;
|
|
|
|
|
|
|
|
/*
|
2010-12-13 08:01:56 +03:00
|
|
|
* Nothing is more annoying than not knowing
|
2008-10-29 18:37:08 +03:00
|
|
|
* which Makefile is the culprit.
|
|
|
|
*/
|
|
|
|
dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
|
|
|
|
if (dir == NULL || *dir == '\0' ||
|
|
|
|
(*dir == '.' && dir[1] == '\0'))
|
|
|
|
dir = Var_Value(".CURDIR", VAR_GLOBAL, &cp);
|
|
|
|
if (dir == NULL)
|
|
|
|
dir = ".";
|
|
|
|
|
|
|
|
(void)fprintf(f, "%s/%s", dir, cfname);
|
|
|
|
} else
|
|
|
|
(void)fprintf(f, "%s", cfname);
|
|
|
|
|
|
|
|
(void)fprintf(f, "\" line %d: ", (int)clineno);
|
|
|
|
}
|
1998-08-06 17:42:22 +04:00
|
|
|
if (type == PARSE_WARNING)
|
2007-01-02 00:47:32 +03:00
|
|
|
(void)fprintf(f, "warning: ");
|
|
|
|
(void)vfprintf(f, fmt, ap);
|
|
|
|
(void)fprintf(f, "\n");
|
|
|
|
(void)fflush(f);
|
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
|
2006-12-05 00:34:47 +03:00
|
|
|
ParseErrorInternal(const 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);
|
2010-04-30 03:12:21 +04:00
|
|
|
(void)fflush(stdout);
|
2007-01-02 00:47:32 +03:00
|
|
|
ParseVErrorInternal(stderr, cfname, clineno, type, fmt, ap);
|
1998-08-06 17:42:22 +04:00
|
|
|
va_end(ap);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2007-01-25 00:43:01 +03:00
|
|
|
if (debug_file != stderr && debug_file != stdout) {
|
2007-01-02 00:47:32 +03:00
|
|
|
va_start(ap, fmt);
|
2007-01-25 00:43:01 +03:00
|
|
|
ParseVErrorInternal(debug_file, cfname, clineno, type, fmt, ap);
|
2007-01-02 00:47:32 +03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
1998-08-06 17:42:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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;
|
2009-01-16 23:50:24 +03:00
|
|
|
const char *fname;
|
|
|
|
size_t lineno;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-12-13 18:19:29 +03:00
|
|
|
if (curFile == NULL) {
|
2009-01-16 23:50:24 +03:00
|
|
|
fname = NULL;
|
|
|
|
lineno = 0;
|
|
|
|
} else {
|
|
|
|
fname = curFile->fname;
|
|
|
|
lineno = curFile->lineno;
|
2008-10-29 18:37:08 +03:00
|
|
|
}
|
2009-01-16 23:50:24 +03:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2010-04-30 03:12:21 +04:00
|
|
|
(void)fflush(stdout);
|
2009-01-16 23:50:24 +03:00
|
|
|
ParseVErrorInternal(stderr, fname, lineno, type, fmt, ap);
|
1993-03-21 12:45:37 +03:00
|
|
|
va_end(ap);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2007-01-25 00:43:01 +03:00
|
|
|
if (debug_file != stderr && debug_file != stdout) {
|
2007-01-02 00:47:32 +03:00
|
|
|
va_start(ap, fmt);
|
2009-01-16 23:50:24 +03:00
|
|
|
ParseVErrorInternal(debug_file, fname, lineno, type, fmt, ap);
|
2007-01-02 00:47:32 +03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2010-04-07 04:11:27 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ParseMessage
|
|
|
|
* Parse a .info .warning or .error directive
|
|
|
|
*
|
|
|
|
* The input is the line minus the ".". We substitute
|
|
|
|
* variables, print the message and exit(1) (for .error) or just print
|
|
|
|
* a warning if the directive is malformed.
|
|
|
|
*/
|
2010-05-25 01:04:49 +04:00
|
|
|
static Boolean
|
2010-04-07 04:11:27 +04:00
|
|
|
ParseMessage(char *line)
|
|
|
|
{
|
|
|
|
int mtype;
|
2010-05-25 01:04:49 +04:00
|
|
|
|
2010-04-07 04:11:27 +04:00
|
|
|
switch(*line) {
|
|
|
|
case 'i':
|
|
|
|
mtype = 0;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
mtype = PARSE_WARNING;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
mtype = PARSE_FATAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Parse_Error(PARSE_WARNING, "invalid syntax: \".%s\"", line);
|
2010-05-25 01:04:49 +04:00
|
|
|
return FALSE;
|
2010-04-07 04:11:27 +04:00
|
|
|
}
|
|
|
|
|
2010-05-25 01:04:49 +04:00
|
|
|
while (isalpha((u_char)*line))
|
2010-04-07 04:11:27 +04:00
|
|
|
line++;
|
2010-05-25 01:04:49 +04:00
|
|
|
if (!isspace((u_char)*line))
|
|
|
|
return FALSE; /* not for us */
|
2010-04-07 04:11:27 +04:00
|
|
|
while (isspace((u_char)*line))
|
|
|
|
line++;
|
|
|
|
|
|
|
|
line = Var_Subst(NULL, line, VAR_CMD, 0);
|
|
|
|
Parse_Error(mtype, "%s", line);
|
|
|
|
free(line);
|
|
|
|
|
|
|
|
if (mtype == PARSE_FATAL) {
|
|
|
|
/* Terminate immediately. */
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-05-25 01:04:49 +04:00
|
|
|
return TRUE;
|
2010-04-07 04:11:27 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* 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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseLinkSrc(void *pgnp, void *cgnp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +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))
|
2005-07-26 02:55:58 +04:00
|
|
|
pgn = (GNode *)Lst_Datum(Lst_Last(pgn->cohorts));
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(pgn->children, cgn);
|
2000-06-11 11:39:52 +04:00
|
|
|
if (specType == Not)
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(cgn->parents, pgn);
|
2000-06-11 11:39:52 +04:00
|
|
|
pgn->unmade += 1;
|
2006-02-11 23:59:49 +03:00
|
|
|
if (DEBUG(PARSE)) {
|
2006-10-15 12:38:21 +04:00
|
|
|
fprintf(debug_file, "# ParseLinkSrc: added child %s - %s\n", pgn->name, cgn->name);
|
2006-02-11 23:59:49 +03:00
|
|
|
Targ_PrintNode(pgn, 0);
|
|
|
|
Targ_PrintNode(cgn, 0);
|
|
|
|
}
|
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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseDoOp(void *gnp, void *opp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +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))
|
|
|
|
{
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((op == OP_DOUBLEDEP) && ((gn->type & OP_OPMASK) == OP_DOUBLEDEP)) {
|
|
|
|
/*
|
|
|
|
* If the node was the object of a :: operator, we need to create a
|
|
|
|
* new instance of it for the children and commands on this dependency
|
|
|
|
* line. The new instance is placed on the 'cohorts' list of the
|
|
|
|
* initial one (note the initial one is not on its own cohorts list)
|
|
|
|
* and the new instance is linked to all parents of the initial
|
|
|
|
* instance.
|
|
|
|
*/
|
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
|
|
|
|
2006-11-18 01:07:39 +03:00
|
|
|
cohort = Targ_FindNode(gn->name, TARG_NOHASH);
|
2013-03-05 06:04:10 +04:00
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(cohort);
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(gn->cohorts, cohort);
|
2002-03-20 21:10:30 +03:00
|
|
|
cohort->centurion = gn;
|
|
|
|
gn->unmade_cohorts += 1;
|
2006-11-18 01:07:39 +03:00
|
|
|
snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
|
|
|
|
gn->unmade_cohorts);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* 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
|
|
|
|
*
|
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
|
2006-11-18 01:07:39 +03:00
|
|
|
ParseDoSrc(int tOp, const char *src)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1995-12-16 08:03:09 +03:00
|
|
|
GNode *gn = NULL;
|
2006-11-18 01:07:39 +03:00
|
|
|
static int wait_number = 0;
|
|
|
|
char wait_src[16];
|
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) {
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(targets, ParseDoOp, &op);
|
1995-12-16 08:03:09 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parseKeywords[keywd].spec == Wait) {
|
2006-11-18 01:07:39 +03:00
|
|
|
/*
|
|
|
|
* We add a .WAIT node in the dependency list.
|
|
|
|
* After any dynamic dependencies (and filename globbing)
|
|
|
|
* have happened, it is given a dependency on the each
|
|
|
|
* previous child back to and previous .WAIT node.
|
|
|
|
* The next child won't be scheduled until the .WAIT node
|
|
|
|
* is built.
|
|
|
|
* We give each .WAIT node a unique name (mainly for diag).
|
|
|
|
*/
|
|
|
|
snprintf(wait_src, sizeof wait_src, ".WAIT_%u", ++wait_number);
|
|
|
|
gn = Targ_FindNode(wait_src, TARG_NOHASH);
|
2013-03-05 06:04:10 +04:00
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
2006-11-18 01:07:39 +03:00
|
|
|
gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
|
|
|
|
Lst_ForEach(targets, ParseLinkSrc, gn);
|
1995-12-16 08:03:09 +03:00
|
|
|
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...
|
|
|
|
*/
|
2008-10-07 02:09:21 +04:00
|
|
|
(void)Lst_AtEnd(create, bmake_strdup(src));
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2006-10-16 01:17:27 +04:00
|
|
|
* Add the name to the .TARGETS variable as well, so the user can
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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);
|
2013-03-05 06:04:10 +04:00
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
2008-12-13 18:19:29 +03:00
|
|
|
if (predecessor != NULL) {
|
2006-11-18 01:07:39 +03:00
|
|
|
(void)Lst_AtEnd(predecessor->order_succ, gn);
|
|
|
|
(void)Lst_AtEnd(gn->order_pred, predecessor);
|
2006-02-11 23:59:49 +03:00
|
|
|
if (DEBUG(PARSE)) {
|
2006-10-15 12:38:21 +04:00
|
|
|
fprintf(debug_file, "# ParseDoSrc: added Order dependency %s - %s\n",
|
2006-02-11 23:59:49 +03:00
|
|
|
predecessor->name, gn->name);
|
|
|
|
Targ_PrintNode(predecessor, 0);
|
|
|
|
Targ_PrintNode(gn, 0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-10-16 01:17:27 +04:00
|
|
|
|
|
|
|
/* Find/create the 'src' node and attach to all targets */
|
2005-02-16 18:11:52 +03:00
|
|
|
gn = Targ_FindNode(src, TARG_CREATE);
|
2013-03-05 06:04:10 +04:00
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (tOp) {
|
|
|
|
gn->type |= tOp;
|
|
|
|
} else {
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(targets, ParseLinkSrc, gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
break;
|
|
|
|
}
|
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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseFindMain(void *gnp, void *dummy)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseAddDir(void *path, void *name)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseClearPath(void *path, void *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 */
|
2005-05-01 05:25:36 +04:00
|
|
|
GNode *gn = NULL; /* a general purpose temporary node */
|
1994-06-07 02:45:17 +04:00
|
|
|
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 */
|
2002-01-26 23:42:14 +03:00
|
|
|
char *lstart = line;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-11-18 01:07:39 +03:00
|
|
|
if (DEBUG(PARSE))
|
|
|
|
fprintf(debug_file, "ParseDoDependency(%s)\n", line);
|
1993-03-21 12:45:37 +03:00
|
|
|
tOp = 0;
|
|
|
|
|
|
|
|
specType = Not;
|
2011-08-31 20:24:54 +04:00
|
|
|
paths = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
curTargs = Lst_Init(FALSE);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
2006-12-03 23:40:44 +03:00
|
|
|
for (cp = line; *cp && (ParseIsEscaped(lstart, cp) ||
|
|
|
|
!(isspace((unsigned char)*cp) ||
|
|
|
|
*cp == '!' || *cp == ':' || *cp == LPAREN));
|
|
|
|
cp++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*cp == '$') {
|
|
|
|
/*
|
|
|
|
* Must be a dynamic source (would have been expanded
|
|
|
|
* otherwise), so call the Var module to parse the puppy
|
|
|
|
* so we can safely advance beyond it...There should be
|
|
|
|
* no errors in this, as they would have been discovered
|
|
|
|
* in the initial Var_Subst and we wouldn't be here.
|
|
|
|
*/
|
2008-02-16 00:29:50 +03:00
|
|
|
int length;
|
2006-04-01 01:58:08 +04:00
|
|
|
void *freeIt;
|
2008-02-16 00:29:50 +03:00
|
|
|
char *result;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-02-16 00:29:50 +03:00
|
|
|
result = Var_Parse(cp, VAR_CMD, TRUE, &length, &freeIt);
|
2006-04-01 01:58:08 +04:00
|
|
|
if (freeIt)
|
|
|
|
free(freeIt);
|
1993-03-21 12:45:37 +03:00
|
|
|
cp += length-1;
|
|
|
|
}
|
|
|
|
}
|
2006-12-03 23:40:44 +03:00
|
|
|
|
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.
|
|
|
|
*/
|
2005-02-16 18:11:52 +03:00
|
|
|
if (Arch_ParseArchive(&line, targets, VAR_CMD) != SUCCESS) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
1993-03-21 12:45:37 +03:00
|
|
|
"Error in archive specification: \"%s\"", line);
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
} 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))
|
2005-02-16 18:11:52 +03: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
|
2009-11-06 23:20:56 +03:00
|
|
|
Parse_Error(PARSE_FATAL, lstart[0] == '.' ? "Unknown directive"
|
|
|
|
: "Need an operator");
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
*cp = '\0';
|
2006-10-16 01:17:27 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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");
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
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
|
2013-03-06 02:01:43 +04:00
|
|
|
* .STALE
|
1993-03-21 12:45:37 +03:00
|
|
|
* .BEGIN
|
|
|
|
* .END
|
2010-04-08 21:41:29 +04:00
|
|
|
* .ERROR
|
1993-03-21 12:45:37 +03:00
|
|
|
* .INTERRUPT Are not to be considered the
|
|
|
|
* main target.
|
|
|
|
* .NOTPARALLEL Make only one target at a time.
|
|
|
|
* .SINGLESHELL Create a shell for each command.
|
2008-12-13 18:19:29 +03:00
|
|
|
* .ORDER Must set initial predecessor to NULL
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
switch (specType) {
|
2013-03-06 02:01:43 +04:00
|
|
|
case ExPath:
|
|
|
|
if (paths == NULL) {
|
|
|
|
paths = Lst_Init(FALSE);
|
|
|
|
}
|
|
|
|
(void)Lst_AtEnd(paths, dirSearchPath);
|
|
|
|
break;
|
|
|
|
case Main:
|
|
|
|
if (!Lst_IsEmpty(create)) {
|
|
|
|
specType = Not;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case Stale:
|
|
|
|
case dotError:
|
|
|
|
case Interrupt:
|
|
|
|
gn = Targ_FindNode(line, TARG_CREATE);
|
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
|
|
|
gn->type |= OP_NOTMAIN|OP_SPECIAL;
|
|
|
|
(void)Lst_AtEnd(targets, gn);
|
|
|
|
break;
|
|
|
|
case Default:
|
|
|
|
gn = Targ_NewGN(".DEFAULT");
|
|
|
|
gn->type |= (OP_NOTMAIN|OP_TRANSFORM);
|
|
|
|
(void)Lst_AtEnd(targets, gn);
|
|
|
|
DEFAULT = gn;
|
|
|
|
break;
|
|
|
|
case NotParallel:
|
|
|
|
maxJobs = 1;
|
|
|
|
break;
|
|
|
|
case SingleShell:
|
|
|
|
compatMake = TRUE;
|
|
|
|
break;
|
|
|
|
case Order:
|
|
|
|
predecessor = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2005-07-26 02:55:58 +04:00
|
|
|
} else if (strncmp(line, ".PATH", 5) == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* .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;
|
2005-02-16 18:11:52 +03:00
|
|
|
path = Suff_GetPath(&line[5]);
|
2008-12-13 18:19:29 +03:00
|
|
|
if (path == NULL) {
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1993-03-21 12:45:37 +03:00
|
|
|
"Suffix '%s' not defined (yet)",
|
|
|
|
&line[5]);
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2011-08-31 20:24:54 +04:00
|
|
|
if (paths == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
paths = Lst_Init(FALSE);
|
|
|
|
}
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(paths, path);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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.
|
|
|
|
*/
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(curTargs, line);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
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)) {
|
2005-02-16 18:11:52 +03:00
|
|
|
gn = Targ_FindNode(targName, TARG_CREATE);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2005-02-16 18:11:52 +03:00
|
|
|
gn = Suff_AddTransform(targName);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2013-03-05 06:04:10 +04:00
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(targets, gn);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
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) {
|
2006-08-26 22:17:41 +04:00
|
|
|
Boolean warning = 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')) {
|
2006-08-26 22:17:41 +04:00
|
|
|
warning = TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
2006-08-26 22:17:41 +04:00
|
|
|
if (warning) {
|
1993-03-21 12:45:37 +03:00
|
|
|
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...
|
|
|
|
*/
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(curTargs, NULL);
|
2006-04-01 00:30:46 +04:00
|
|
|
curTargs = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (!Lst_IsEmpty(targets)) {
|
|
|
|
switch(specType) {
|
|
|
|
default:
|
|
|
|
Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored");
|
|
|
|
break;
|
|
|
|
case Default:
|
2013-03-06 02:01:43 +04:00
|
|
|
case Stale:
|
1993-03-21 12:45:37 +03:00
|
|
|
case Begin:
|
|
|
|
case End:
|
2010-04-08 21:41:29 +04:00
|
|
|
case dotError:
|
1993-03-21 12:45:37 +03:00
|
|
|
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 {
|
2009-11-06 23:20:56 +03:00
|
|
|
Parse_Error(PARSE_FATAL, lstart[0] == '.' ? "Unknown directive"
|
|
|
|
: "Missing dependency operator");
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cp++; /* Advance beyond operator */
|
|
|
|
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(targets, ParseDoOp, &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:
|
2005-02-16 18:11:52 +03:00
|
|
|
Suff_ClearSuffixes();
|
1993-03-21 12:45:37 +03:00
|
|
|
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:
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(paths, ParseClearPath, 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
|
|
|
|
*/
|
2005-02-16 18:11:52 +03:00
|
|
|
Main_ParseArgLine(line);
|
1993-03-21 12:45:37 +03:00
|
|
|
*line = '\0';
|
1994-03-05 03:34:29 +03:00
|
|
|
} else if (specType == ExShell) {
|
2005-02-16 18:11:52 +03:00
|
|
|
if (Job_ParseShell(line) != SUCCESS) {
|
|
|
|
Parse_Error(PARSE_FATAL, "improper shell specification");
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
*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:
|
2005-02-16 18:11:52 +03:00
|
|
|
Suff_AddSuffix(line, &mainNode);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
case ExPath:
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(paths, ParseAddDir, line);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case Includes:
|
2005-02-16 18:11:52 +03:00
|
|
|
Suff_AddInclude(line);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case Libs:
|
2005-02-16 18:11:52 +03:00
|
|
|
Suff_AddLib(line);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case Null:
|
2005-02-16 18:11:52 +03:00
|
|
|
Suff_SetNull(line);
|
1993-03-21 12:45:37 +03:00
|
|
|
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) {
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(paths, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2002-11-26 09:12:59 +03:00
|
|
|
if (specType == ExPath)
|
|
|
|
Dir_SetPATH();
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
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.
|
|
|
|
*/
|
2006-10-16 01:17:27 +04:00
|
|
|
for (; *cp && !isspace ((unsigned char)*cp); 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-26 23:42:14 +03:00
|
|
|
if (*cp == LPAREN) {
|
2005-02-16 18:11:52 +03:00
|
|
|
sources = Lst_Init(FALSE);
|
|
|
|
if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
1993-03-21 12:45:37 +03:00
|
|
|
"Error in source archive spec \"%s\"", line);
|
2006-04-01 00:30:46 +04:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!Lst_IsEmpty (sources)) {
|
2005-07-26 02:55:58 +04:00
|
|
|
gn = (GNode *)Lst_DeQueue(sources);
|
2006-11-18 01:07:39 +03:00
|
|
|
ParseDoSrc(tOp, gn->name);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(sources, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
cp = line;
|
|
|
|
} else {
|
|
|
|
if (*cp) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp += 1;
|
|
|
|
}
|
|
|
|
|
2006-11-18 01:07:39 +03:00
|
|
|
ParseDoSrc(tOp, line);
|
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
|
|
|
|
2008-12-13 18:19:29 +03:00
|
|
|
if (mainNode == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* If we have yet to decide on a main target to make, in the
|
|
|
|
* absence of any user input, we want the first target on
|
|
|
|
* the first dependency line that is actually a real target
|
|
|
|
* (i.e. isn't a .USE or .EXEC rule) to be made.
|
|
|
|
*/
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(targets, ParseFindMain, NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2006-04-01 00:30:46 +04:00
|
|
|
out:
|
|
|
|
if (curTargs)
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(curTargs, NULL);
|
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 */
|
2009-01-09 00:12:09 +03:00
|
|
|
char ch;
|
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
|
|
|
|
2009-01-09 00:12:09 +03:00
|
|
|
/* Scan for one of the assignment operators outside a variable expansion */
|
|
|
|
while ((ch = *line++) != 0) {
|
|
|
|
if (ch == '(' || ch == '{') {
|
1995-09-10 07:58:16 +04:00
|
|
|
level++;
|
2009-01-09 00:12:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == ')' || ch == '}') {
|
1995-09-10 07:58:16 +04:00
|
|
|
level--;
|
2009-01-09 00:12:09 +03:00
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2009-01-09 00:12:09 +03:00
|
|
|
if (level != 0)
|
|
|
|
continue;
|
|
|
|
while (ch == ' ' || ch == '\t') {
|
|
|
|
ch = *line++;
|
|
|
|
wasSpace = TRUE;
|
|
|
|
}
|
|
|
|
if (ch == '=')
|
|
|
|
return TRUE;
|
|
|
|
if (*line == '=' && ISEQOPERATOR(ch))
|
|
|
|
return TRUE;
|
|
|
|
if (wasSpace)
|
|
|
|
return FALSE;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-01-09 00:12:09 +03:00
|
|
|
return FALSE;
|
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 */
|
2009-01-04 23:17:36 +03:00
|
|
|
int depth;
|
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
|
2009-01-04 23:17:36 +03:00
|
|
|
* XXX Rather than counting () and {} we should look for $ and
|
|
|
|
* then expand the variable.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2009-01-04 23:17:36 +03:00
|
|
|
for (depth = 0, cp = line + 1; depth != 0 || *cp != '='; cp++) {
|
|
|
|
if (*cp == '(' || *cp == '{') {
|
|
|
|
depth++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp == ')' || *cp == '}') {
|
|
|
|
depth--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (depth == 0 && 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) {
|
2005-02-16 18:11:52 +03:00
|
|
|
Var_Append(line, cp, ctxt);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (type == VAR_SUBST) {
|
|
|
|
/*
|
|
|
|
* Allow variables in the old value to be undefined, but leave their
|
|
|
|
* invocation alone -- this is done by forcing oldVars to be false.
|
|
|
|
* XXX: This can cause recursive variables, but that's not hard to do,
|
|
|
|
* and this allows someone to do something like
|
|
|
|
*
|
|
|
|
* CFLAGS = $(.INCLUDES)
|
|
|
|
* CFLAGS := -I.. $(CFLAGS)
|
|
|
|
*
|
|
|
|
* And not get an error.
|
|
|
|
*/
|
|
|
|
Boolean oldOldVars = oldVars;
|
|
|
|
|
|
|
|
oldVars = FALSE;
|
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;
|
2006-08-26 22:17:41 +04:00
|
|
|
const char *error;
|
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
|
|
|
}
|
|
|
|
|
2006-08-26 22:17:41 +04:00
|
|
|
res = Cmd_Exec(cp, &error);
|
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
|
|
|
|
2006-08-26 22:17:41 +04:00
|
|
|
if (error)
|
|
|
|
Parse_Error(PARSE_WARNING, error, 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();
|
2007-10-05 19:27:45 +04:00
|
|
|
} else if (strcmp(line, MAKE_JOB_PREFIX) == 0) {
|
2007-10-02 02:14:09 +04:00
|
|
|
Job_SetPrefix();
|
2007-10-05 19:27:45 +04:00
|
|
|
} else if (strcmp(line, MAKE_EXPORTED) == 0) {
|
|
|
|
Var_Export(cp, 0);
|
2002-11-26 09:12:59 +03:00
|
|
|
}
|
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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseAddCmd(void *gnp, void *cmd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +04:00
|
|
|
GNode *gn = (GNode *)gnp;
|
2006-11-18 01:07:39 +03:00
|
|
|
|
|
|
|
/* Add to last (ie current) cohort for :: targets */
|
1999-09-16 04:54:14 +04:00
|
|
|
if ((gn->type & OP_DOUBLEDEP) && !Lst_IsEmpty (gn->cohorts))
|
2005-07-26 02:55:58 +04:00
|
|
|
gn = (GNode *)Lst_Datum(Lst_Last(gn->cohorts));
|
2006-11-18 01:07:39 +03:00
|
|
|
|
|
|
|
/* if target already supplied, ignore commands */
|
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);
|
2005-02-16 18:11:52 +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
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_WARNING,
|
2001-01-14 23:54:16 +03:00
|
|
|
"duplicate script for target \"%s\" ignored",
|
|
|
|
gn->name);
|
2005-02-16 18:11:52 +03:00
|
|
|
ParseErrorInternal(gn->fname, gn->lineno, PARSE_WARNING,
|
2001-01-14 23:54:16 +03:00
|
|
|
"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
|
2009-01-24 00:26:30 +03:00
|
|
|
ParseHasCommands(void *gnp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-08-08 20:42:54 +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
|
|
|
{
|
2005-07-26 02:55:58 +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
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
2006-12-08 00:07:01 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
static void
|
2006-12-08 00:07:01 +03:00
|
|
|
Parse_include_file(char *file, Boolean isSystem, int silent)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2010-12-25 07:57:07 +03:00
|
|
|
struct loadedfile *lf;
|
1993-03-21 12:45:37 +03:00
|
|
|
char *fullname; /* full pathname of file */
|
2007-10-13 15:08:05 +04:00
|
|
|
char *newName;
|
|
|
|
char *prefEnd, *incdir;
|
2006-12-16 11:59:29 +03:00
|
|
|
int fd;
|
2007-10-13 15:08:05 +04:00
|
|
|
int i;
|
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.
|
|
|
|
*/
|
2008-10-07 02:09:21 +04:00
|
|
|
fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
|
2002-01-24 04:39:03 +03:00
|
|
|
|
2007-10-13 15:08:05 +04:00
|
|
|
if (fullname == NULL && !isSystem) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-10-07 02:09:21 +04:00
|
|
|
incdir = bmake_strdup(curFile->fname);
|
2007-10-13 15:08:05 +04:00
|
|
|
prefEnd = strrchr(incdir, '/');
|
2005-08-08 20:42:54 +04:00
|
|
|
if (prefEnd != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*prefEnd = '\0';
|
2007-10-13 15:08:05 +04:00
|
|
|
/* Now do lexical processing of leading "../" on the filename */
|
|
|
|
for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) {
|
|
|
|
prefEnd = strrchr(incdir + 1, '/');
|
|
|
|
if (prefEnd == NULL || strcmp(prefEnd, "/..") == 0)
|
|
|
|
break;
|
|
|
|
*prefEnd = '\0';
|
|
|
|
}
|
|
|
|
newName = str_concat(incdir, file + i, STR_ADDSLASH);
|
2005-02-16 18:11:52 +03:00
|
|
|
fullname = Dir_FindFile(newName, parseIncPath);
|
2007-10-13 15:08:05 +04:00
|
|
|
if (fullname == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
fullname = Dir_FindFile(newName, dirSearchPath);
|
2005-07-26 02:55:58 +04:00
|
|
|
free(newName);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2007-10-13 15:08:05 +04:00
|
|
|
free(incdir);
|
|
|
|
|
2007-10-22 19:36:13 +04:00
|
|
|
if (fullname == NULL) {
|
2002-01-24 04:39:03 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
2007-10-22 19:36:13 +04:00
|
|
|
* If we have a suffix specific path we should use that.
|
2002-01-24 04:39:03 +03:00
|
|
|
*/
|
2007-10-22 19:36:13 +04:00
|
|
|
char *suff;
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst suffPath = NULL;
|
2007-10-22 19:36:13 +04:00
|
|
|
|
2008-02-16 00:29:50 +03:00
|
|
|
if ((suff = strrchr(file, '.'))) {
|
2007-10-22 19:36:13 +04:00
|
|
|
suffPath = Suff_GetPath(suff);
|
2008-12-13 18:19:29 +03:00
|
|
|
if (suffPath != NULL) {
|
2007-10-22 19:36:13 +04:00
|
|
|
fullname = Dir_FindFile(file, suffPath);
|
|
|
|
}
|
|
|
|
}
|
2005-08-08 20:42:54 +04:00
|
|
|
if (fullname == NULL) {
|
2007-10-22 19:36:13 +04:00
|
|
|
fullname = Dir_FindFile(file, parseIncPath);
|
|
|
|
if (fullname == NULL) {
|
|
|
|
fullname = Dir_FindFile(file, dirSearchPath);
|
|
|
|
}
|
2002-01-24 04:39:03 +03:00
|
|
|
}
|
2007-10-22 19:36:13 +04:00
|
|
|
}
|
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 */
|
2005-08-08 20:42:54 +04:00
|
|
|
if (fullname == NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2002-01-24 04:39:03 +03:00
|
|
|
* Look for it on the system path
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2006-12-08 00:07:01 +03:00
|
|
|
fullname = Dir_FindFile(file,
|
|
|
|
Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2005-08-08 20:42:54 +04:00
|
|
|
if (fullname == NULL) {
|
1998-08-06 17:42:22 +04:00
|
|
|
if (!silent)
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Could not find %s", file);
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-16 11:59:29 +03:00
|
|
|
/* Actually open the file... */
|
|
|
|
fd = open(fullname, O_RDONLY);
|
|
|
|
if (fd == -1) {
|
1998-08-06 17:42:22 +04:00
|
|
|
if (!silent)
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
|
2007-10-13 15:08:05 +04:00
|
|
|
free(fullname);
|
2006-12-16 11:59:29 +03:00
|
|
|
return;
|
2006-12-08 00:07:01 +03:00
|
|
|
}
|
2006-12-16 11:59:29 +03:00
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
/* load it */
|
|
|
|
lf = loadfile(fullname, fd);
|
|
|
|
|
2006-12-16 11:59:29 +03:00
|
|
|
/* Start reading from this file next */
|
2010-12-25 07:57:07 +03:00
|
|
|
Parse_SetInput(fullname, 0, -1, loadedfile_nextbuf, lf);
|
|
|
|
curFile->lf = lf;
|
2006-12-08 00:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ParseDoInclude(char *line)
|
|
|
|
{
|
|
|
|
char endc; /* the character which ends the file spec */
|
|
|
|
char *cp; /* current position in file spec */
|
|
|
|
int silent = (*line != 'i') ? 1 : 0;
|
|
|
|
char *file = &line[7 + silent];
|
|
|
|
|
|
|
|
/* 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 == '<') {
|
|
|
|
endc = '>';
|
|
|
|
} else {
|
|
|
|
endc = '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip to matching delimiter */
|
|
|
|
for (cp = ++file; *cp && *cp != endc; cp++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*cp != endc) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Unclosed %cinclude filename. '%c' expected",
|
|
|
|
'.', endc);
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-12-08 00:07:01 +03:00
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
|
|
|
file = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
|
|
|
|
|
|
|
Parse_include_file(file, endc == '>', silent);
|
|
|
|
free(file);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
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
|
2006-12-05 00:34:47 +03:00
|
|
|
ParseSetParseFile(const char *filename)
|
1999-08-10 01:06:28 +04:00
|
|
|
{
|
2011-11-06 23:46:56 +04:00
|
|
|
char *slash, *dirname;
|
|
|
|
const char *pd, *pf;
|
2008-02-16 00:29:50 +03:00
|
|
|
int len;
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2002-01-27 04:50:54 +03:00
|
|
|
slash = strrchr(filename, '/');
|
2006-12-05 00:34:47 +03:00
|
|
|
if (slash == NULL) {
|
2011-11-06 23:46:56 +04:00
|
|
|
Var_Set(".PARSEDIR", pd = curdir, VAR_GLOBAL, 0);
|
|
|
|
Var_Set(".PARSEFILE", pf = filename, VAR_GLOBAL, 0);
|
|
|
|
dirname= NULL;
|
1999-08-10 01:06:28 +04:00
|
|
|
} else {
|
2006-12-05 00:34:47 +03:00
|
|
|
len = slash - filename;
|
2008-10-07 02:09:21 +04:00
|
|
|
dirname = bmake_malloc(len + 1);
|
2008-02-16 00:29:50 +03:00
|
|
|
memcpy(dirname, filename, len);
|
2011-11-06 23:46:56 +04:00
|
|
|
dirname[len] = '\0';
|
|
|
|
Var_Set(".PARSEDIR", pd = dirname, VAR_GLOBAL, 0);
|
|
|
|
Var_Set(".PARSEFILE", pf = slash + 1, VAR_GLOBAL, 0);
|
1999-08-10 01:06:28 +04:00
|
|
|
}
|
2011-11-06 23:46:56 +04:00
|
|
|
if (DEBUG(PARSE))
|
|
|
|
fprintf(debug_file, "ParseSetParseFile: ${.PARSEDIR} = `%s' "
|
|
|
|
"${.PARSEFILE} = `%s'\n", pd, pf);
|
|
|
|
free(dirname);
|
1999-08-10 01:06:28 +04:00
|
|
|
}
|
|
|
|
|
2012-04-25 00:12:16 +04:00
|
|
|
/*
|
|
|
|
* Track the makefiles we read - so makefiles can
|
|
|
|
* set dependencies on them.
|
|
|
|
* Avoid adding anything more than once.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ParseTrackInput(const char *name)
|
|
|
|
{
|
|
|
|
char *old;
|
|
|
|
char *fp = NULL;
|
|
|
|
size_t name_len = strlen(name);
|
|
|
|
|
|
|
|
old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
|
|
|
|
if (old) {
|
|
|
|
/* does it contain name? */
|
|
|
|
for (; old != NULL; old = strchr(old, ' ')) {
|
|
|
|
if (*old == ' ')
|
|
|
|
old++;
|
|
|
|
if (memcmp(old, name, name_len) == 0
|
|
|
|
&& (old[name_len] == 0 || old[name_len] == ' '))
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Var_Append (MAKE_MAKEFILES, name, VAR_GLOBAL);
|
|
|
|
cleanup:
|
|
|
|
if (fp) {
|
|
|
|
free(fp);
|
|
|
|
}
|
|
|
|
}
|
2007-10-09 00:26:36 +04:00
|
|
|
|
1999-08-10 01:06:28 +04:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
2006-12-16 11:59:29 +03:00
|
|
|
* Parse_setInput --
|
|
|
|
* Start Parsing from the given source
|
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,
|
2006-12-16 11:59:29 +03:00
|
|
|
* fname and curFile are altered for the new file
|
1994-03-05 03:34:29 +03:00
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2010-12-25 07:57:07 +03:00
|
|
|
Parse_SetInput(const char *name, int line, int fd,
|
|
|
|
char *(*nextbuf)(void *, size_t *), void *arg)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2009-01-11 18:50:06 +03:00
|
|
|
char *buf;
|
2010-12-25 07:57:07 +03:00
|
|
|
size_t len;
|
2009-01-11 18:50:06 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (name == NULL)
|
|
|
|
name = curFile->fname;
|
2007-10-13 03:38:27 +04:00
|
|
|
else
|
2012-04-25 00:12:16 +04:00
|
|
|
ParseTrackInput(name);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
|
|
|
if (DEBUG(PARSE))
|
2009-01-11 18:50:06 +03:00
|
|
|
fprintf(debug_file, "Parse_SetInput: file %s, line %d, fd %d, nextbuf %p, arg %p\n",
|
|
|
|
name, line, fd, nextbuf, arg);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2009-01-11 18:50:06 +03:00
|
|
|
if (fd == -1 && nextbuf == NULL)
|
2006-12-16 11:59:29 +03:00
|
|
|
/* sanity */
|
|
|
|
return;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2007-02-04 22:23:49 +03:00
|
|
|
if (curFile != NULL)
|
|
|
|
/* Save exiting file info */
|
|
|
|
Lst_AtFront(includes, curFile);
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2006-12-16 11:59:29 +03:00
|
|
|
/* Allocate and fill in new structure */
|
2008-10-07 02:09:21 +04:00
|
|
|
curFile = bmake_malloc(sizeof *curFile);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2006-12-16 11:59:29 +03: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.
|
|
|
|
*/
|
2013-06-18 23:31:27 +04:00
|
|
|
curFile->fname = bmake_strdup(name);
|
2006-12-16 11:59:29 +03:00
|
|
|
curFile->lineno = line;
|
2009-01-11 18:50:06 +03:00
|
|
|
curFile->first_lineno = line;
|
|
|
|
curFile->nextbuf = nextbuf;
|
|
|
|
curFile->nextbuf_arg = arg;
|
2010-12-25 07:57:07 +03:00
|
|
|
curFile->lf = NULL;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
assert(nextbuf != NULL);
|
|
|
|
|
|
|
|
/* Get first block of input data */
|
|
|
|
buf = curFile->nextbuf(curFile->nextbuf_arg, &len);
|
|
|
|
if (buf == NULL) {
|
|
|
|
/* Was all a waste of time ... */
|
2013-06-18 23:31:27 +04:00
|
|
|
if (curFile->fname)
|
|
|
|
free(curFile->fname);
|
2010-12-25 07:57:07 +03:00
|
|
|
free(curFile);
|
|
|
|
return;
|
2006-12-16 11:59:29 +03:00
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
curFile->P_str = buf;
|
|
|
|
curFile->P_ptr = buf;
|
|
|
|
curFile->P_end = buf+len;
|
2006-12-16 11:59:29 +03:00
|
|
|
|
2009-01-11 18:50:06 +03:00
|
|
|
curFile->cond_depth = Cond_save_depth();
|
|
|
|
ParseSetParseFile(name);
|
2006-12-16 11:59:29 +03:00
|
|
|
}
|
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 *cp; /* current position in file spec */
|
1998-08-06 17:42:22 +04:00
|
|
|
int done = 0;
|
|
|
|
int silent = (line[0] != 'i') ? 1 : 0;
|
|
|
|
char *file = &line[silent + 7];
|
2006-12-08 00:07:01 +03:00
|
|
|
char *all_files;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2006-03-28 21:41:35 +04:00
|
|
|
if (DEBUG(PARSE)) {
|
2006-10-15 12:38:21 +04:00
|
|
|
fprintf(debug_file, "ParseTraditionalInclude: %s\n", file);
|
2006-03-28 21:41:35 +04:00
|
|
|
}
|
|
|
|
|
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++;
|
|
|
|
|
2006-03-28 21:41:35 +04:00
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
2006-12-08 00:07:01 +03:00
|
|
|
all_files = Var_Subst(NULL, file, VAR_CMD, FALSE);
|
2006-03-28 21:41:35 +04:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
if (*file == '\0') {
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
1994-03-05 03:34:29 +03:00
|
|
|
"Filename missing from \"include\"");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-08 00:07:01 +03:00
|
|
|
for (file = all_files; !done; file = cp + 1) {
|
|
|
|
/* Skip to end of line or next whitespace */
|
1998-08-06 17:42:22 +04:00
|
|
|
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
|
|
|
|
2006-12-08 00:07:01 +03:00
|
|
|
Parse_include_file(file, FALSE, silent);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
2006-12-08 00:07:01 +03:00
|
|
|
free(all_files);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-20 09:33:41 +04:00
|
|
|
#ifdef GMAKEEXPORT
|
2012-03-31 04:12:24 +04:00
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* ParseGmakeExport --
|
|
|
|
* Parse export <variable>=<value>
|
|
|
|
*
|
|
|
|
* And set the environment with it.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* None
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ParseGmakeExport(char *line)
|
|
|
|
{
|
|
|
|
char *variable = &line[6];
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
if (DEBUG(PARSE)) {
|
2012-04-20 09:33:41 +04:00
|
|
|
fprintf(debug_file, "ParseGmakeExport: %s\n", variable);
|
2012-03-31 04:12:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over whitespace
|
|
|
|
*/
|
|
|
|
while (isspace((unsigned char)*variable))
|
|
|
|
variable++;
|
|
|
|
|
|
|
|
for (value = variable; *value && *value != '='; value++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*value != '=') {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2012-04-20 09:33:41 +04:00
|
|
|
"Variable/Value missing from \"export\"");
|
2012-03-31 04:12:24 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-03-22 20:07:59 +04:00
|
|
|
*value++ = '\0'; /* terminate variable */
|
2012-03-31 04:12:24 +04:00
|
|
|
|
|
|
|
/*
|
2012-04-20 09:33:41 +04:00
|
|
|
* Expand the value before putting it in the environment.
|
2012-03-31 04:12:24 +04:00
|
|
|
*/
|
|
|
|
value = Var_Subst(NULL, value, VAR_CMD, FALSE);
|
|
|
|
setenv(variable, value, 1);
|
|
|
|
}
|
|
|
|
#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
|
2006-12-08 00:07:01 +03:00
|
|
|
ParseEOF(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-01-11 18:50:06 +03:00
|
|
|
char *ptr;
|
2010-12-25 07:57:07 +03:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
assert(curFile->nextbuf != NULL);
|
|
|
|
|
|
|
|
/* get next input buffer, if any */
|
|
|
|
ptr = curFile->nextbuf(curFile->nextbuf_arg, &len);
|
|
|
|
curFile->P_ptr = ptr;
|
|
|
|
curFile->P_str = ptr;
|
|
|
|
curFile->P_end = ptr + len;
|
|
|
|
curFile->lineno = curFile->first_lineno;
|
|
|
|
if (ptr != NULL) {
|
|
|
|
/* Iterate again */
|
|
|
|
return CONTINUE;
|
2009-01-11 18:50:06 +03:00
|
|
|
}
|
|
|
|
|
2007-02-04 22:23:49 +03:00
|
|
|
/* Ensure the makefile (or loop) didn't have mismatched conditionals */
|
|
|
|
Cond_restore_depth(curFile->cond_depth);
|
2007-01-25 00:43:01 +03:00
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
if (curFile->lf != NULL) {
|
|
|
|
loadedfile_destroy(curFile->lf);
|
|
|
|
curFile->lf = NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-16 11:59:29 +03:00
|
|
|
/* Dispose of curFile info */
|
|
|
|
/* Leak curFile->fname because all the gnodes have pointers to it */
|
|
|
|
free(curFile->P_str);
|
|
|
|
free(curFile);
|
|
|
|
|
2007-02-04 22:23:49 +03:00
|
|
|
curFile = Lst_DeQueue(includes);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-12-13 18:19:29 +03:00
|
|
|
if (curFile == NULL) {
|
2006-12-16 11:59:29 +03:00
|
|
|
/* We've run out of input */
|
1999-08-10 01:06:28 +04:00
|
|
|
Var_Delete(".PARSEDIR", VAR_GLOBAL);
|
|
|
|
Var_Delete(".PARSEFILE", VAR_GLOBAL);
|
2006-12-16 11:59:29 +03:00
|
|
|
return DONE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (DEBUG(PARSE))
|
2010-12-25 07:57:07 +03:00
|
|
|
fprintf(debug_file, "ParseEOF: returning to file %s, line %d\n",
|
|
|
|
curFile->fname, curFile->lineno);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2006-12-16 11:59:29 +03:00
|
|
|
/* Restore the PARSEDIR/PARSEFILE variables */
|
|
|
|
ParseSetParseFile(curFile->fname);
|
1993-03-21 12:45:37 +03:00
|
|
|
return (CONTINUE);
|
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
#define PARSE_RAW 1
|
|
|
|
#define PARSE_SKIP 2
|
|
|
|
|
|
|
|
static char *
|
|
|
|
ParseGetLine(int flags, int *length)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2006-12-16 11:59:29 +03:00
|
|
|
IFile *cf = curFile;
|
2007-01-02 00:47:32 +03:00
|
|
|
char *ptr;
|
2006-12-16 11:59:29 +03:00
|
|
|
char ch;
|
2007-01-02 00:47:32 +03:00
|
|
|
char *line;
|
|
|
|
char *line_end;
|
|
|
|
char *escaped;
|
|
|
|
char *comment;
|
|
|
|
char *tp;
|
2006-12-16 11:59:29 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Loop through blank lines and comment lines */
|
2006-12-16 11:59:29 +03:00
|
|
|
for (;;) {
|
2007-01-02 00:47:32 +03:00
|
|
|
cf->lineno++;
|
|
|
|
line = cf->P_ptr;
|
|
|
|
ptr = line;
|
|
|
|
line_end = line;
|
|
|
|
escaped = NULL;
|
|
|
|
comment = NULL;
|
|
|
|
for (;;) {
|
2010-12-25 07:57:07 +03:00
|
|
|
if (cf->P_end != NULL && ptr == cf->P_end) {
|
|
|
|
/* end of buffer */
|
|
|
|
ch = 0;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-02 00:47:32 +03:00
|
|
|
ch = *ptr;
|
|
|
|
if (ch == 0 || (ch == '\\' && ptr[1] == 0)) {
|
|
|
|
if (cf->P_end == NULL)
|
|
|
|
/* End of string (aka for loop) data */
|
|
|
|
break;
|
2013-08-11 01:20:03 +04:00
|
|
|
/* see if there is more we can parse */
|
|
|
|
while (ptr++ < cf->P_end) {
|
|
|
|
if ((ch = *ptr) == '\n') {
|
|
|
|
if (ptr > line && ptr[-1] == '\\')
|
|
|
|
continue;
|
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"Zero byte read from file, skipping rest of line.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
if (cf->nextbuf != NULL) {
|
|
|
|
/*
|
|
|
|
* End of this buffer; return EOF and outer logic
|
|
|
|
* will get the next one. (eww)
|
|
|
|
*/
|
2007-01-02 00:47:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Zero byte read from file");
|
|
|
|
return NULL;
|
2007-01-02 00:47:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == '\\') {
|
|
|
|
/* Don't treat next character as special, remember first one */
|
|
|
|
if (escaped == NULL)
|
|
|
|
escaped = ptr;
|
|
|
|
if (ptr[1] == '\n')
|
|
|
|
cf->lineno++;
|
|
|
|
ptr += 2;
|
|
|
|
line_end = ptr;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == '#' && comment == NULL) {
|
|
|
|
/* Remember first '#' for comment stripping */
|
2012-03-25 00:28:41 +04:00
|
|
|
/* Unless previous char was '[', as in modifier :[#] */
|
|
|
|
if (!(ptr > line && ptr[-1] == '['))
|
|
|
|
comment = line_end;
|
2007-01-02 00:47:32 +03:00
|
|
|
}
|
|
|
|
ptr++;
|
2006-12-16 11:59:29 +03:00
|
|
|
if (ch == '\n')
|
2007-01-02 00:47:32 +03:00
|
|
|
break;
|
|
|
|
if (!isspace((unsigned char)ch))
|
|
|
|
/* We are not interested in trailing whitespace */
|
|
|
|
line_end = ptr;
|
2006-12-16 11:59:29 +03:00
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Save next 'to be processed' location */
|
|
|
|
cf->P_ptr = ptr;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Check we have a non-comment, non-blank line */
|
|
|
|
if (line_end == line || comment == line) {
|
|
|
|
if (ch == 0)
|
|
|
|
/* At end of file */
|
|
|
|
return NULL;
|
|
|
|
/* Parse another line */
|
|
|
|
continue;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* We now have a line of data */
|
|
|
|
*line_end = 0;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (flags & PARSE_RAW) {
|
|
|
|
/* Leave '\' (etc) in line buffer (eg 'for' lines) */
|
|
|
|
*length = line_end - line;
|
|
|
|
return line;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (flags & PARSE_SKIP) {
|
|
|
|
/* Completely ignore non-directives */
|
|
|
|
if (line[0] != '.')
|
|
|
|
continue;
|
|
|
|
/* We could do more of the .else/.elif/.endif checks here */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Brutally ignore anything after a non-escaped '#' in non-commands */
|
|
|
|
if (comment != NULL && line[0] != '\t') {
|
|
|
|
line_end = comment;
|
|
|
|
*line_end = 0;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* If we didn't see a '\\' then the in-situ data is fine */
|
|
|
|
if (escaped == NULL) {
|
|
|
|
*length = line_end - line;
|
|
|
|
return line;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Remove escapes from '\n' and '#' */
|
|
|
|
tp = ptr = escaped;
|
|
|
|
escaped = line;
|
|
|
|
for (; ; *tp++ = ch) {
|
|
|
|
ch = *ptr++;
|
|
|
|
if (ch != '\\') {
|
|
|
|
if (ch == 0)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
ch = *ptr++;
|
|
|
|
if (ch == 0) {
|
|
|
|
/* Delete '\\' at end of buffer */
|
|
|
|
tp--;
|
|
|
|
break;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-18 23:22:44 +03:00
|
|
|
if (ch == '#' && line[0] != '\t')
|
|
|
|
/* Delete '\\' from before '#' on non-command lines */
|
2007-01-02 00:47:32 +03:00
|
|
|
continue;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (ch != '\n') {
|
|
|
|
/* Leave '\\' in buffer for later */
|
|
|
|
*tp++ = '\\';
|
|
|
|
/* Make sure we don't delete an escaped ' ' from the line end */
|
|
|
|
escaped = tp + 1;
|
|
|
|
continue;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-03 02:22:37 +03:00
|
|
|
/* Escaped '\n' replace following whitespace with a single ' ' */
|
2007-01-02 00:47:32 +03:00
|
|
|
while (ptr[0] == ' ' || ptr[0] == '\t')
|
|
|
|
ptr++;
|
|
|
|
ch = ' ';
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Delete any trailing spaces - eg from empty continuations */
|
|
|
|
while (tp > escaped && isspace((unsigned char)tp[-1]))
|
|
|
|
tp--;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
*tp = 0;
|
|
|
|
*length = tp - line;
|
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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
1994-06-07 02:45:17 +04:00
|
|
|
char *line; /* Result */
|
1993-03-21 12:45:37 +03:00
|
|
|
int lineLength; /* Length of result */
|
2004-03-06 06:57:07 +03:00
|
|
|
int lineno; /* Saved line # */
|
2008-11-29 20:50:11 +03:00
|
|
|
int rval;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
for (;;) {
|
2007-01-02 00:47:32 +03:00
|
|
|
line = ParseGetLine(0, &lineLength);
|
|
|
|
if (line == NULL)
|
|
|
|
return NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
if (line[0] != '.')
|
|
|
|
return line;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2006-12-03 23:40:44 +03:00
|
|
|
/*
|
2007-01-02 00:47:32 +03:00
|
|
|
* The line might be a conditional. Ask the conditional module
|
|
|
|
* about it and act accordingly
|
2006-12-03 23:40:44 +03:00
|
|
|
*/
|
2007-01-02 00:47:32 +03:00
|
|
|
switch (Cond_Eval(line)) {
|
|
|
|
case COND_SKIP:
|
|
|
|
/* Skip to next conditional that evaluates to COND_PARSE. */
|
|
|
|
do {
|
|
|
|
line = ParseGetLine(PARSE_SKIP, &lineLength);
|
|
|
|
} while (line && Cond_Eval(line) != COND_PARSE);
|
|
|
|
if (line == NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2007-01-02 00:47:32 +03:00
|
|
|
continue;
|
|
|
|
case COND_PARSE:
|
|
|
|
continue;
|
|
|
|
case COND_INVALID: /* Not a conditional line */
|
2008-11-29 20:50:11 +03:00
|
|
|
/* Check for .for loops */
|
|
|
|
rval = For_Eval(line);
|
|
|
|
if (rval == 0)
|
|
|
|
/* Not a .for line */
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2008-11-29 20:50:11 +03:00
|
|
|
if (rval < 0)
|
|
|
|
/* Syntax error - error printed, ignore line */
|
|
|
|
continue;
|
|
|
|
/* Start of a .for loop */
|
2007-01-02 00:47:32 +03:00
|
|
|
lineno = curFile->lineno;
|
2008-11-29 20:50:11 +03:00
|
|
|
/* Accumulate loop lines until matching .endfor */
|
2006-12-03 23:40:44 +03:00
|
|
|
do {
|
2007-01-02 00:47:32 +03:00
|
|
|
line = ParseGetLine(PARSE_RAW, &lineLength);
|
2006-12-03 23:40:44 +03:00
|
|
|
if (line == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2011-02-20 23:15:36 +03:00
|
|
|
"Unexpected end of file in for loop.");
|
1994-03-05 03:34:29 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-11-29 20:50:11 +03:00
|
|
|
} while (For_Accum(line));
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Stash each iteration as a new 'input file' */
|
|
|
|
For_Run(lineno);
|
|
|
|
/* Read next line from for-loop buffer */
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2007-01-02 00:47:32 +03:00
|
|
|
return (line);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
* 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) {
|
2006-10-28 01:00:18 +04:00
|
|
|
Lst_ForEach(targets, Suff_EndTransform, NULL);
|
2005-02-16 18:11:52 +03:00
|
|
|
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
|
2006-12-16 11:59:29 +03:00
|
|
|
* fd Open file to makefile to parse
|
2002-06-15 22:24:55 +04:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Results:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Side Effects:
|
2006-12-16 11:59:29 +03:00
|
|
|
* closes fd.
|
1993-03-21 12:45:37 +03:00
|
|
|
* Loads. Nodes are added to the list of all targets, nodes and links
|
|
|
|
* are added to the dependency graph. etc. etc. etc.
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2006-12-16 11:59:29 +03:00
|
|
|
Parse_File(const char *name, int fd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2006-10-15 22:08:14 +04:00
|
|
|
char *cp; /* pointer into the line */
|
|
|
|
char *line; /* the line we're working on */
|
2010-12-25 07:57:07 +03:00
|
|
|
struct loadedfile *lf;
|
|
|
|
|
|
|
|
lf = loadfile(name, fd);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
inLine = FALSE;
|
|
|
|
fatals = 0;
|
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
if (name == NULL) {
|
|
|
|
name = "(stdin)";
|
|
|
|
}
|
|
|
|
|
|
|
|
Parse_SetInput(name, 0, -1, loadedfile_nextbuf, lf);
|
|
|
|
curFile->lf = lf;
|
1999-08-10 01:06:28 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
do {
|
2007-01-02 00:47:32 +03:00
|
|
|
for (; (line = ParseReadLine()) != NULL; ) {
|
2006-11-18 01:07:39 +03:00
|
|
|
if (DEBUG(PARSE))
|
2008-02-16 00:29:50 +03:00
|
|
|
fprintf(debug_file, "ParseReadLine (%d): '%s'\n",
|
|
|
|
curFile->lineno, line);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (*line == '.') {
|
|
|
|
/*
|
2009-11-06 23:20:56 +03:00
|
|
|
* Lines that begin with the special character may be
|
1993-03-21 12:45:37 +03:00
|
|
|
* include or undef directives.
|
2009-11-06 23:20:56 +03:00
|
|
|
* On the other hand they can be suffix rules (.c.o: ...)
|
|
|
|
* or just dependencies for filenames that start '.'.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2007-01-02 00:47:32 +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 ||
|
2007-01-02 00:47:32 +03:00
|
|
|
((cp[0] == 's' || cp[0] == '-') &&
|
|
|
|
strncmp(&cp[1], "include", 7) == 0)) {
|
2005-02-16 18:11:52 +03:00
|
|
|
ParseDoInclude(cp);
|
2006-10-15 22:08:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strncmp(cp, "undef", 5) == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
char *cp2;
|
2007-01-02 00:47:32 +03: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) &&
|
2007-01-02 00:47:32 +03:00
|
|
|
(*cp2 != '\0'); cp2++)
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
*cp2 = '\0';
|
|
|
|
Var_Delete(cp, VAR_GLOBAL);
|
2006-10-15 22:08:14 +04:00
|
|
|
continue;
|
2007-10-05 19:27:45 +04:00
|
|
|
} else if (strncmp(cp, "export", 6) == 0) {
|
|
|
|
for (cp += 6; isspace((unsigned char) *cp); cp++)
|
|
|
|
continue;
|
|
|
|
Var_Export(cp, 1);
|
|
|
|
continue;
|
2009-11-19 03:30:24 +03:00
|
|
|
} else if (strncmp(cp, "unexport", 8) == 0) {
|
|
|
|
Var_UnExport(cp);
|
|
|
|
continue;
|
2010-04-07 04:11:27 +04:00
|
|
|
} else if (strncmp(cp, "info", 4) == 0 ||
|
|
|
|
strncmp(cp, "error", 5) == 0 ||
|
|
|
|
strncmp(cp, "warning", 7) == 0) {
|
2010-05-25 01:04:49 +04:00
|
|
|
if (ParseMessage(cp))
|
|
|
|
continue;
|
2010-04-07 04:11:27 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
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
|
|
|
*/
|
2007-02-24 20:55:54 +03:00
|
|
|
cp = line + 1;
|
2007-01-02 00:47:32 +03:00
|
|
|
shellCommand:
|
2007-02-24 20:55:54 +03:00
|
|
|
for (; isspace ((unsigned char)*cp); cp++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp) {
|
2006-10-15 22:08:14 +04:00
|
|
|
if (!inLine)
|
2005-02-16 18:11:52 +03:00
|
|
|
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);
|
2006-10-15 22:08:14 +04:00
|
|
|
/*
|
|
|
|
* So long as it's not a blank line and we're actually
|
|
|
|
* in a dependency spec, add the command to the list of
|
|
|
|
* commands of all targets in the dependency spec
|
|
|
|
*/
|
2007-01-15 04:26:32 +03:00
|
|
|
if (targets) {
|
2008-10-07 02:09:21 +04:00
|
|
|
cp = bmake_strdup(cp);
|
2007-01-15 04:26:32 +03:00
|
|
|
Lst_ForEach(targets, ParseAddCmd, cp);
|
2006-10-15 22:08:14 +04:00
|
|
|
#ifdef CLEANUP
|
2007-01-15 04:26:32 +03:00
|
|
|
Lst_AtEnd(targCmds, cp);
|
2006-10-15 22:08:14 +04:00
|
|
|
#endif
|
2007-01-15 04:26:32 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2006-10-15 22:08:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
#ifdef SYSVINCLUDE
|
2006-10-15 22:08:14 +04:00
|
|
|
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".
|
|
|
|
*/
|
2005-02-16 18:11:52 +03:00
|
|
|
ParseTraditionalInclude(line);
|
2006-10-15 22:08:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-31 04:12:24 +04:00
|
|
|
#endif
|
|
|
|
#ifdef GMAKEEXPORT
|
|
|
|
if (strncmp(line, "export", 6) == 0 &&
|
|
|
|
isspace((unsigned char) line[6]) &&
|
|
|
|
strchr(line, ':') == NULL) {
|
|
|
|
/*
|
2012-04-20 09:33:41 +04:00
|
|
|
* It's a Gmake "export".
|
2012-03-31 04:12:24 +04:00
|
|
|
*/
|
|
|
|
ParseGmakeExport(line);
|
|
|
|
continue;
|
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
#endif
|
2006-10-15 22:08:14 +04:00
|
|
|
if (Parse_IsVar(line)) {
|
1993-03-21 12:45:37 +03:00
|
|
|
ParseFinishLine();
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_DoVar(line, VAR_GLOBAL);
|
2006-10-15 22:08:14 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
#ifndef POSIX
|
2006-10-15 22:08:14 +04:00
|
|
|
/*
|
|
|
|
* To make life easier on novices, if the line is indented we
|
|
|
|
* first make sure the line has a dependency operator in it.
|
|
|
|
* If it doesn't have an operator and we're in a dependency
|
|
|
|
* line's script, we assume it's actually a shell command
|
|
|
|
* and add it to the current list of targets.
|
|
|
|
*/
|
|
|
|
cp = line;
|
|
|
|
if (isspace((unsigned char) line[0])) {
|
2007-01-02 00:47:32 +03:00
|
|
|
while ((*cp != '\0') && isspace((unsigned char) *cp))
|
2006-10-15 22:08:14 +04:00
|
|
|
cp++;
|
|
|
|
while (*cp && (ParseIsEscaped(line, cp) ||
|
2002-01-26 23:42:14 +03:00
|
|
|
(*cp != ':') && (*cp != '!'))) {
|
2006-10-15 22:08:14 +04:00
|
|
|
cp++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2007-01-02 00:47:32 +03:00
|
|
|
if (*cp == '\0') {
|
|
|
|
if (inLine) {
|
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"Shell command needs a leading tab");
|
|
|
|
goto shellCommand;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 22:08:14 +04:00
|
|
|
#endif
|
|
|
|
ParseFinishLine();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/*
|
|
|
|
* For some reason - probably to make the parser impossible -
|
|
|
|
* a ';' can be used to separate commands from dependencies.
|
2009-10-07 20:40:30 +04:00
|
|
|
* Attempt to avoid ';' inside substitution patterns.
|
2007-01-02 00:47:32 +03:00
|
|
|
*/
|
2009-10-07 20:40:30 +04:00
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
for (cp = line; *cp != 0; cp++) {
|
|
|
|
if (*cp == '\\' && cp[1] != 0) {
|
|
|
|
cp++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*cp == '$' &&
|
|
|
|
(cp[1] == '(' || cp[1] == '{')) {
|
|
|
|
level++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (level > 0) {
|
|
|
|
if (*cp == ')' || *cp == '}') {
|
|
|
|
level--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (*cp == ';') {
|
|
|
|
break;
|
|
|
|
}
|
2007-01-02 00:47:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*cp != 0)
|
|
|
|
/* Terminate the dependency list at the ';' */
|
2007-02-24 20:55:54 +03:00
|
|
|
*cp++ = 0;
|
2007-01-02 00:47:32 +03:00
|
|
|
else
|
|
|
|
cp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
|
|
|
line = Var_Subst(NULL, line, VAR_CMD, TRUE);
|
2006-10-15 22:08:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Need a non-circular list for the target nodes
|
|
|
|
*/
|
|
|
|
if (targets)
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(targets, NULL);
|
2006-10-15 22:08:14 +04:00
|
|
|
|
|
|
|
targets = Lst_Init(FALSE);
|
|
|
|
inLine = TRUE;
|
|
|
|
|
|
|
|
ParseDoDependency(line);
|
2007-01-02 00:47:32 +03:00
|
|
|
free(line);
|
|
|
|
|
|
|
|
/* If there were commands after a ';', add them now */
|
|
|
|
if (cp != NULL) {
|
|
|
|
goto shellCommand;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
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
|
|
|
*/
|
2006-12-08 00:07:01 +03:00
|
|
|
} while (ParseEOF() == CONTINUE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (fatals) {
|
2010-04-30 03:12:21 +04:00
|
|
|
(void)fflush(stdout);
|
2001-02-24 00:11:38 +03:00
|
|
|
(void)fprintf(stderr,
|
2011-02-20 23:17:35 +03:00
|
|
|
"%s: Fatal errors encountered -- cannot continue",
|
2001-02-24 00:11:38 +03:00
|
|
|
progname);
|
2010-04-07 04:11:27 +04:00
|
|
|
PrintOnError(NULL, NULL);
|
2005-07-26 02:55:58 +04:00
|
|
|
exit(1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-
|
|
|
|
*---------------------------------------------------------------------
|
|
|
|
* 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
|
|
|
{
|
2008-12-13 18:19:29 +03:00
|
|
|
mainNode = NULL;
|
2005-02-16 18:11:52 +03:00
|
|
|
parseIncPath = Lst_Init(FALSE);
|
|
|
|
sysIncPath = Lst_Init(FALSE);
|
|
|
|
defIncPath = Lst_Init(FALSE);
|
|
|
|
includes = Lst_Init(FALSE);
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
2005-02-16 18:11:52 +03: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
|
2005-08-10 01:36:42 +04:00
|
|
|
Lst_Destroy(targCmds, (FreeProc *)free);
|
1994-06-07 02:45:17 +04:00
|
|
|
if (targets)
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(targets, NULL);
|
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);
|
2008-12-13 18:19:29 +03:00
|
|
|
Lst_Destroy(includes, NULL); /* 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
|
|
|
|
2005-02-16 18:11:52 +03:00
|
|
|
mainList = Lst_Init(FALSE);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2008-12-13 18:19:29 +03:00
|
|
|
if (mainNode == NULL) {
|
2005-02-16 18:11:52 +03:00
|
|
|
Punt("no target to make.");
|
1993-03-21 12:45:37 +03:00
|
|
|
/*NOTREACHED*/
|
|
|
|
} else if (mainNode->type & OP_DOUBLEDEP) {
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(mainList, mainNode);
|
1998-03-23 11:52:48 +03:00
|
|
|
Lst_Concat(mainList, mainNode->cohorts, LST_CONCNEW);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
else
|
2006-10-28 01:00:18 +04:00
|
|
|
(void)Lst_AtEnd(mainList, 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
|
|
|
{
|
2006-12-16 11:59:29 +03:00
|
|
|
gn->fname = curFile->fname;
|
|
|
|
gn->lineno = curFile->lineno;
|
2001-01-14 08:34:06 +03:00
|
|
|
}
|