2020-10-28 03:38:37 +03:00
|
|
|
/* $NetBSD: parse.c,v 1.402 2020/10/28 00:38:37 rillig 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.
|
|
|
|
*/
|
|
|
|
|
2020-10-28 03:38:37 +03:00
|
|
|
/*
|
|
|
|
* Parsing of makefiles.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_File is the main entry point and controls most of the other
|
|
|
|
* functions in this module.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* The directories for the .include "..." directive are kept in
|
|
|
|
* 'parseIncPath', while those for .include <...> are kept in 'sysIncPath'.
|
|
|
|
* The targets currently being defined are kept in 'targets'.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Interface:
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_Init Initialize the module
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-18 00:32:30 +03:00
|
|
|
* Parse_End Clean up the module
|
1994-06-07 02:45:17 +04:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_File Parse a top-level makefile. Included files are
|
|
|
|
* handled by Parse_include_file though.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_IsVar Return 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.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_Error Report a parse error, a warning or an informational
|
|
|
|
* message.
|
2020-09-28 00:35:16 +03:00
|
|
|
*
|
2020-10-28 03:38:37 +03:00
|
|
|
* Parse_MainName Returns a list of the main target to create.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
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>
|
1994-03-05 03:34:29 +03:00
|
|
|
#include <errno.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
#include <stdarg.h>
|
2017-04-17 16:29:07 +03:00
|
|
|
#include <stdint.h>
|
2002-06-15 22:24:55 +04:00
|
|
|
|
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 "dir.h"
|
|
|
|
#include "job.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
2020-09-13 18:15:51 +03:00
|
|
|
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
|
2020-10-28 03:38:37 +03:00
|
|
|
MAKE_RCSID("$NetBSD: parse.c,v 1.402 2020/10/28 00:38:37 rillig Exp $");
|
2020-09-13 18:15:51 +03:00
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* types and constants */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
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 {
|
2020-09-28 00:35:16 +03:00
|
|
|
char *fname; /* name of file */
|
|
|
|
Boolean fromForLoop; /* simulated .include by the .for loop */
|
|
|
|
int lineno; /* current line number in file */
|
|
|
|
int first_lineno; /* line number of start of text */
|
2020-10-06 00:37:07 +03:00
|
|
|
unsigned int cond_depth; /* 'if' nesting when file opened */
|
2020-09-28 00:35:16 +03:00
|
|
|
Boolean depending; /* state of doing_depend on EOF */
|
|
|
|
char *P_str; /* point to base of string buffer */
|
|
|
|
char *P_ptr; /* point to next char of string buffer */
|
|
|
|
char *P_end; /* point to the end of string buffer */
|
|
|
|
char *(*nextbuf)(void *, size_t *); /* Function to get more data */
|
|
|
|
void *nextbuf_arg; /* Opaque arg for nextbuf() */
|
|
|
|
struct loadedfile *lf; /* loadedfile object, if any */
|
1994-03-05 03:34:29 +03:00
|
|
|
} IFile;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
/*
|
|
|
|
* Tokens for target attributes
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-18 20:19:54 +03:00
|
|
|
typedef enum ParseSpecial {
|
2020-09-28 00:35:16 +03:00
|
|
|
Begin, /* .BEGIN */
|
|
|
|
Default, /* .DEFAULT */
|
|
|
|
DeleteOnError, /* .DELETE_ON_ERROR */
|
|
|
|
End, /* .END */
|
|
|
|
dotError, /* .ERROR */
|
|
|
|
Ignore, /* .IGNORE */
|
|
|
|
Includes, /* .INCLUDES */
|
|
|
|
Interrupt, /* .INTERRUPT */
|
|
|
|
Libs, /* .LIBS */
|
|
|
|
Meta, /* .META */
|
|
|
|
MFlags, /* .MFLAGS or .MAKEFLAGS */
|
|
|
|
Main, /* .MAIN and we don't have anything user-specified to
|
|
|
|
* make */
|
|
|
|
NoExport, /* .NOEXPORT */
|
|
|
|
NoMeta, /* .NOMETA */
|
|
|
|
NoMetaCmp, /* .NOMETA_CMP */
|
|
|
|
NoPath, /* .NOPATH */
|
|
|
|
Not, /* Not special */
|
|
|
|
NotParallel, /* .NOTPARALLEL */
|
|
|
|
Null, /* .NULL */
|
|
|
|
ExObjdir, /* .OBJDIR */
|
|
|
|
Order, /* .ORDER */
|
|
|
|
Parallel, /* .PARALLEL */
|
|
|
|
ExPath, /* .PATH */
|
|
|
|
Phony, /* .PHONY */
|
2000-05-11 12:22:40 +04:00
|
|
|
#ifdef POSIX
|
2020-09-28 00:35:16 +03:00
|
|
|
Posix, /* .POSIX */
|
2000-05-11 12:22:40 +04:00
|
|
|
#endif
|
2020-09-28 00:35:16 +03:00
|
|
|
Precious, /* .PRECIOUS */
|
|
|
|
ExShell, /* .SHELL */
|
|
|
|
Silent, /* .SILENT */
|
|
|
|
SingleShell, /* .SINGLESHELL */
|
|
|
|
Stale, /* .STALE */
|
|
|
|
Suffixes, /* .SUFFIXES */
|
|
|
|
Wait, /* .WAIT */
|
|
|
|
Attribute /* Generic attribute */
|
1993-03-21 12:45:37 +03:00
|
|
|
} ParseSpecial;
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
typedef List SearchPathList;
|
2020-10-19 23:51:18 +03:00
|
|
|
typedef ListNode SearchPathListNode;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* result data */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The main target to create. This is the first target on the first
|
|
|
|
* dependency line in the first makefile.
|
|
|
|
*/
|
|
|
|
static GNode *mainNode;
|
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* eval state */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
2020-09-27 15:26:23 +03:00
|
|
|
/* During parsing, the targets from the currently active dependency line,
|
|
|
|
* or NULL if the current line does not belong to a dependency line, for
|
|
|
|
* example because it is a variable assignment.
|
2020-09-14 21:21:26 +03:00
|
|
|
*
|
|
|
|
* See unit-tests/deptgt.mk, keyword "parse.c:targets". */
|
2020-09-22 07:05:41 +03:00
|
|
|
static GNodeList *targets;
|
2010-12-13 06:32:25 +03:00
|
|
|
|
|
|
|
#ifdef CLEANUP
|
2020-10-17 20:23:22 +03:00
|
|
|
/* All shell commands for all targets, in no particular order and possibly
|
|
|
|
* with duplicates. Kept in a separate list since the commands from .USE or
|
|
|
|
* .USEBEFORE nodes are shared with other GNodes, thereby giving up the
|
|
|
|
* easily understandable ownership over the allocated strings. */
|
2020-09-22 07:05:41 +03:00
|
|
|
static StringList *targCmds;
|
2010-12-13 06:32:25 +03:00
|
|
|
#endif
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-10-17 21:36:56 +03:00
|
|
|
static GNode *predecessor;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* parser state */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
|
|
|
/* number of fatal errors */
|
|
|
|
static int fatals = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Variables for doing includes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* current file being read */
|
|
|
|
static IFile *curFile;
|
|
|
|
|
2020-09-14 22:59:47 +03:00
|
|
|
/* The include chain of makefiles that leads to curFile. At the bottom of
|
|
|
|
* the stack is the top-level makefile from the command line, and on top of
|
|
|
|
* this file, there are the included files or .for loops, up to but excluding
|
|
|
|
* curFile.
|
|
|
|
*
|
|
|
|
* This data could be used to print stack traces on parse errors. As of
|
|
|
|
* 2020-09-14, this is not done though. It seems quite simple to print the
|
|
|
|
* tuples (fname:lineno:fromForLoop), from top to bottom. This simple idea is
|
|
|
|
* made complicated by the fact that the .for loops also use this stack for
|
|
|
|
* storing information.
|
|
|
|
*
|
|
|
|
* The lineno fields of the IFiles with fromForLoop == TRUE look confusing,
|
|
|
|
* which is demonstrated by the test 'include-main.mk'. They seem sorted
|
|
|
|
* backwards since they tell the number of completely parsed lines, which for
|
|
|
|
* a .for loop is right after the terminating .endfor. To compensate for this
|
|
|
|
* confusion, there is another field first_lineno pointing at the start of the
|
|
|
|
* .for loop, 1-based for human consumption.
|
|
|
|
*
|
|
|
|
* To make the stack trace intuitive, the entry below the first .for loop must
|
|
|
|
* be ignored completely since neither its lineno nor its first_lineno is
|
|
|
|
* useful. Instead, the topmost .for loop needs to be printed twice, once
|
|
|
|
* with its first_lineno and once with its lineno.
|
|
|
|
*
|
|
|
|
* As of 2020-09-15, using the above rules, the stack trace for the .info line
|
|
|
|
* in include-subsub.mk would be:
|
|
|
|
*
|
|
|
|
* curFile: include-subsub.mk:4
|
|
|
|
* (lineno, from an .include)
|
|
|
|
* includes[4]: include-sub.mk:32
|
|
|
|
* (lineno, from a .for loop below an .include)
|
|
|
|
* includes[4]: include-sub.mk:31
|
|
|
|
* (first_lineno, from a .for loop, lineno == 32)
|
|
|
|
* includes[3]: include-sub.mk:30
|
|
|
|
* (first_lineno, from a .for loop, lineno == 33)
|
|
|
|
* includes[2]: include-sub.mk:29
|
|
|
|
* (first_lineno, from a .for loop, lineno == 34)
|
|
|
|
* includes[1]: include-sub.mk:35
|
|
|
|
* (not printed since it is below a .for loop)
|
|
|
|
* includes[0]: include-main.mk:27
|
|
|
|
*/
|
2020-10-25 16:06:12 +03:00
|
|
|
static Vector /* of IFile pointer */ includes;
|
|
|
|
|
|
|
|
static IFile *
|
|
|
|
GetInclude(size_t i)
|
|
|
|
{
|
|
|
|
return *((IFile **)Vector_Get(&includes, i));
|
|
|
|
}
|
2010-12-13 06:32:25 +03:00
|
|
|
|
|
|
|
/* include paths (lists of directories) */
|
2020-09-22 07:05:41 +03:00
|
|
|
SearchPath *parseIncPath; /* dirs for "..." includes */
|
|
|
|
SearchPath *sysIncPath; /* dirs for <...> includes */
|
|
|
|
SearchPath *defIncPath; /* default for sysIncPath */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* parser tables */
|
2010-12-13 06:32:25 +03:00
|
|
|
|
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 {
|
2020-09-28 00:35:16 +03:00
|
|
|
const char *name; /* Name of keyword */
|
|
|
|
ParseSpecial spec; /* Type when used as a target */
|
|
|
|
GNodeType op; /* Operator when used as a source */
|
1993-03-21 12:45:37 +03:00
|
|
|
} parseKeywords[] = {
|
2020-09-28 00:35:16 +03:00
|
|
|
{ ".BEGIN", Begin, 0 },
|
|
|
|
{ ".DEFAULT", Default, 0 },
|
|
|
|
{ ".DELETE_ON_ERROR", DeleteOnError, 0 },
|
|
|
|
{ ".END", End, 0 },
|
|
|
|
{ ".ERROR", dotError, 0 },
|
|
|
|
{ ".EXEC", Attribute, OP_EXEC },
|
|
|
|
{ ".IGNORE", Ignore, OP_IGNORE },
|
|
|
|
{ ".INCLUDES", Includes, 0 },
|
|
|
|
{ ".INTERRUPT", Interrupt, 0 },
|
|
|
|
{ ".INVISIBLE", Attribute, OP_INVISIBLE },
|
|
|
|
{ ".JOIN", Attribute, OP_JOIN },
|
|
|
|
{ ".LIBS", Libs, 0 },
|
|
|
|
{ ".MADE", Attribute, OP_MADE },
|
|
|
|
{ ".MAIN", Main, 0 },
|
|
|
|
{ ".MAKE", Attribute, OP_MAKE },
|
|
|
|
{ ".MAKEFLAGS", MFlags, 0 },
|
|
|
|
{ ".META", Meta, OP_META },
|
|
|
|
{ ".MFLAGS", MFlags, 0 },
|
|
|
|
{ ".NOMETA", NoMeta, OP_NOMETA },
|
|
|
|
{ ".NOMETA_CMP", NoMetaCmp, OP_NOMETA_CMP },
|
|
|
|
{ ".NOPATH", NoPath, OP_NOPATH },
|
|
|
|
{ ".NOTMAIN", Attribute, OP_NOTMAIN },
|
|
|
|
{ ".NOTPARALLEL", NotParallel, 0 },
|
|
|
|
{ ".NO_PARALLEL", NotParallel, 0 },
|
|
|
|
{ ".NULL", Null, 0 },
|
|
|
|
{ ".OBJDIR", ExObjdir, 0 },
|
|
|
|
{ ".OPTIONAL", Attribute, OP_OPTIONAL },
|
|
|
|
{ ".ORDER", Order, 0 },
|
|
|
|
{ ".PARALLEL", Parallel, 0 },
|
|
|
|
{ ".PATH", ExPath, 0 },
|
|
|
|
{ ".PHONY", Phony, OP_PHONY },
|
2000-05-11 12:22:40 +04:00
|
|
|
#ifdef POSIX
|
2020-09-28 00:35:16 +03:00
|
|
|
{ ".POSIX", Posix, 0 },
|
2000-05-11 12:22:40 +04:00
|
|
|
#endif
|
2020-09-28 00:35:16 +03:00
|
|
|
{ ".PRECIOUS", Precious, OP_PRECIOUS },
|
|
|
|
{ ".RECURSIVE", Attribute, OP_MAKE },
|
|
|
|
{ ".SHELL", ExShell, 0 },
|
|
|
|
{ ".SILENT", Silent, OP_SILENT },
|
|
|
|
{ ".SINGLESHELL", SingleShell, 0 },
|
|
|
|
{ ".STALE", Stale, 0 },
|
|
|
|
{ ".SUFFIXES", Suffixes, 0 },
|
|
|
|
{ ".USE", Attribute, OP_USE },
|
|
|
|
{ ".USEBEFORE", Attribute, OP_USEBEFORE },
|
|
|
|
{ ".WAIT", Wait, 0 },
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* file loader */
|
2010-12-25 07:57:07 +03:00
|
|
|
|
|
|
|
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 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct loadedfile *
|
|
|
|
loadedfile_create(const char *path)
|
|
|
|
{
|
|
|
|
struct loadedfile *lf;
|
|
|
|
|
|
|
|
lf = bmake_malloc(sizeof(*lf));
|
2020-07-28 22:13:49 +03:00
|
|
|
lf->path = path == NULL ? "(stdin)" : path;
|
2010-12-25 07:57:07 +03:00
|
|
|
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.
|
|
|
|
*/
|
2020-08-29 15:20:17 +03:00
|
|
|
static Boolean
|
2010-12-25 07:57:07 +03:00
|
|
|
load_getsize(int fd, size_t *ret)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat(fd, &st) < 0) {
|
2020-08-29 15:20:17 +03:00
|
|
|
return FALSE;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISREG(st.st_mode)) {
|
2020-08-29 15:20:17 +03:00
|
|
|
return FALSE;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2020-08-29 15:20:17 +03:00
|
|
|
return FALSE;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
2020-10-22 08:50:02 +03:00
|
|
|
*ret = (size_t)st.st_size;
|
2020-08-29 15:20:17 +03:00
|
|
|
return TRUE;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2020-10-06 00:37:07 +03:00
|
|
|
static unsigned long pagesize = 0;
|
2010-12-25 07:57:07 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-08-29 15:20:17 +03:00
|
|
|
if (load_getsize(fd, &lf->len)) {
|
2010-12-25 07:57:07 +03:00
|
|
|
/* found a size, try mmap */
|
2018-02-22 04:59:28 +03:00
|
|
|
if (pagesize == 0)
|
2020-10-06 00:37:07 +03:00
|
|
|
pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
|
|
|
|
if (pagesize == 0 || pagesize == (unsigned long)-1) {
|
2010-12-25 07:57:07 +03:00
|
|
|
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') {
|
2017-04-16 23:00:58 +03:00
|
|
|
char *b = bmake_malloc(lf->len + 1);
|
2011-05-18 01:56:51 +04:00
|
|
|
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) {
|
2017-04-17 00:03:13 +03:00
|
|
|
if (lf->len > SIZE_MAX/2) {
|
|
|
|
errno = EFBIG;
|
|
|
|
Error("%s: file too large", path);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
lf->len *= 2;
|
|
|
|
lf->buf = bmake_realloc(lf->buf, lf->len);
|
|
|
|
}
|
2017-04-17 00:03:13 +03:00
|
|
|
assert(bufpos < lf->len);
|
2010-12-25 07:57:07 +03:00
|
|
|
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;
|
|
|
|
}
|
2020-10-06 00:37:07 +03:00
|
|
|
bufpos += (size_t)result;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
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) {
|
2017-03-01 19:39:49 +03:00
|
|
|
/* as for mmap case, ensure trailing \n */
|
|
|
|
if (lf->buf[lf->len - 1] != '\n')
|
|
|
|
lf->len++;
|
2010-12-25 23:46:18 +03:00
|
|
|
lf->buf = bmake_realloc(lf->buf, lf->len);
|
2017-03-01 19:39:49 +03:00
|
|
|
lf->buf[lf->len - 1] = '\n';
|
2010-12-25 23:46:18 +03:00
|
|
|
}
|
2010-12-25 07:57:07 +03:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (path != NULL) {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
return lf;
|
|
|
|
}
|
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* old code */
|
2002-01-26 23:42:14 +03:00
|
|
|
|
2020-09-05 18:05:08 +03:00
|
|
|
/* Check if the current character is escaped on the current line. */
|
|
|
|
static Boolean
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseIsEscaped(const char *line, const char *c)
|
2002-01-26 23:42:14 +03:00
|
|
|
{
|
2020-09-05 18:12:03 +03:00
|
|
|
Boolean active = FALSE;
|
2002-01-26 23:42:14 +03:00
|
|
|
for (;;) {
|
|
|
|
if (line == c)
|
|
|
|
return active;
|
|
|
|
if (*--c != '\\')
|
|
|
|
return active;
|
|
|
|
active = !active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 18:04:09 +03:00
|
|
|
/* Add the filename and lineno to the GNode so that we remember where it
|
|
|
|
* was first defined. */
|
|
|
|
static void
|
|
|
|
ParseMark(GNode *gn)
|
|
|
|
{
|
|
|
|
gn->fname = curFile->fname;
|
|
|
|
gn->lineno = curFile->lineno;
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/* Look in the table of keywords for one matching the given string.
|
|
|
|
* Return the index of the keyword, or -1 if it isn't there. */
|
1993-03-21 12:45:37 +03:00
|
|
|
static int
|
2006-11-18 01:07:39 +03:00
|
|
|
ParseFindKeyword(const char *str)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-10-17 21:36:56 +03: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;
|
2020-10-17 21:39:43 +03:00
|
|
|
end = sizeof parseKeywords / sizeof parseKeywords[0] - 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
do {
|
2020-10-17 21:39:43 +03:00
|
|
|
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) {
|
2020-07-03 11:02:55 +03:00
|
|
|
return cur;
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (diff < 0) {
|
|
|
|
end = cur - 1;
|
|
|
|
} else {
|
|
|
|
start = cur + 1;
|
|
|
|
}
|
|
|
|
} while (start <= end);
|
2020-07-03 11:02:55 +03:00
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-09-12 14:21:15 +03:00
|
|
|
static void
|
2020-09-14 00:12:08 +03:00
|
|
|
PrintLocation(FILE *f, const char *filename, size_t lineno)
|
2020-09-12 14:21:15 +03:00
|
|
|
{
|
|
|
|
char dirbuf[MAXPATHLEN+1];
|
2020-09-14 00:12:08 +03:00
|
|
|
const char *dir, *base;
|
|
|
|
char *dir_freeIt, *base_freeIt;
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2020-09-14 00:12:08 +03:00
|
|
|
if (*filename == '/' || strcmp(filename, "(stdin)") == 0) {
|
|
|
|
(void)fprintf(f, "\"%s\" line %zu: ", filename, lineno);
|
2020-09-13 16:17:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2020-09-13 16:17:44 +03:00
|
|
|
/* Find out which makefile is the culprit.
|
|
|
|
* We try ${.PARSEDIR} and apply realpath(3) if not absolute. */
|
|
|
|
|
|
|
|
dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &dir_freeIt);
|
|
|
|
if (dir == NULL)
|
|
|
|
dir = ".";
|
|
|
|
if (*dir != '/')
|
|
|
|
dir = realpath(dir, dirbuf);
|
|
|
|
|
2020-09-14 00:12:08 +03:00
|
|
|
base = Var_Value(".PARSEFILE", VAR_GLOBAL, &base_freeIt);
|
|
|
|
if (base == NULL) {
|
|
|
|
const char *slash = strrchr(filename, '/');
|
|
|
|
base = slash != NULL ? slash + 1 : filename;
|
2020-09-13 16:17:44 +03:00
|
|
|
}
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2020-09-14 00:12:08 +03:00
|
|
|
(void)fprintf(f, "\"%s/%s\" line %zu: ", dir, base, lineno);
|
|
|
|
bmake_free(base_freeIt);
|
2020-09-13 16:17:44 +03:00
|
|
|
bmake_free(dir_freeIt);
|
2020-09-12 14:21:15 +03:00
|
|
|
}
|
|
|
|
|
2020-09-13 16:22:29 +03:00
|
|
|
/* Print a parse error message, including location information.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-09-13 16:22:29 +03:00
|
|
|
* Increment "fatals" if the level is PARSE_FATAL, and continue parsing
|
|
|
|
* until the end of the current top-level makefile, then exit (see
|
2020-10-05 22:27:47 +03:00
|
|
|
* Parse_File). */
|
1998-08-06 17:42:22 +04:00
|
|
|
static void
|
2020-10-23 23:04:56 +03:00
|
|
|
ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno,
|
|
|
|
ParseErrorLevel type, 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);
|
|
|
|
|
2020-09-12 14:21:15 +03:00
|
|
|
if (cfname != NULL)
|
|
|
|
PrintLocation(f, cfname, 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);
|
2020-09-13 16:22:29 +03:00
|
|
|
|
2018-02-13 00:38:09 +03:00
|
|
|
if (type == PARSE_INFO)
|
|
|
|
return;
|
2020-10-27 00:34:10 +03:00
|
|
|
if (type == PARSE_FATAL || opts.parseWarnFatal)
|
2020-09-13 16:22:29 +03:00
|
|
|
fatals++;
|
2020-10-27 00:34:10 +03:00
|
|
|
if (opts.parseWarnFatal && !fatal_warning_error_printed) {
|
2001-01-10 18:54:00 +03:00
|
|
|
Error("parsing warnings being treated as errors");
|
|
|
|
fatal_warning_error_printed = TRUE;
|
|
|
|
}
|
1998-08-06 17:42:22 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 00:55:34 +04:00
|
|
|
static void
|
2020-10-23 23:04:56 +03:00
|
|
|
ParseErrorInternal(const char *cfname, size_t clineno, ParseErrorLevel type,
|
2020-10-17 21:36:56 +03:00
|
|
|
const char *fmt, ...)
|
2014-09-08 00:55:34 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
(void)fflush(stdout);
|
|
|
|
ParseVErrorInternal(stderr, cfname, clineno, type, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2020-10-27 00:34:10 +03:00
|
|
|
if (opts.debug_file != stderr && opts.debug_file != stdout) {
|
2014-09-08 00:55:34 +04:00
|
|
|
va_start(ap, fmt);
|
2020-10-27 00:34:10 +03:00
|
|
|
ParseVErrorInternal(opts.debug_file, cfname, clineno, type,
|
|
|
|
fmt, ap);
|
2014-09-08 00:55:34 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-08 08:26:21 +03:00
|
|
|
/* External interface to ParseErrorInternal; uses the default filename and
|
|
|
|
* line number.
|
1998-08-06 17:42:22 +04:00
|
|
|
*
|
2020-09-08 08:26:21 +03:00
|
|
|
* Fmt is given without a trailing newline. */
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
2020-10-23 23:04:56 +03:00
|
|
|
Parse_Error(ParseErrorLevel 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;
|
2020-10-06 00:37:07 +03:00
|
|
|
lineno = (size_t)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
|
|
|
|
2020-10-27 00:34:10 +03:00
|
|
|
if (opts.debug_file != stderr && opts.debug_file != stdout) {
|
2007-01-02 00:47:32 +03:00
|
|
|
va_start(ap, fmt);
|
2020-10-27 00:34:10 +03:00
|
|
|
ParseVErrorInternal(opts.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
|
|
|
|
2020-09-13 16:25:07 +03:00
|
|
|
/* Parse a .info .warning or .error directive.
|
2010-04-07 04:11:27 +04:00
|
|
|
*
|
2020-09-13 16:25:07 +03:00
|
|
|
* 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-04-07 04:11:27 +04:00
|
|
|
*/
|
2010-05-25 01:04:49 +04:00
|
|
|
static Boolean
|
2020-10-17 22:10:07 +03:00
|
|
|
ParseMessage(const char *directive)
|
2010-04-07 04:11:27 +04:00
|
|
|
{
|
2020-10-17 22:10:07 +03:00
|
|
|
const char *p = directive;
|
|
|
|
int mtype = *p == 'i' ? PARSE_INFO :
|
|
|
|
*p == 'w' ? PARSE_WARNING : PARSE_FATAL;
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
while (ch_isalpha(*p))
|
|
|
|
p++;
|
|
|
|
if (!ch_isspace(*p))
|
|
|
|
return FALSE; /* missing argument */
|
|
|
|
|
|
|
|
cpp_skip_whitespace(&p);
|
|
|
|
(void)Var_Subst(p, VAR_CMD, VARE_WANTRES, &arg);
|
2020-09-22 23:19:46 +03:00
|
|
|
/* TODO: handle errors */
|
2020-10-17 22:10:07 +03:00
|
|
|
|
|
|
|
Parse_Error(mtype, "%s", arg);
|
|
|
|
free(arg);
|
2010-04-07 04:11:27 +04:00
|
|
|
|
|
|
|
if (mtype == PARSE_FATAL) {
|
2020-09-28 04:24:34 +03:00
|
|
|
PrintOnError(NULL, NULL);
|
2010-04-07 04:11:27 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2010-05-25 01:04:49 +04:00
|
|
|
return TRUE;
|
2010-04-07 04:11:27 +04:00
|
|
|
}
|
|
|
|
|
2020-09-14 20:44:57 +03:00
|
|
|
/* Add the child to the parent's children.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-18 00:21:37 +03:00
|
|
|
* Additionally, add the parent to the child's parents, but only if the
|
|
|
|
* target is not special. An example for such a special target is .END,
|
|
|
|
* which does not need to be informed once the child target has been made. */
|
2020-09-26 03:03:29 +03:00
|
|
|
static void
|
2020-10-18 00:21:37 +03:00
|
|
|
LinkSource(GNode *pgn, GNode *cgn, Boolean isSpecial)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-08-28 07:48:56 +03:00
|
|
|
if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts))
|
2020-10-20 00:57:37 +03:00
|
|
|
pgn = pgn->cohorts->last->datum;
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(pgn->children, cgn);
|
2020-09-29 02:13:57 +03:00
|
|
|
pgn->unmade++;
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2020-10-18 00:21:37 +03:00
|
|
|
/* Special targets like .END don't need any children. */
|
|
|
|
if (!isSpecial)
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(cgn->parents, pgn);
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2006-02-11 23:59:49 +03:00
|
|
|
if (DEBUG(PARSE)) {
|
2020-09-29 01:23:35 +03:00
|
|
|
debug_printf("# %s: added child %s - %s\n",
|
|
|
|
__func__, 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
|
|
|
}
|
|
|
|
|
2020-10-18 00:21:37 +03:00
|
|
|
/* Add the node to each target from the current dependency group. */
|
|
|
|
static void
|
|
|
|
LinkToTargets(GNode *gn, Boolean isSpecial)
|
|
|
|
{
|
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next)
|
|
|
|
LinkSource(ln->datum, gn, isSpecial);
|
|
|
|
}
|
|
|
|
|
2020-09-27 15:42:09 +03:00
|
|
|
static Boolean
|
|
|
|
TryApplyDependencyOperator(GNode *gn, GNodeType op)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
/*
|
2020-10-23 21:36:09 +03:00
|
|
|
* If the node occurred on the left-hand side of a dependency and the
|
|
|
|
* operator also defines a dependency, they must match.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-23 21:36:09 +03:00
|
|
|
if ((op & OP_OPMASK) && (gn->type & OP_OPMASK) &&
|
|
|
|
((op & OP_OPMASK) != (gn->type & OP_OPMASK)))
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Inconsistent operator for %s", gn->name);
|
2020-09-27 15:42:09 +03:00
|
|
|
return FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-07-28 22:13:49 +03:00
|
|
|
if (op == OP_DOUBLEDEP && (gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-10-17 21:36:56 +03: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
|
|
|
|
2020-09-26 19:00:12 +03:00
|
|
|
cohort = Targ_NewInternalNode(gn->name);
|
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;
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(gn->cohorts, cohort);
|
2002-03-20 21:10:30 +03:00
|
|
|
cohort->centurion = gn;
|
2020-09-29 02:13:57 +03:00
|
|
|
gn->unmade_cohorts++;
|
2006-11-18 01:07:39 +03:00
|
|
|
snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
|
2020-10-18 22:11:35 +03:00
|
|
|
(unsigned int)gn->unmade_cohorts % 1000000);
|
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
|
|
|
|
2020-09-27 15:42:09 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ApplyDependencyOperator(GNodeType op)
|
|
|
|
{
|
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next)
|
2020-10-17 20:47:14 +03:00
|
|
|
if (!TryApplyDependencyOperator(ln->datum, op))
|
2020-09-27 15:42:09 +03:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static Boolean
|
|
|
|
ParseDoSrcKeyword(const char *src, ParseSpecial specType)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2006-11-18 01:07:39 +03:00
|
|
|
static int wait_number = 0;
|
|
|
|
char wait_src[16];
|
2020-10-05 22:27:47 +03:00
|
|
|
GNode *gn;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-09-11 20:32:36 +03:00
|
|
|
if (*src == '.' && ch_isupper(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) {
|
2020-09-27 15:42:09 +03:00
|
|
|
ApplyDependencyOperator(op);
|
2020-10-05 22:27:47 +03:00
|
|
|
return TRUE;
|
1995-12-16 08:03:09 +03:00
|
|
|
}
|
|
|
|
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);
|
2020-09-26 19:00:12 +03:00
|
|
|
gn = Targ_NewInternalNode(wait_src);
|
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;
|
2020-10-18 00:21:37 +03:00
|
|
|
LinkToTargets(gn, specType != Not);
|
2020-10-05 22:27:47 +03:00
|
|
|
return TRUE;
|
1995-12-16 08:03:09 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
|
|
|
ParseDoSrcMain(const char *src)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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...
|
|
|
|
*/
|
2020-10-27 00:34:10 +03:00
|
|
|
Lst_Append(opts.create, bmake_strdup(src));
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
|
|
|
* Add the name to the .TARGETS variable as well, so the user can
|
|
|
|
* employ that, if desired.
|
|
|
|
*/
|
|
|
|
Var_Append(".TARGETS", src, VAR_GLOBAL);
|
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
|
|
|
ParseDoSrcOrder(const char *src)
|
|
|
|
{
|
|
|
|
GNode *gn;
|
|
|
|
/*
|
|
|
|
* Create proper predecessor/successor links between the previous
|
|
|
|
* source and the current one.
|
|
|
|
*/
|
|
|
|
gn = Targ_GetNode(src);
|
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
|
|
|
if (predecessor != NULL) {
|
|
|
|
Lst_Append(predecessor->order_succ, gn);
|
|
|
|
Lst_Append(gn->order_pred, predecessor);
|
|
|
|
if (DEBUG(PARSE)) {
|
|
|
|
debug_printf("# %s: added Order dependency %s - %s\n",
|
|
|
|
__func__, predecessor->name, gn->name);
|
|
|
|
Targ_PrintNode(predecessor, 0);
|
|
|
|
Targ_PrintNode(gn, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The current source now becomes the predecessor for the next one.
|
|
|
|
*/
|
|
|
|
predecessor = gn;
|
|
|
|
}
|
2006-10-16 01:17:27 +04:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
|
|
|
ParseDoSrcOther(const char *src, GNodeType tOp, ParseSpecial specType)
|
|
|
|
{
|
|
|
|
GNode *gn;
|
2020-10-05 18:43:32 +03:00
|
|
|
|
2020-10-05 22:27:47 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find/create the 'src' node and attach to all targets */
|
|
|
|
gn = Targ_GetNode(src);
|
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
|
|
|
if (tOp) {
|
|
|
|
gn->type |= tOp;
|
|
|
|
} else {
|
2020-10-18 00:21:37 +03:00
|
|
|
LinkToTargets(gn, specType != Not);
|
1995-12-16 08:03:09 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/* Given the name of a source in a dependency line, figure out if it is an
|
|
|
|
* attribute (such as .SILENT) 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 (such as .PHONY) and apply it if so.
|
|
|
|
* Otherwise, make the source a child of the targets in the list 'targets'.
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* tOp operator (if any) from special targets
|
|
|
|
* src name of the source to handle
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ParseDoSrc(GNodeType tOp, const char *src, ParseSpecial specType)
|
|
|
|
{
|
|
|
|
if (ParseDoSrcKeyword(src, specType))
|
2020-10-17 20:47:14 +03:00
|
|
|
return;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
if (specType == Main)
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoSrcMain(src);
|
2020-10-05 22:27:47 +03:00
|
|
|
else if (specType == Order)
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoSrcOrder(src);
|
2020-10-05 22:27:47 +03:00
|
|
|
else
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoSrcOther(src, tOp, specType);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2020-09-27 15:05:04 +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. */
|
|
|
|
static void
|
|
|
|
FindMainTarget(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-09-27 15:05:04 +03:00
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
if (mainNode != NULL)
|
2020-10-17 20:47:14 +03:00
|
|
|
return;
|
2020-09-27 15:05:04 +03:00
|
|
|
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
if (!(gn->type & OP_NOTARGET)) {
|
|
|
|
mainNode = gn;
|
|
|
|
Targ_SetMain(gn);
|
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:23:32 +03:00
|
|
|
/*
|
|
|
|
* We got to the end of the line while we were still looking at targets.
|
|
|
|
*
|
|
|
|
* Ending a dependency line without an operator is a Bozo no-no. As a
|
|
|
|
* heuristic, this is also often triggered by undetected conflicts from
|
|
|
|
* cvs/rcs merges.
|
|
|
|
*/
|
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseErrorNoDependency(const char *lstart)
|
2020-09-14 19:23:32 +03:00
|
|
|
{
|
2020-10-21 01:50:55 +03:00
|
|
|
if ((strncmp(lstart, "<<<<<<", 6) == 0) ||
|
|
|
|
(strncmp(lstart, "======", 6) == 0) ||
|
|
|
|
(strncmp(lstart, ">>>>>>", 6) == 0))
|
2020-09-14 19:23:32 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
|
|
|
|
else if (lstart[0] == '.') {
|
|
|
|
const char *dirstart = lstart + 1;
|
|
|
|
const char *dirend;
|
2020-10-05 22:27:47 +03:00
|
|
|
cpp_skip_whitespace(&dirstart);
|
2020-09-14 19:23:32 +03:00
|
|
|
dirend = dirstart;
|
|
|
|
while (ch_isalnum(*dirend) || *dirend == '-')
|
|
|
|
dirend++;
|
|
|
|
Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"",
|
|
|
|
(int)(dirend - dirstart), dirstart);
|
|
|
|
} else
|
|
|
|
Parse_Error(PARSE_FATAL, "Need an operator");
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:40:06 +03:00
|
|
|
static void
|
|
|
|
ParseDependencyTargetWord(/*const*/ char **pp, const char *lstart)
|
|
|
|
{
|
|
|
|
/*const*/ char *cp = *pp;
|
|
|
|
|
|
|
|
while (*cp != '\0') {
|
|
|
|
if ((ch_isspace(*cp) || *cp == '!' || *cp == ':' || *cp == '(') &&
|
|
|
|
!ParseIsEscaped(lstart, cp))
|
|
|
|
break;
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
const char *nested_p = cp;
|
|
|
|
const char *nested_val;
|
2020-10-17 21:36:56 +03:00
|
|
|
void *freeIt;
|
2020-09-14 19:40:06 +03:00
|
|
|
|
|
|
|
(void)Var_Parse(&nested_p, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES,
|
|
|
|
&nested_val, &freeIt);
|
|
|
|
/* TODO: handle errors */
|
|
|
|
free(freeIt);
|
|
|
|
cp += nested_p - cp;
|
|
|
|
} else
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pp = cp;
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
* .PHONY The list of targets
|
|
|
|
* .NOPATH Don't search for file in the path
|
|
|
|
* .STALE
|
|
|
|
* .BEGIN
|
|
|
|
* .END
|
|
|
|
* .ERROR
|
|
|
|
* .DELETE_ON_ERROR
|
|
|
|
* .INTERRUPT Are not to be considered the
|
|
|
|
* main target.
|
|
|
|
* .NOTPARALLEL Make only one target at a time.
|
|
|
|
* .SINGLESHELL Create a shell for each command.
|
|
|
|
* .ORDER Must set initial predecessor to NULL
|
2020-10-05 19:33:20 +03:00
|
|
|
*/
|
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyTargetSpecial(ParseSpecial *inout_specType,
|
|
|
|
const char *line,
|
|
|
|
SearchPathList **inout_paths)
|
2020-10-05 19:33:20 +03:00
|
|
|
{
|
2020-10-05 22:27:47 +03:00
|
|
|
switch (*inout_specType) {
|
|
|
|
case ExPath:
|
|
|
|
if (*inout_paths == NULL) {
|
2020-10-18 16:02:10 +03:00
|
|
|
*inout_paths = Lst_New();
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
Lst_Append(*inout_paths, dirSearchPath);
|
|
|
|
break;
|
|
|
|
case Main:
|
2020-10-27 00:34:10 +03:00
|
|
|
if (!Lst_IsEmpty(opts.create)) {
|
2020-10-05 22:27:47 +03:00
|
|
|
*inout_specType = Not;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case Stale:
|
|
|
|
case dotError:
|
|
|
|
case Interrupt: {
|
|
|
|
GNode *gn = Targ_GetNode(line);
|
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
|
|
|
gn->type |= OP_NOTMAIN|OP_SPECIAL;
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Default: {
|
|
|
|
GNode *gn = Targ_NewGN(".DEFAULT");
|
|
|
|
gn->type |= OP_NOTMAIN|OP_TRANSFORM;
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
DEFAULT = gn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DeleteOnError:
|
|
|
|
deleteOnError = TRUE;
|
|
|
|
break;
|
|
|
|
case NotParallel:
|
2020-10-27 00:34:10 +03:00
|
|
|
opts.maxJobs = 1;
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case SingleShell:
|
2020-10-27 00:34:10 +03:00
|
|
|
opts.compatMake = TRUE;
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case Order:
|
|
|
|
predecessor = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
|
|
|
* .PATH<suffix> has to be handled specially.
|
|
|
|
* Call on the suffix module to give us a path to modify.
|
|
|
|
*/
|
|
|
|
static Boolean
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyTargetPath(const char *line, SearchPathList **inout_paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
SearchPath *path;
|
|
|
|
|
|
|
|
path = Suff_GetPath(&line[5]);
|
|
|
|
if (path == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Suffix '%s' not defined (yet)",
|
|
|
|
&line[5]);
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
if (*inout_paths == NULL) {
|
2020-10-18 16:02:10 +03:00
|
|
|
*inout_paths = Lst_New();
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
Lst_Append(*inout_paths, path);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if it's a special target and if so set specType to match it.
|
|
|
|
*/
|
|
|
|
static Boolean
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyTarget(const char *line, ParseSpecial *inout_specType,
|
|
|
|
GNodeType *out_tOp, SearchPathList **inout_paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
int keywd;
|
|
|
|
|
|
|
|
if (!(*line == '.' && ch_isupper(line[1])))
|
|
|
|
return TRUE;
|
2020-10-05 19:33:20 +03:00
|
|
|
|
|
|
|
/*
|
2020-10-05 22:27:47 +03:00
|
|
|
* See if the target is a special target that must have it
|
|
|
|
* or its sources handled specially.
|
2020-10-05 19:33:20 +03:00
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
keywd = ParseFindKeyword(line);
|
|
|
|
if (keywd != -1) {
|
|
|
|
if (*inout_specType == ExPath && parseKeywords[keywd].spec != ExPath) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Mismatched special targets");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
*inout_specType = parseKeywords[keywd].spec;
|
|
|
|
*out_tOp = parseKeywords[keywd].op;
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
ParseDoDependencyTargetSpecial(inout_specType, line, inout_paths);
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
} else if (strncmp(line, ".PATH", 5) == 0) {
|
|
|
|
*inout_specType = ExPath;
|
|
|
|
if (!ParseDoDependencyTargetPath(line, inout_paths))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyTargetMundane(char *line, StringList *curTargs)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
if (Dir_HasWildcards(line)) {
|
|
|
|
/*
|
|
|
|
* Targets are to be sought only in the current directory,
|
|
|
|
* so create an empty path for the thing. Note we need to
|
|
|
|
* use Dir_Destroy in the destruction of the path as the
|
|
|
|
* Dir module could have added a directory to the path...
|
|
|
|
*/
|
2020-10-18 16:02:10 +03:00
|
|
|
SearchPath *emptyPath = Lst_New();
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
Dir_Expand(line, emptyPath, curTargs);
|
|
|
|
|
|
|
|
Lst_Destroy(emptyPath, Dir_Destroy);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* No wildcards, but we want to avoid code duplication,
|
|
|
|
* so create a list with the word on it.
|
|
|
|
*/
|
|
|
|
Lst_Append(curTargs, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply the targets. */
|
|
|
|
|
2020-10-17 21:36:56 +03:00
|
|
|
while (!Lst_IsEmpty(curTargs)) {
|
2020-10-05 22:27:47 +03:00
|
|
|
char *targName = Lst_Dequeue(curTargs);
|
|
|
|
GNode *gn = Suff_IsTransform(targName)
|
|
|
|
? Suff_AddTransform(targName)
|
|
|
|
: Targ_GetNode(targName);
|
|
|
|
if (doing_depend)
|
|
|
|
ParseMark(gn);
|
|
|
|
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ParseDoDependencyTargetExtraWarn(char **pp, const char *lstart)
|
|
|
|
{
|
|
|
|
Boolean warning = FALSE;
|
|
|
|
char *cp = *pp;
|
|
|
|
|
|
|
|
while (*cp && (ParseIsEscaped(lstart, cp) ||
|
|
|
|
(*cp != '!' && *cp != ':'))) {
|
|
|
|
if (ParseIsEscaped(lstart, cp) ||
|
|
|
|
(*cp != ' ' && *cp != '\t')) {
|
|
|
|
warning = TRUE;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (warning) {
|
|
|
|
Parse_Error(PARSE_WARNING, "Extra target ignored");
|
|
|
|
}
|
|
|
|
*pp = cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyCheckSpec(ParseSpecial specType)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-10-17 21:36:56 +03:00
|
|
|
switch (specType) {
|
2020-10-05 22:27:47 +03:00
|
|
|
default:
|
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"Special and mundane targets don't mix. Mundane ones ignored");
|
|
|
|
break;
|
|
|
|
case Default:
|
|
|
|
case Stale:
|
|
|
|
case Begin:
|
|
|
|
case End:
|
|
|
|
case dotError:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyParseOp(char **pp, const char *lstart, GNodeType *out_op)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
const char *cp = *pp;
|
|
|
|
|
|
|
|
if (*cp == '!') {
|
|
|
|
*out_op = OP_FORCE;
|
|
|
|
(*pp)++;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*cp == ':') {
|
|
|
|
if (cp[1] == ':') {
|
|
|
|
*out_op = OP_DOUBLEDEP;
|
|
|
|
(*pp) += 2;
|
|
|
|
} else {
|
|
|
|
*out_op = OP_DEPENDS;
|
|
|
|
(*pp)++;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const char *msg = lstart[0] == '.' ? "Unknown directive"
|
|
|
|
: "Missing dependency operator";
|
|
|
|
Parse_Error(PARSE_FATAL, "%s", msg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 23:51:18 +03:00
|
|
|
static void
|
|
|
|
ClearPaths(SearchPathList *paths)
|
|
|
|
{
|
|
|
|
if (paths != NULL) {
|
|
|
|
SearchPathListNode *ln;
|
|
|
|
for (ln = paths->first; ln != NULL; ln = ln->next)
|
|
|
|
Dir_ClearPath(ln->datum);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dir_SetPATH();
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencySourcesEmpty(ParseSpecial specType, SearchPathList *paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
switch (specType) {
|
|
|
|
case Suffixes:
|
|
|
|
Suff_ClearSuffixes();
|
|
|
|
break;
|
|
|
|
case Precious:
|
|
|
|
allPrecious = TRUE;
|
|
|
|
break;
|
|
|
|
case Ignore:
|
2020-10-27 00:34:10 +03:00
|
|
|
opts.ignoreErrors = TRUE;
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case Silent:
|
2020-10-27 00:34:10 +03:00
|
|
|
opts.beSilent = TRUE;
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case ExPath:
|
2020-10-19 23:51:18 +03:00
|
|
|
ClearPaths(paths);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
#ifdef POSIX
|
|
|
|
case Posix:
|
|
|
|
Var_Set("%POSIX", "1003.2", VAR_GLOBAL);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 23:55:30 +03:00
|
|
|
static void
|
|
|
|
AddToPaths(const char *dir, SearchPathList *paths)
|
|
|
|
{
|
|
|
|
if (paths != NULL) {
|
|
|
|
SearchPathListNode *ln;
|
|
|
|
for (ln = paths->first; ln != NULL; ln = ln->next)
|
|
|
|
(void)Dir_AddDir(ln->datum, dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* If it was .OBJDIR, the source is a new definition for .OBJDIR,
|
|
|
|
* and will cause make to do a new chdir to that path.
|
|
|
|
*/
|
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencySourceSpecial(ParseSpecial specType, char *word,
|
|
|
|
SearchPathList *paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
switch (specType) {
|
|
|
|
case Suffixes:
|
2020-10-21 01:50:55 +03:00
|
|
|
Suff_AddSuffix(word, &mainNode);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case ExPath:
|
2020-10-21 01:50:55 +03:00
|
|
|
AddToPaths(word, paths);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case Includes:
|
2020-10-21 01:50:55 +03:00
|
|
|
Suff_AddInclude(word);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case Libs:
|
2020-10-21 01:50:55 +03:00
|
|
|
Suff_AddLib(word);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case Null:
|
2020-10-21 01:50:55 +03:00
|
|
|
Suff_SetNull(word);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
case ExObjdir:
|
2020-10-21 01:50:55 +03:00
|
|
|
Main_SetObjdir("%s", word);
|
2020-10-05 22:27:47 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencyTargets(char **inout_cp,
|
|
|
|
char **inout_line,
|
|
|
|
const char *lstart,
|
|
|
|
ParseSpecial *inout_specType,
|
|
|
|
GNodeType *inout_tOp,
|
|
|
|
SearchPathList **inout_paths,
|
|
|
|
StringList *curTargs)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
char *cp = *inout_cp;
|
|
|
|
char *line = *inout_line;
|
|
|
|
char savec;
|
2014-09-18 12:06:13 +04:00
|
|
|
|
2020-09-27 15:26:23 +03:00
|
|
|
for (;;) {
|
2014-09-18 12:06:13 +04:00
|
|
|
/*
|
|
|
|
* Here LINE points to the beginning of the next word, and
|
|
|
|
* LSTART points to the actual beginning of the line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Find the end of the next word. */
|
2020-09-14 19:40:06 +03:00
|
|
|
cp = line;
|
|
|
|
ParseDependencyTargetWord(&cp, lstart);
|
2006-12-03 23:40:44 +03:00
|
|
|
|
2014-09-18 12:06:13 +04:00
|
|
|
/*
|
|
|
|
* If the word is followed by a left parenthesis, it's the
|
|
|
|
* name of an object file inside an archive (ar file).
|
|
|
|
*/
|
2020-09-14 19:16:52 +03:00
|
|
|
if (!ParseIsEscaped(lstart, cp) && *cp == '(') {
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
2014-09-08 00:55:34 +04: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
|
2020-08-29 15:20:17 +03:00
|
|
|
* and places them on the given list, returning TRUE if all
|
|
|
|
* went well and FALSE if there was an error in the
|
2014-09-08 00:55:34 +04:00
|
|
|
* specification. On error, line should remain untouched.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-08-27 09:13:53 +03:00
|
|
|
if (!Arch_ParseArchive(&line, targets, VAR_CMD)) {
|
2005-02-16 18:11:52 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-10-05 22:27:47 +03:00
|
|
|
"Error in archive specification: \"%s\"", line);
|
|
|
|
return FALSE;
|
2014-09-08 00:55:34 +04:00
|
|
|
} else {
|
2014-09-18 12:06:13 +04:00
|
|
|
/* Done with this word; on to the next. */
|
2016-03-11 16:54:47 +03:00
|
|
|
cp = line;
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
2014-09-08 00:55:34 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!*cp) {
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseErrorNoDependency(lstart);
|
2020-10-05 22:27:47 +03:00
|
|
|
return FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2014-09-18 12:06:13 +04:00
|
|
|
|
|
|
|
/* Insert a null terminator. */
|
|
|
|
savec = *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = '\0';
|
2006-10-16 01:17:27 +04:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
if (!ParseDoDependencyTarget(line, inout_specType, inout_tOp,
|
|
|
|
inout_paths))
|
|
|
|
return FALSE;
|
2020-10-05 19:54:41 +03:00
|
|
|
|
|
|
|
/*
|
make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)
The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.
Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.
With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.
Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
2020-10-05 22:24:29 +03:00
|
|
|
* Have word in line. Get or create its node and stick it at
|
|
|
|
* the end of the targets list
|
2020-10-05 19:54:41 +03:00
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
if (*inout_specType == Not && *line != '\0') {
|
|
|
|
ParseDoDependencyTargetMundane(line, curTargs);
|
|
|
|
} else if (*inout_specType == ExPath && *line != '.' && *line != '\0') {
|
make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)
The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.
Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.
With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.
Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
2020-10-05 22:24:29 +03:00
|
|
|
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line);
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
|
|
|
|
make(1): fix double-free bug in -DCLEANUP mode (since 2020-10-02)
The bug had been introduced with dir.c 1.155 on 2020-10-02 22:20:25. In
that commit, openDirectories was replaced with a combination of a list
with a hash table, for more efficient lookup by name.
Upon cleanup, OpenDirs_Done is called, which in turn called
Dir_ClearPath. Dir_ClearPath takes full ownership of the given list and
empties it. This was no problem before since afterwards the list was
empty and calling Lst_Free just frees the remaining list pointer.
With OpenDirs, this list was combined with a hash table, and the hash
table contains the list nodes, assuming that the OpenDirs functions have
full ownership of both the list and the hash table. This assumption was
generally correct, except for the one moment during cleanup where full
ownership of the list was passed to Dir_ClearPath, while the hash table
still contained pointers to the (now freed) list nodes. This by itself
was not a problem since the hash table would be freed afterwards. But
as part of Dir_ClearPath, OpenDirs_Remove was called, which looked up
the freed directory by name and now found the freed list node, trying to
free it again. Boom.
Fixed by replacing the call to Dir_ClearPath with code that only frees
the directories, without giving up control over the list.
2020-10-05 22:24:29 +03:00
|
|
|
/* Don't need the inserted null terminator any more. */
|
|
|
|
*cp = savec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it is a special type and not .PATH, it's the only target we
|
|
|
|
* allow on this line...
|
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
if (*inout_specType != Not && *inout_specType != ExPath) {
|
|
|
|
ParseDoDependencyTargetExtraWarn(&cp, lstart);
|
|
|
|
} else {
|
|
|
|
pp_skip_whitespace(&cp);
|
|
|
|
}
|
|
|
|
line = cp;
|
|
|
|
if (*line == '\0')
|
|
|
|
break;
|
|
|
|
if ((*line == '!' || *line == ':') && !ParseIsEscaped(lstart, line))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*inout_cp = cp;
|
|
|
|
*inout_line = line;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencySourcesSpecial(char *start, char *end,
|
2020-10-05 22:27:47 +03:00
|
|
|
ParseSpecial specType, SearchPathList *paths)
|
|
|
|
{
|
|
|
|
char savec;
|
|
|
|
|
2020-10-21 01:50:55 +03:00
|
|
|
while (*start) {
|
|
|
|
while (*end && !ch_isspace(*end))
|
|
|
|
end++;
|
|
|
|
savec = *end;
|
|
|
|
*end = '\0';
|
|
|
|
ParseDoDependencySourceSpecial(specType, start, paths);
|
|
|
|
*end = savec;
|
|
|
|
if (savec != '\0')
|
|
|
|
end++;
|
|
|
|
pp_skip_whitespace(&end);
|
|
|
|
start = end;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoDependencySourcesMundane(char *start, char *end,
|
2020-10-17 21:36:56 +03:00
|
|
|
ParseSpecial specType, GNodeType tOp)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-10-21 01:50:55 +03:00
|
|
|
while (*start) {
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
|
|
|
* The targets take real sources, so we must beware of archive
|
|
|
|
* specifications (i.e. things with left parentheses in them)
|
|
|
|
* and handle them accordingly.
|
|
|
|
*/
|
2020-10-21 01:50:55 +03:00
|
|
|
for (; *end && !ch_isspace(*end); end++) {
|
|
|
|
if (*end == '(' && end > start && end[-1] != '$') {
|
2020-10-05 22:27:47 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:50:55 +03:00
|
|
|
if (*end == '(') {
|
2020-10-18 16:02:10 +03:00
|
|
|
GNodeList *sources = Lst_New();
|
2020-10-21 01:50:55 +03:00
|
|
|
if (!Arch_ParseArchive(&start, sources, VAR_CMD)) {
|
2020-10-05 22:27:47 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-10-21 01:50:55 +03:00
|
|
|
"Error in source archive spec \"%s\"", start);
|
2020-10-05 22:27:47 +03:00
|
|
|
return FALSE;
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
while (!Lst_IsEmpty(sources)) {
|
|
|
|
GNode *gn = Lst_Dequeue(sources);
|
|
|
|
ParseDoSrc(tOp, gn->name, specType);
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
Lst_Free(sources);
|
2020-10-21 01:50:55 +03:00
|
|
|
end = start;
|
2020-10-05 19:54:41 +03:00
|
|
|
} else {
|
2020-10-21 01:50:55 +03:00
|
|
|
if (*end) {
|
|
|
|
*end = '\0';
|
|
|
|
end++;
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2020-10-21 01:50:55 +03:00
|
|
|
ParseDoSrc(tOp, start, specType);
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2020-10-21 01:50:55 +03:00
|
|
|
pp_skip_whitespace(&end);
|
|
|
|
start = end;
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse a dependency line consisting of targets, followed by a dependency
|
|
|
|
* operator, optionally followed by sources.
|
|
|
|
*
|
|
|
|
* The nodes of the sources are linked as children to the nodes of the
|
|
|
|
* targets. Nodes are created as necessary.
|
|
|
|
*
|
|
|
|
* The operator is applied to each node in the global 'targets' list,
|
|
|
|
* which is where the nodes found for the targets are kept, by means of
|
|
|
|
* the ParseDoOp function.
|
|
|
|
*
|
|
|
|
* The sources are parsed in much the same way as the targets, except
|
|
|
|
* that 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 and sources such as .PHONY or .PRECIOUS are handled
|
|
|
|
* specially. These are the ones detailed by the specType variable.
|
|
|
|
*
|
|
|
|
* The storing of transformation rules such as '.c.o' 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
|
|
|
|
ParseDoDependency(char *line)
|
|
|
|
{
|
|
|
|
char *cp; /* our current position */
|
|
|
|
GNodeType op; /* the operator on the line */
|
|
|
|
SearchPathList *paths; /* search paths to alter when parsing
|
|
|
|
* a list of .PATH targets */
|
|
|
|
int tOp; /* operator from special target */
|
|
|
|
StringList *curTargs; /* target names to be found and added
|
|
|
|
* to the targets list */
|
2020-10-17 21:36:56 +03:00
|
|
|
char *lstart = line;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* specType contains the SPECial TYPE of the current target. It is Not
|
|
|
|
* if the target is unspecial. If it *is* special, however, the children
|
|
|
|
* are linked as children of the parent but not vice versa.
|
|
|
|
*/
|
|
|
|
ParseSpecial specType = Not;
|
|
|
|
|
|
|
|
DEBUG1(PARSE, "ParseDoDependency(%s)\n", line);
|
|
|
|
tOp = 0;
|
|
|
|
|
|
|
|
paths = NULL;
|
|
|
|
|
2020-10-18 16:02:10 +03:00
|
|
|
curTargs = Lst_New();
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First, grind through the targets.
|
|
|
|
*/
|
|
|
|
if (!ParseDoDependencyTargets(&cp, &line, lstart, &specType, &tOp, &paths,
|
|
|
|
curTargs))
|
|
|
|
goto out;
|
2020-10-05 19:45:03 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Don't need the list of target names anymore...
|
|
|
|
*/
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Free(curTargs);
|
2006-04-01 00:30:46 +04:00
|
|
|
curTargs = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
if (!Lst_IsEmpty(targets))
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoDependencyCheckSpec(specType);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
2020-10-05 22:27:47 +03:00
|
|
|
* Have now parsed all the target names. Must parse the operator next.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
if (!ParseDoDependencyParseOp(&cp, lstart, &op))
|
2020-10-17 20:47:14 +03:00
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2014-09-18 12:06:13 +04:00
|
|
|
/*
|
|
|
|
* Apply the operator to the target. This is how we remember which
|
|
|
|
* operator a target was defined with. It fails if the operator
|
|
|
|
* used isn't consistent across all references.
|
|
|
|
*/
|
2020-09-27 15:42:09 +03:00
|
|
|
ApplyDependencyOperator(op);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
2014-09-18 12:06:13 +04:00
|
|
|
* Onward to the sources.
|
|
|
|
*
|
|
|
|
* LINE will now point to the first source word, if any, or the
|
|
|
|
* end of the string if not.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
pp_skip_whitespace(&cp);
|
1993-03-21 12:45:37 +03:00
|
|
|
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) {
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoDependencySourcesEmpty(specType, paths);
|
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) {
|
2020-08-29 15:20:17 +03:00
|
|
|
if (!Job_ParseShell(line)) {
|
2005-02-16 18:11:52 +03:00
|
|
|
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';
|
2020-07-28 22:13:49 +03:00
|
|
|
} else if (specType == NotParallel || specType == SingleShell ||
|
2020-10-17 21:36:56 +03:00
|
|
|
specType == DeleteOnError) {
|
1993-03-21 12:45:37 +03:00
|
|
|
*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
|
|
|
*/
|
2020-07-28 22:13:49 +03:00
|
|
|
if (specType == Suffixes || specType == ExPath ||
|
|
|
|
specType == Includes || specType == Libs ||
|
|
|
|
specType == Null || specType == ExObjdir)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-10-17 20:47:14 +03:00
|
|
|
ParseDoDependencySourcesSpecial(line, cp, specType, paths);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (paths) {
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Free(paths);
|
2017-04-17 00:35:08 +03:00
|
|
|
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 {
|
2017-04-17 00:35:08 +03:00
|
|
|
assert(paths == NULL);
|
2020-10-17 20:47:14 +03:00
|
|
|
if (!ParseDoDependencySourcesMundane(line, cp, specType, tOp))
|
|
|
|
goto out;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2020-09-27 15:05:04 +03:00
|
|
|
FindMainTarget();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2006-04-01 00:30:46 +04:00
|
|
|
out:
|
2020-08-27 01:55:46 +03:00
|
|
|
if (paths != NULL)
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Free(paths);
|
2020-08-27 01:55:46 +03:00
|
|
|
if (curTargs != NULL)
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Free(curTargs);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 23:14:27 +03:00
|
|
|
typedef struct VarAssignParsed {
|
|
|
|
const char *nameStart; /* unexpanded */
|
|
|
|
const char *nameEnd; /* before operator adjustment */
|
|
|
|
const char *eq; /* the '=' of the assignment operator */
|
|
|
|
} VarAssignParsed;
|
|
|
|
|
2020-10-18 23:07:26 +03:00
|
|
|
/* Determine the assignment operator and adjust the end of the variable
|
|
|
|
* name accordingly. */
|
|
|
|
static void
|
2020-10-18 23:14:27 +03:00
|
|
|
AdjustVarassignOp(const VarAssignParsed *pvar, const char *value,
|
|
|
|
VarAssign *out_var)
|
2020-10-18 23:07:26 +03:00
|
|
|
{
|
2020-10-18 23:14:27 +03:00
|
|
|
const char *op = pvar->eq;
|
|
|
|
const char * const name = pvar->nameStart;
|
2020-10-18 23:07:26 +03:00
|
|
|
VarAssignOp type;
|
|
|
|
|
|
|
|
if (op > name && op[-1] == '+') {
|
|
|
|
type = VAR_APPEND;
|
|
|
|
op--;
|
|
|
|
|
|
|
|
} else if (op > name && op[-1] == '?') {
|
|
|
|
op--;
|
|
|
|
type = VAR_DEFAULT;
|
|
|
|
|
|
|
|
} else if (op > name && op[-1] == ':') {
|
|
|
|
op--;
|
|
|
|
type = VAR_SUBST;
|
|
|
|
|
|
|
|
} else if (op > name && op[-1] == '!') {
|
|
|
|
op--;
|
|
|
|
type = VAR_SHELL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
type = VAR_NORMAL;
|
|
|
|
#ifdef SUNSHCMD
|
|
|
|
while (op > name && ch_isspace(op[-1]))
|
|
|
|
op--;
|
|
|
|
|
|
|
|
if (op >= name + 3 && op[-3] == ':' && op[-2] == 's' && op[-1] == 'h') {
|
|
|
|
type = VAR_SHELL;
|
|
|
|
op -= 3;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-10-18 23:14:27 +03:00
|
|
|
const char *nameEnd = pvar->nameEnd < op ? pvar->nameEnd : op;
|
|
|
|
out_var->varname = bmake_strsedup(pvar->nameStart, nameEnd);
|
|
|
|
out_var->op = type;
|
|
|
|
out_var->value = value;
|
2020-10-18 23:07:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/* Parse a variable assignment, consisting of a single-word variable name,
|
|
|
|
* optional whitespace, an assignment operator, optional whitespace and the
|
|
|
|
* variable value.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-05 22:27:47 +03:00
|
|
|
* Used for both lines in a file and command line arguments. */
|
1993-03-21 12:45:37 +03:00
|
|
|
Boolean
|
2020-10-05 22:27:47 +03:00
|
|
|
Parse_IsVar(const char *p, VarAssign *out_var)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-10-18 23:14:27 +03:00
|
|
|
VarAssignParsed pvar;
|
2020-10-05 22:27:47 +03:00
|
|
|
const char *firstSpace = NULL;
|
2009-01-09 00:12:09 +03:00
|
|
|
char ch;
|
1995-09-10 07:58:16 +04:00
|
|
|
int level = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/* Skip to variable name */
|
|
|
|
while (*p == ' ' || *p == '\t')
|
|
|
|
p++;
|
|
|
|
|
|
|
|
/* During parsing, the '+' of the '+=' operator is initially parsed
|
|
|
|
* as part of the variable name. It is later corrected, as is the ':sh'
|
|
|
|
* modifier. Of these two (nameEnd and op), the earlier one determines the
|
|
|
|
* actual end of the variable name. */
|
2020-10-18 23:14:27 +03:00
|
|
|
pvar.nameStart = p;
|
2020-10-05 22:27:47 +03:00
|
|
|
#ifdef CLEANUP
|
2020-10-18 23:14:27 +03:00
|
|
|
pvar.nameEnd = NULL;
|
|
|
|
pvar.eq = NULL;
|
2020-10-05 22:27:47 +03:00
|
|
|
#endif
|
2020-10-04 22:36:32 +03:00
|
|
|
|
2009-01-09 00:12:09 +03:00
|
|
|
/* Scan for one of the assignment operators outside a variable expansion */
|
2020-10-05 22:27:47 +03:00
|
|
|
while ((ch = *p++) != 0) {
|
2009-01-09 00:12:09 +03:00
|
|
|
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
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2009-01-09 00:12:09 +03:00
|
|
|
if (level != 0)
|
|
|
|
continue;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
if (ch == ' ' || ch == '\t')
|
|
|
|
if (firstSpace == NULL)
|
2020-10-17 20:47:14 +03:00
|
|
|
firstSpace = p - 1;
|
2020-10-05 22:27:47 +03:00
|
|
|
while (ch == ' ' || ch == '\t')
|
|
|
|
ch = *p++;
|
|
|
|
|
2013-08-29 01:56:49 +04:00
|
|
|
#ifdef SUNSHCMD
|
2020-10-05 22:27:47 +03:00
|
|
|
if (ch == ':' && strncmp(p, "sh", 2) == 0) {
|
|
|
|
p += 2;
|
2013-08-29 01:56:49 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2020-10-05 22:27:47 +03:00
|
|
|
if (ch == '=') {
|
2020-10-18 23:14:27 +03:00
|
|
|
pvar.eq = p - 1;
|
|
|
|
pvar.nameEnd = firstSpace != NULL ? firstSpace : p - 1;
|
2020-10-05 22:27:47 +03:00
|
|
|
cpp_skip_whitespace(&p);
|
2020-10-18 23:14:27 +03:00
|
|
|
AdjustVarassignOp(&pvar, p, out_var);
|
2009-01-09 00:12:09 +03:00
|
|
|
return TRUE;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
if (*p == '=' && (ch == '+' || ch == ':' || ch == '?' || ch == '!')) {
|
2020-10-18 23:14:27 +03:00
|
|
|
pvar.eq = p;
|
|
|
|
pvar.nameEnd = firstSpace != NULL ? firstSpace : p;
|
2020-10-05 22:27:47 +03:00
|
|
|
p++;
|
|
|
|
cpp_skip_whitespace(&p);
|
2020-10-18 23:14:27 +03:00
|
|
|
AdjustVarassignOp(&pvar, p, out_var);
|
2009-01-09 00:12:09 +03:00
|
|
|
return TRUE;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
if (firstSpace != NULL)
|
2009-01-09 00:12:09 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
|
|
|
VarCheckSyntax(VarAssignOp type, const char *uvalue, GNode *ctxt)
|
|
|
|
{
|
2020-07-31 23:22:10 +03:00
|
|
|
if (DEBUG(LINT)) {
|
2020-10-05 22:27:47 +03:00
|
|
|
if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) {
|
|
|
|
/* Check for syntax errors such as unclosed expressions or
|
|
|
|
* unknown modifiers. */
|
2020-09-25 23:48:23 +03:00
|
|
|
char *expandedValue;
|
2020-07-31 23:22:10 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
(void)Var_Subst(uvalue, ctxt, VARE_NONE, &expandedValue);
|
2020-09-22 23:19:46 +03:00
|
|
|
/* TODO: handle errors */
|
2020-09-25 23:48:23 +03:00
|
|
|
free(expandedValue);
|
2020-07-31 23:22:10 +03:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 23:29:50 +03:00
|
|
|
static void
|
2020-10-18 23:46:42 +03:00
|
|
|
VarAssign_EvalSubst(const char *name, const char *uvalue, GNode *ctxt,
|
2020-10-18 23:29:50 +03:00
|
|
|
const char **out_avalue, void **out_avalue_freeIt)
|
|
|
|
{
|
|
|
|
const char *avalue = uvalue;
|
|
|
|
char *evalue;
|
|
|
|
/*
|
|
|
|
* Allow variables in the old value to be undefined, but leave their
|
|
|
|
* expressions 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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure that we set the variable the first time to nothing
|
|
|
|
* so that it gets substituted!
|
|
|
|
*/
|
|
|
|
if (!Var_Exists(name, ctxt))
|
|
|
|
Var_Set(name, "", ctxt);
|
|
|
|
|
|
|
|
(void)Var_Subst(uvalue, ctxt, VARE_WANTRES|VARE_ASSIGN, &evalue);
|
|
|
|
/* TODO: handle errors */
|
|
|
|
oldVars = oldOldVars;
|
|
|
|
avalue = evalue;
|
|
|
|
Var_Set(name, avalue, ctxt);
|
|
|
|
|
|
|
|
*out_avalue = avalue;
|
|
|
|
*out_avalue_freeIt = evalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-10-18 23:46:42 +03:00
|
|
|
VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt,
|
2020-10-18 23:29:50 +03:00
|
|
|
const char **out_avalue, void **out_avalue_freeIt)
|
|
|
|
{
|
|
|
|
const char *cmd, *errfmt;
|
|
|
|
char *cmdOut;
|
|
|
|
void *cmd_freeIt = NULL;
|
|
|
|
|
|
|
|
cmd = uvalue;
|
|
|
|
if (strchr(cmd, '$') != NULL) {
|
|
|
|
char *ecmd;
|
|
|
|
(void)Var_Subst(cmd, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES, &ecmd);
|
|
|
|
/* TODO: handle errors */
|
|
|
|
cmd = cmd_freeIt = ecmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdOut = Cmd_Exec(cmd, &errfmt);
|
2020-10-18 23:46:42 +03:00
|
|
|
Var_Set(name, cmdOut, ctxt);
|
2020-10-18 23:29:50 +03:00
|
|
|
*out_avalue = *out_avalue_freeIt = cmdOut;
|
|
|
|
|
|
|
|
if (errfmt)
|
|
|
|
Parse_Error(PARSE_WARNING, errfmt, cmd);
|
|
|
|
|
|
|
|
free(cmd_freeIt);
|
|
|
|
}
|
|
|
|
|
2020-10-18 23:46:42 +03:00
|
|
|
/* Perform a variable assignment.
|
|
|
|
*
|
|
|
|
* The actual value of the variable is returned in *out_avalue and
|
|
|
|
* *out_avalue_freeIt. Especially for VAR_SUBST and VAR_SHELL this can differ
|
|
|
|
* from the literal value.
|
|
|
|
*
|
|
|
|
* Return whether the assignment was actually done. The assignment is only
|
|
|
|
* skipped if the operator is '?=' and the variable already exists. */
|
2020-10-05 22:27:47 +03:00
|
|
|
static Boolean
|
2020-10-18 23:46:42 +03:00
|
|
|
VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue,
|
|
|
|
GNode *ctxt, const char **out_avalue, void **out_avalue_freeIt)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
const char *avalue = uvalue;
|
|
|
|
void *avalue_freeIt = NULL;
|
2020-10-04 17:40:13 +03:00
|
|
|
|
2020-10-18 23:46:42 +03:00
|
|
|
if (op == VAR_APPEND) {
|
2020-10-05 22:27:47 +03:00
|
|
|
Var_Append(name, uvalue, ctxt);
|
2020-10-18 23:46:42 +03:00
|
|
|
} else if (op == VAR_SUBST) {
|
|
|
|
VarAssign_EvalSubst(name, uvalue, ctxt, &avalue, &avalue_freeIt);
|
|
|
|
} else if (op == VAR_SHELL) {
|
|
|
|
VarAssign_EvalShell(name, uvalue, ctxt, &avalue, &avalue_freeIt);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
2020-10-18 23:46:42 +03:00
|
|
|
if (op == VAR_DEFAULT && Var_Exists(name, ctxt)) {
|
2020-10-05 22:27:47 +03:00
|
|
|
*out_avalue_freeIt = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal assignment -- just do it. */
|
|
|
|
Var_Set(name, uvalue, ctxt);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
|
|
|
*out_avalue = avalue;
|
|
|
|
*out_avalue_freeIt = avalue_freeIt;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VarAssignSpecial(const char *name, const char *avalue)
|
|
|
|
{
|
|
|
|
if (strcmp(name, MAKEOVERRIDES) == 0)
|
2001-10-31 04:15:57 +03:00
|
|
|
Main_ExportMAKEFLAGS(FALSE); /* re-export MAKEFLAGS */
|
2020-10-05 22:27:47 +03:00
|
|
|
else if (strcmp(name, ".CURDIR") == 0) {
|
2002-11-26 09:12:59 +03:00
|
|
|
/*
|
2020-09-22 05:26:22 +03:00
|
|
|
* Someone is being (too?) clever...
|
2002-11-26 09:12:59 +03:00
|
|
|
* Let's pretend they know what they are doing and
|
2020-09-22 05:26:22 +03:00
|
|
|
* re-initialize the 'cur' CachedDir.
|
2002-11-26 09:12:59 +03:00
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
Dir_InitCur(avalue);
|
2002-11-26 09:12:59 +03:00
|
|
|
Dir_SetPATH();
|
2020-10-05 22:27:47 +03:00
|
|
|
} else if (strcmp(name, MAKE_JOB_PREFIX) == 0) {
|
2007-10-02 02:14:09 +04:00
|
|
|
Job_SetPrefix();
|
2020-10-05 22:27:47 +03:00
|
|
|
} else if (strcmp(name, MAKE_EXPORTED) == 0) {
|
|
|
|
Var_Export(avalue, FALSE);
|
2002-11-26 09:12:59 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Take the variable assignment in the passed line and execute it.
|
|
|
|
*
|
|
|
|
* 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++ =".
|
|
|
|
*
|
|
|
|
* Input:
|
|
|
|
* p A line guaranteed to be a variable assignment
|
|
|
|
* (see Parse_IsVar).
|
|
|
|
* ctxt Context in which to do the assignment
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Parse_DoVar(VarAssign *var, GNode *ctxt)
|
|
|
|
{
|
|
|
|
const char *avalue; /* actual value (maybe expanded) */
|
|
|
|
void *avalue_freeIt;
|
|
|
|
|
|
|
|
VarCheckSyntax(var->op, var->value, ctxt);
|
2020-10-18 23:46:42 +03:00
|
|
|
if (VarAssign_Eval(var->varname, var->op, var->value, ctxt,
|
|
|
|
&avalue, &avalue_freeIt))
|
2020-10-05 22:27:47 +03:00
|
|
|
VarAssignSpecial(var->varname, avalue);
|
|
|
|
|
|
|
|
free(avalue_freeIt);
|
|
|
|
free(var->varname);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2014-08-23 19:05:40 +04:00
|
|
|
|
2014-09-08 00:55:34 +04:00
|
|
|
/*
|
2014-07-16 19:33:41 +04:00
|
|
|
* ParseMaybeSubMake --
|
2020-09-28 00:35:16 +03:00
|
|
|
* Scan the command string to see if it a possible submake node
|
2014-07-16 19:33:41 +04:00
|
|
|
* Input:
|
|
|
|
* cmd the command to scan
|
|
|
|
* Results:
|
|
|
|
* TRUE if the command is possibly a submake, FALSE if not.
|
|
|
|
*/
|
|
|
|
static Boolean
|
|
|
|
ParseMaybeSubMake(const char *cmd)
|
|
|
|
{
|
2014-07-16 22:58:07 +04:00
|
|
|
size_t i;
|
2014-07-16 19:33:41 +04:00
|
|
|
static struct {
|
|
|
|
const char *name;
|
|
|
|
size_t len;
|
|
|
|
} vals[] = {
|
|
|
|
#define MKV(A) { A, sizeof(A) - 1 }
|
|
|
|
MKV("${MAKE}"),
|
|
|
|
MKV("${.MAKE}"),
|
|
|
|
MKV("$(MAKE)"),
|
|
|
|
MKV("$(.MAKE)"),
|
|
|
|
MKV("make"),
|
|
|
|
};
|
2020-10-17 21:39:43 +03:00
|
|
|
for (i = 0; i < sizeof vals / sizeof vals[0]; i++) {
|
2014-07-16 19:33:41 +04:00
|
|
|
char *ptr;
|
|
|
|
if ((ptr = strstr(cmd, vals[i].name)) == NULL)
|
|
|
|
continue;
|
2020-09-11 20:32:36 +03:00
|
|
|
if ((ptr == cmd || !ch_isalnum(ptr[-1]))
|
|
|
|
&& !ch_isalnum(ptr[vals[i].len]))
|
2014-07-16 19:33:41 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-09-26 00:13:44 +03:00
|
|
|
/* Append the command to the target node.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-09-26 00:13:44 +03:00
|
|
|
* The node may be marked as a submake node if the command is determined to
|
|
|
|
* be that. */
|
|
|
|
static void
|
|
|
|
ParseAddCmd(GNode *gn, char *cmd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2006-11-18 01:07:39 +03:00
|
|
|
/* Add to last (ie current) cohort for :: targets */
|
2020-09-26 00:13:44 +03:00
|
|
|
if ((gn->type & OP_DOUBLEDEP) && gn->cohorts->last != NULL)
|
|
|
|
gn = gn->cohorts->last->datum;
|
2006-11-18 01:07:39 +03:00
|
|
|
|
2014-09-08 00:55:34 +04:00
|
|
|
/* if target already supplied, ignore commands */
|
|
|
|
if (!(gn->type & OP_HAS_COMMANDS)) {
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(gn->commands, cmd);
|
2014-09-08 00:55:34 +04:00
|
|
|
if (ParseMaybeSubMake(cmd))
|
|
|
|
gn->type |= OP_SUBMAKE;
|
|
|
|
ParseMark(gn);
|
|
|
|
} else {
|
2020-09-26 00:13:44 +03:00
|
|
|
#if 0
|
2014-09-08 00:55:34 +04:00
|
|
|
/* XXX: We cannot do this until we fix the tree */
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(gn->commands, cmd);
|
2014-09-08 00:55:34 +04:00
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"overriding commands for target \"%s\"; "
|
|
|
|
"previous commands defined at %s: %d ignored",
|
|
|
|
gn->name, gn->fname, gn->lineno);
|
|
|
|
#else
|
|
|
|
Parse_Error(PARSE_WARNING,
|
2020-10-17 21:36:56 +03:00
|
|
|
"duplicate script for target \"%s\" ignored",
|
|
|
|
gn->name);
|
2020-10-06 00:37:07 +03:00
|
|
|
ParseErrorInternal(gn->fname, (size_t)gn->lineno, PARSE_WARNING,
|
2020-10-17 21:36:56 +03:00
|
|
|
"using previous script for \"%s\" defined here",
|
|
|
|
gn->name);
|
2014-09-08 00:55:34 +04:00
|
|
|
#endif
|
2014-08-23 19:05:40 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Add a directory to the path searched for included makefiles bracketed
|
|
|
|
* by double-quotes. */
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
2020-10-02 02:44:36 +03:00
|
|
|
Parse_AddIncludeDir(const 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
|
|
|
}
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Push to another file.
|
1996-11-06 20:58:58 +03:00
|
|
|
*
|
2020-09-05 22:07:25 +03:00
|
|
|
* The input is the line minus the '.'. A file spec is a string enclosed in
|
|
|
|
* <> or "". The <> file is looked for only in sysIncPath. The "" file is
|
|
|
|
* first searched in the parsedir and then in the directories specified by
|
|
|
|
* the -I command line options.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
static void
|
2016-02-18 08:02:49 +03:00
|
|
|
Parse_include_file(char *file, Boolean isSystem, Boolean depinc, int silent)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2010-12-25 07:57:07 +03:00
|
|
|
struct loadedfile *lf;
|
2020-10-17 21:36:56 +03:00
|
|
|
char *fullname; /* full pathname of file */
|
|
|
|
char *newName;
|
|
|
|
char *prefEnd, *incdir;
|
|
|
|
int fd;
|
|
|
|
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';
|
|
|
|
}
|
2020-08-10 22:53:19 +03:00
|
|
|
newName = str_concat3(incdir, "/", file + i);
|
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
|
|
|
/*
|
2020-08-01 17:47:49 +03:00
|
|
|
* Makefile wasn't found in same directory as included makefile.
|
2002-01-24 04:39:03 +03:00
|
|
|
* 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;
|
2020-09-22 07:05:41 +03:00
|
|
|
SearchPath *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
|
|
|
*/
|
2020-10-17 21:39:43 +03:00
|
|
|
SearchPath *path = Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath;
|
|
|
|
fullname = Dir_FindFile(file, path);
|
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;
|
2016-02-18 08:02:49 +03:00
|
|
|
if (depinc)
|
2020-10-17 21:36:56 +03:00
|
|
|
doing_depend = depinc; /* only turn it on */
|
2006-12-08 00:07:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ParseDoInclude(char *line)
|
|
|
|
{
|
2020-10-17 21:36:56 +03:00
|
|
|
char endc; /* the character which ends the file spec */
|
|
|
|
char *cp; /* current position in file spec */
|
|
|
|
int silent = *line != 'i';
|
2020-10-17 21:39:43 +03:00
|
|
|
char *file = line + (silent ? 8 : 7);
|
2006-12-08 00:07:01 +03:00
|
|
|
|
|
|
|
/* Skip to delimiter character so we know where to look */
|
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
|
|
|
|
|
|
|
if (*file != '"' && *file != '<') {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-10-17 21:36:56 +03:00
|
|
|
".include filename must be delimited by '\"' or '<'");
|
2006-12-08 00:07:01 +03:00
|
|
|
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,
|
2020-10-17 21:36:56 +03:00
|
|
|
"Unclosed %cinclude filename. '%c' expected",
|
|
|
|
'.', endc);
|
2006-12-08 00:07:01 +03:00
|
|
|
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.
|
|
|
|
*/
|
2020-09-22 23:19:46 +03:00
|
|
|
(void)Var_Subst(file, VAR_CMD, VARE_WANTRES, &file);
|
|
|
|
/* TODO: handle errors */
|
2006-12-08 00:07:01 +03:00
|
|
|
|
2020-07-28 22:13:49 +03:00
|
|
|
Parse_include_file(file, endc == '>', *line == 'd', silent);
|
2006-12-08 00:07:01 +03:00
|
|
|
free(file);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-09-05 21:18:05 +03:00
|
|
|
/* Split filename into dirname + basename, then assign these to the
|
|
|
|
* given variables. */
|
2014-01-10 20:12:52 +04:00
|
|
|
static void
|
2020-09-05 21:18:05 +03:00
|
|
|
SetFilenameVars(const char *filename, const char *dirvar, const char *filevar)
|
2014-01-10 20:12:52 +04:00
|
|
|
{
|
2020-09-05 21:18:05 +03:00
|
|
|
const char *slash, *dirname, *basename;
|
|
|
|
void *freeIt;
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2020-09-05 21:18:05 +03:00
|
|
|
slash = strrchr(filename, '/');
|
|
|
|
if (slash == NULL) {
|
|
|
|
dirname = curdir;
|
|
|
|
basename = filename;
|
|
|
|
freeIt = NULL;
|
|
|
|
} else {
|
|
|
|
dirname = freeIt = bmake_strsedup(filename, slash);
|
|
|
|
basename = slash + 1;
|
|
|
|
}
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2020-09-05 21:18:05 +03:00
|
|
|
Var_Set(dirvar, dirname, VAR_GLOBAL);
|
|
|
|
Var_Set(filevar, basename, VAR_GLOBAL);
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2020-09-28 23:46:11 +03:00
|
|
|
DEBUG5(PARSE, "%s: ${%s} = `%s' ${%s} = `%s'\n",
|
|
|
|
__func__, dirvar, dirname, filevar, basename);
|
2020-09-05 21:18:05 +03:00
|
|
|
free(freeIt);
|
2014-01-10 20:12:52 +04:00
|
|
|
}
|
2020-09-05 21:18:05 +03:00
|
|
|
|
|
|
|
/* Return the immediately including file.
|
1999-08-10 01:06:28 +04:00
|
|
|
*
|
2020-09-05 21:18:05 +03:00
|
|
|
* This is made complicated since the .for loop is implemented as a special
|
|
|
|
* kind of .include; see For_Run. */
|
|
|
|
static const char *
|
|
|
|
GetActuallyIncludingFile(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
2020-09-05 21:31:03 +03:00
|
|
|
for (i = includes.len; i > 0; i--) {
|
2020-10-25 16:06:12 +03:00
|
|
|
IFile *parent = GetInclude(i - 1);
|
|
|
|
IFile *child = i < includes.len ? GetInclude(i) : curFile;
|
2020-09-05 21:18:05 +03:00
|
|
|
if (!child->fromForLoop)
|
2020-09-05 21:31:03 +03:00
|
|
|
return parent->fname;
|
2020-09-05 21:18:05 +03:00
|
|
|
}
|
2020-09-05 21:31:03 +03:00
|
|
|
return NULL;
|
2020-09-05 21:18:05 +03:00
|
|
|
}
|
|
|
|
|
2020-09-05 22:11:16 +03:00
|
|
|
/* Set .PARSEDIR, .PARSEFILE, .INCLUDEDFROMDIR and .INCLUDEDFROMFILE. */
|
1999-08-10 01:06:28 +04:00
|
|
|
static void
|
2006-12-05 00:34:47 +03:00
|
|
|
ParseSetParseFile(const char *filename)
|
1999-08-10 01:06:28 +04:00
|
|
|
{
|
2020-09-05 21:18:05 +03:00
|
|
|
const char *including;
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2020-09-05 21:18:05 +03:00
|
|
|
SetFilenameVars(filename, ".PARSEDIR", ".PARSEFILE");
|
|
|
|
|
|
|
|
including = GetActuallyIncludingFile();
|
|
|
|
if (including != NULL) {
|
|
|
|
SetFilenameVars(including,
|
|
|
|
".INCLUDEDFROMDIR", ".INCLUDEDFROMFILE");
|
1999-08-10 01:06:28 +04:00
|
|
|
} else {
|
2020-09-05 21:18:05 +03:00
|
|
|
Var_Delete(".INCLUDEDFROMDIR", VAR_GLOBAL);
|
|
|
|
Var_Delete(".INCLUDEDFROMFILE", VAR_GLOBAL);
|
1999-08-10 01:06:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Track the makefiles we read - so makefiles can set dependencies on them.
|
|
|
|
* Avoid adding anything more than once. */
|
2012-04-25 00:12:16 +04:00
|
|
|
static void
|
|
|
|
ParseTrackInput(const char *name)
|
|
|
|
{
|
|
|
|
char *fp = NULL;
|
2020-07-03 11:13:23 +03:00
|
|
|
|
2020-08-01 12:25:36 +03:00
|
|
|
const char *old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
|
2012-04-25 00:12:16 +04:00
|
|
|
if (old) {
|
2020-08-01 12:25:36 +03:00
|
|
|
size_t name_len = strlen(name);
|
|
|
|
const char *ep = old + strlen(old) - name_len;
|
2012-04-25 00:12:16 +04:00
|
|
|
/* does it contain name? */
|
|
|
|
for (; old != NULL; old = strchr(old, ' ')) {
|
|
|
|
if (*old == ' ')
|
|
|
|
old++;
|
2015-11-26 03:23:04 +03:00
|
|
|
if (old >= ep)
|
2020-10-17 21:36:56 +03:00
|
|
|
break; /* cannot contain name */
|
|
|
|
if (memcmp(old, name, name_len) == 0 &&
|
|
|
|
(old[name_len] == '\0' || old[name_len] == ' '))
|
2012-04-25 00:12:16 +04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 21:36:56 +03:00
|
|
|
Var_Append(MAKE_MAKEFILES, name, VAR_GLOBAL);
|
|
|
|
cleanup:
|
2020-08-01 12:55:00 +03:00
|
|
|
bmake_free(fp);
|
2012-04-25 00:12:16 +04:00
|
|
|
}
|
2007-10-09 00:26:36 +04:00
|
|
|
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2020-09-04 20:59:36 +03:00
|
|
|
/* Start Parsing from the given source.
|
1994-03-05 03:34:29 +03:00
|
|
|
*
|
2020-09-04 20:59:36 +03:00
|
|
|
* The given file is added to the includes stack. */
|
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,
|
2020-10-17 21:36:56 +03:00
|
|
|
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;
|
2020-09-05 21:18:05 +03:00
|
|
|
Boolean fromForLoop = name == NULL;
|
2009-01-11 18:50:06 +03:00
|
|
|
|
2020-09-05 21:18:05 +03:00
|
|
|
if (fromForLoop)
|
2007-01-02 00:47:32 +03:00
|
|
|
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))
|
2020-09-29 01:23:35 +03:00
|
|
|
debug_printf("%s: file %s, line %d, fd %d, nextbuf %s, arg %p\n",
|
|
|
|
__func__, name, line, fd,
|
|
|
|
nextbuf == loadedfile_nextbuf ? "loadedfile" : "other",
|
|
|
|
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
|
|
|
|
2020-10-25 16:06:12 +03:00
|
|
|
if (curFile != NULL) {
|
2020-09-05 21:18:05 +03:00
|
|
|
/* Save existing file info */
|
2020-10-25 16:06:12 +03:00
|
|
|
IFile **next = Vector_Push(&includes);
|
|
|
|
*next = 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);
|
2020-09-05 21:18:05 +03:00
|
|
|
curFile->fromForLoop = fromForLoop;
|
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;
|
2016-02-19 09:19:06 +03:00
|
|
|
curFile->depending = doing_depend; /* restore this on EOF */
|
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) {
|
2020-08-01 17:47:49 +03:00
|
|
|
/* 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;
|
2020-10-17 21:36:56 +03:00
|
|
|
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
|
|
|
|
2020-10-17 21:39:43 +03:00
|
|
|
/* Check if the directive is an include directive. */
|
2018-04-05 03:31:10 +03:00
|
|
|
static Boolean
|
2020-09-13 12:43:01 +03:00
|
|
|
IsInclude(const char *dir, Boolean sysv)
|
2018-04-05 03:31:10 +03:00
|
|
|
{
|
2020-09-13 12:43:01 +03:00
|
|
|
if (dir[0] == 's' || dir[0] == '-' || (dir[0] == 'd' && !sysv))
|
|
|
|
dir++;
|
2018-04-05 03:31:10 +03:00
|
|
|
|
2020-09-13 12:43:01 +03:00
|
|
|
if (strncmp(dir, "include", 7) != 0)
|
2018-04-05 03:31:10 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2020-08-03 23:43:41 +03:00
|
|
|
/* Space is not mandatory for BSD .include */
|
2020-09-13 12:43:01 +03:00
|
|
|
return !sysv || ch_isspace(dir[7]);
|
2018-04-05 03:31:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
#ifdef SYSVINCLUDE
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Check if the line is a SYSV include directive. */
|
2018-04-05 03:31:10 +03:00
|
|
|
static Boolean
|
|
|
|
IsSysVInclude(const char *line)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (!IsInclude(line, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
|
2020-10-17 21:39:43 +03:00
|
|
|
/* Avoid interpreting a dependency line as an include */
|
2018-04-05 03:31:10 +03:00
|
|
|
for (p = line; (p = strchr(p, ':')) != NULL;) {
|
|
|
|
if (*++p == '\0') {
|
|
|
|
/* end of line -> dependency */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-09-11 20:32:36 +03:00
|
|
|
if (*p == ':' || ch_isspace(*p)) {
|
2018-04-05 03:31:10 +03:00
|
|
|
/* :: operator or ': ' -> dependency */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Push to another file. The line points to the word "include". */
|
1994-03-05 03:34:29 +03:00
|
|
|
static void
|
2002-06-15 22:24:55 +04:00
|
|
|
ParseTraditionalInclude(char *line)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2020-10-17 21:36:56 +03:00
|
|
|
char *cp; /* current position in file spec */
|
|
|
|
int done = 0;
|
|
|
|
int silent = line[0] != 'i';
|
|
|
|
char *file = line + (silent ? 8 : 7);
|
|
|
|
char *all_files;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2020-09-28 23:46:11 +03:00
|
|
|
DEBUG2(PARSE, "%s: %s\n", __func__, file);
|
2006-03-28 21:41:35 +04:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
pp_skip_whitespace(&file);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2006-03-28 21:41:35 +04:00
|
|
|
/*
|
|
|
|
* Substitute for any variables in the file name before trying to
|
|
|
|
* find the thing.
|
|
|
|
*/
|
2020-09-22 23:19:46 +03:00
|
|
|
(void)Var_Subst(file, VAR_CMD, VARE_WANTRES, &all_files);
|
|
|
|
/* TODO: handle errors */
|
2006-03-28 21:41:35 +04:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
if (*file == '\0') {
|
2020-10-17 21:36:56 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Filename missing from \"include\"");
|
2017-04-17 00:38:38 +03:00
|
|
|
goto out;
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
|
2006-12-08 00:07:01 +03:00
|
|
|
for (file = all_files; !done; file = cp + 1) {
|
|
|
|
/* Skip to end of line or next whitespace */
|
2020-09-11 20:32:36 +03:00
|
|
|
for (cp = file; *cp && !ch_isspace(*cp); cp++)
|
1998-08-06 17:42:22 +04:00
|
|
|
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
|
|
|
|
2016-02-18 08:02:49 +03:00
|
|
|
Parse_include_file(file, FALSE, FALSE, silent);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
2017-04-17 00:38:38 +03:00
|
|
|
out:
|
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
|
2020-10-17 21:39:43 +03:00
|
|
|
/* Parse "export <variable>=<value>", and actually export it. */
|
2012-03-31 04:12:24 +04:00
|
|
|
static void
|
|
|
|
ParseGmakeExport(char *line)
|
|
|
|
{
|
2020-10-17 21:39:43 +03:00
|
|
|
char *variable = line + 6;
|
2020-10-17 21:36:56 +03:00
|
|
|
char *value;
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2020-09-28 23:46:11 +03:00
|
|
|
DEBUG2(PARSE, "%s: %s\n", __func__, variable);
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
pp_skip_whitespace(&variable);
|
2012-03-31 04:12:24 +04:00
|
|
|
|
|
|
|
for (value = variable; *value && *value != '='; value++)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*value != '=') {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-09-05 22:07:25 +03:00
|
|
|
"Variable/Value missing from \"export\"");
|
2012-03-31 04:12:24 +04:00
|
|
|
return;
|
|
|
|
}
|
2020-10-17 21:36:56 +03: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
|
|
|
*/
|
2020-09-22 23:19:46 +03:00
|
|
|
(void)Var_Subst(value, VAR_CMD, VARE_WANTRES, &value);
|
|
|
|
/* TODO: handle errors */
|
|
|
|
|
2012-03-31 04:12:24 +04:00
|
|
|
setenv(variable, value, 1);
|
2017-04-17 00:37:37 +03:00
|
|
|
free(value);
|
2012-03-31 04:12:24 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* 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.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Results:
|
2020-10-17 21:58:26 +03:00
|
|
|
* TRUE to continue parsing, i.e. it had only reached the end of an
|
|
|
|
* included file, FALSE if the main file has been parsed completely.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-17 21:58:26 +03:00
|
|
|
static Boolean
|
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);
|
|
|
|
|
2016-02-18 08:02:49 +03:00
|
|
|
doing_depend = curFile->depending; /* restore this */
|
2010-12-25 07:57:07 +03:00
|
|
|
/* 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 */
|
2020-10-17 21:58:26 +03:00
|
|
|
return TRUE;
|
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) {
|
2020-10-17 21:36:56 +03:00
|
|
|
loadedfile_destroy(curFile->lf);
|
|
|
|
curFile->lf = NULL;
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-10-25 16:06:12 +03:00
|
|
|
if (includes.len == 0) {
|
2020-08-22 20:34:25 +03:00
|
|
|
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);
|
2014-02-15 04:17:17 +04:00
|
|
|
Var_Delete(".INCLUDEDFROMDIR", VAR_GLOBAL);
|
|
|
|
Var_Delete(".INCLUDEDFROMFILE", VAR_GLOBAL);
|
2020-10-17 21:58:26 +03:00
|
|
|
return FALSE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-25 16:06:12 +03:00
|
|
|
curFile = GetInclude(includes.len - 1);
|
|
|
|
Vector_Pop(&includes);
|
2020-09-28 23:46:11 +03:00
|
|
|
DEBUG2(PARSE, "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
|
|
|
ParseSetParseFile(curFile->fname);
|
2020-10-17 21:58:26 +03:00
|
|
|
return TRUE;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
#define PARSE_RAW 1
|
|
|
|
#define PARSE_SKIP 2
|
|
|
|
|
|
|
|
static char *
|
2020-10-05 22:27:47 +03:00
|
|
|
ParseGetLine(int flags)
|
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,
|
2020-10-17 21:36:56 +03:00
|
|
|
"Zero byte read from file, "
|
|
|
|
"skipping rest of line.");
|
2013-08-11 01:20:03 +04:00
|
|
|
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;
|
2020-09-11 20:32:36 +03:00
|
|
|
if (!ch_isspace(ch))
|
2007-01-02 00:47:32 +03:00
|
|
|
/* 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) */
|
|
|
|
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 */
|
2020-10-05 22:27:47 +03:00
|
|
|
if (escaped == NULL)
|
2007-01-02 00:47:32 +03:00
|
|
|
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
|
|
|
|
2014-09-08 00:55:34 +04:00
|
|
|
/* Escaped '\n' replace following whitespace with a single ' ' */
|
|
|
|
while (ptr[0] == ' ' || ptr[0] == '\t')
|
|
|
|
ptr++;
|
|
|
|
ch = ' ';
|
2007-01-02 00:47:32 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
/* Delete any trailing spaces - eg from empty continuations */
|
2020-09-11 20:32:36 +03:00
|
|
|
while (tp > escaped && ch_isspace(tp[-1]))
|
2007-01-02 00:47:32 +03:00
|
|
|
tp--;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2007-01-02 00:47:32 +03:00
|
|
|
*tp = 0;
|
1994-03-05 03:34:29 +03:00
|
|
|
return line;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Read an entire line from the input file. Called only by Parse_File.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Results:
|
2020-09-05 22:07:25 +03:00
|
|
|
* A line without its newline.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2020-09-28 00:35:16 +03:00
|
|
|
char *line; /* Result */
|
|
|
|
int lineno; /* Saved line # */
|
|
|
|
int rval;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-03-05 03:34:29 +03:00
|
|
|
for (;;) {
|
2020-10-05 22:27:47 +03:00
|
|
|
line = ParseGetLine(0);
|
2007-01-02 00:47:32 +03:00
|
|
|
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
|
|
|
*/
|
2020-09-13 16:50:27 +03:00
|
|
|
switch (Cond_EvalLine(line)) {
|
2007-01-02 00:47:32 +03:00
|
|
|
case COND_SKIP:
|
|
|
|
/* Skip to next conditional that evaluates to COND_PARSE. */
|
|
|
|
do {
|
2020-10-05 22:27:47 +03:00
|
|
|
line = ParseGetLine(PARSE_SKIP);
|
2020-09-13 16:50:27 +03:00
|
|
|
} while (line && Cond_EvalLine(line) != COND_PARSE);
|
2007-01-02 00:47:32 +03:00
|
|
|
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 {
|
2020-10-05 22:27:47 +03:00
|
|
|
line = ParseGetLine(PARSE_RAW);
|
2006-12-03 23:40:44 +03:00
|
|
|
if (line == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-10-17 21:36:56 +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
|
|
|
}
|
2020-07-03 11:02:55 +03:00
|
|
|
return line;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-09-26 02:35:25 +03:00
|
|
|
FinishDependencyGroup(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-09-26 02:39:51 +03:00
|
|
|
if (targets != NULL) {
|
2020-10-17 20:16:54 +03:00
|
|
|
GNodeListNode *ln;
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
|
|
|
|
Suff_EndTransform(gn);
|
|
|
|
|
|
|
|
/* Mark the target as already having commands if it does, to
|
|
|
|
* keep from having shell commands on multiple dependency lines. */
|
|
|
|
if (!Lst_IsEmpty(gn->commands))
|
|
|
|
gn->type |= OP_HAS_COMMANDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Lst_Free(targets);
|
2020-09-27 15:26:23 +03:00
|
|
|
targets = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2020-09-26 00:13:44 +03:00
|
|
|
/* Add the command to each target from the current dependency spec. */
|
2020-09-25 23:57:22 +03:00
|
|
|
static void
|
2020-10-17 21:39:43 +03:00
|
|
|
ParseLine_ShellCommand(const char *p)
|
2020-09-25 23:57:22 +03:00
|
|
|
{
|
2020-10-17 21:39:43 +03:00
|
|
|
cpp_skip_whitespace(&p);
|
|
|
|
if (*p == '\0')
|
2020-09-26 00:13:44 +03:00
|
|
|
return; /* skip empty commands */
|
|
|
|
|
2020-09-26 02:39:51 +03:00
|
|
|
if (targets == NULL) {
|
2020-10-17 21:39:43 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Unassociated shell command \"%s\"", p);
|
2020-09-26 00:13:44 +03:00
|
|
|
return;
|
2020-09-26 02:39:51 +03:00
|
|
|
}
|
2020-09-26 00:13:44 +03:00
|
|
|
|
|
|
|
{
|
2020-10-17 21:39:43 +03:00
|
|
|
char *cmd = bmake_strdup(p);
|
2020-09-26 00:13:44 +03:00
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
|
|
|
ParseAddCmd(gn, cmd);
|
|
|
|
}
|
2020-09-25 23:57:22 +03:00
|
|
|
#ifdef CLEANUP
|
2020-09-26 00:13:44 +03:00
|
|
|
Lst_Append(targCmds, cmd);
|
2020-09-25 23:57:22 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-10-17 23:37:38 +03:00
|
|
|
static Boolean
|
|
|
|
ParseDirective(char *line)
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (*line == '.') {
|
|
|
|
/*
|
|
|
|
* Lines that begin with the special character may be
|
|
|
|
* include or undef directives.
|
|
|
|
* On the other hand they can be suffix rules (.c.o: ...)
|
|
|
|
* or just dependencies for filenames that start '.'.
|
|
|
|
*/
|
|
|
|
cp = line + 1;
|
|
|
|
pp_skip_whitespace(&cp);
|
|
|
|
if (IsInclude(cp, FALSE)) {
|
|
|
|
ParseDoInclude(cp);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (strncmp(cp, "undef", 5) == 0) {
|
|
|
|
const char *varname;
|
|
|
|
cp += 5;
|
|
|
|
pp_skip_whitespace(&cp);
|
|
|
|
varname = cp;
|
|
|
|
for (; !ch_isspace(*cp) && *cp != '\0'; cp++)
|
|
|
|
continue;
|
|
|
|
*cp = '\0';
|
|
|
|
Var_Delete(varname, VAR_GLOBAL);
|
|
|
|
/* TODO: undefine all variables, not only the first */
|
|
|
|
/* TODO: use Str_Words, like everywhere else */
|
|
|
|
return TRUE;
|
|
|
|
} else if (strncmp(cp, "export", 6) == 0) {
|
|
|
|
cp += 6;
|
|
|
|
pp_skip_whitespace(&cp);
|
|
|
|
Var_Export(cp, TRUE);
|
|
|
|
return TRUE;
|
|
|
|
} else if (strncmp(cp, "unexport", 8) == 0) {
|
|
|
|
Var_UnExport(cp);
|
|
|
|
return TRUE;
|
|
|
|
} else if (strncmp(cp, "info", 4) == 0 ||
|
|
|
|
strncmp(cp, "error", 5) == 0 ||
|
|
|
|
strncmp(cp, "warning", 7) == 0) {
|
|
|
|
if (ParseMessage(cp))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean
|
|
|
|
ParseVarassign(const char *line)
|
|
|
|
{
|
|
|
|
VarAssign var;
|
|
|
|
if (Parse_IsVar(line, &var)) {
|
|
|
|
FinishDependencyGroup();
|
|
|
|
Parse_DoVar(&var, VAR_GLOBAL);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-10-17 23:51:34 +03:00
|
|
|
static char *
|
|
|
|
FindSemicolon(char *p)
|
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
for (; *p != '\0'; p++) {
|
|
|
|
if (*p == '\\' && p[1] != '\0') {
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p == '$' && (p[1] == '(' || p[1] == '{')) {
|
|
|
|
level++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level > 0 && (*p == ')' || *p == '}')) {
|
|
|
|
level--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level == 0 && *p == ';') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2020-10-17 23:37:38 +03:00
|
|
|
/* dependency -> target... op [source...]
|
|
|
|
* op -> ':' | '::' | '!' */
|
|
|
|
static void
|
2020-10-17 23:51:34 +03:00
|
|
|
ParseDependency(char *line)
|
2020-10-17 23:37:38 +03:00
|
|
|
{
|
|
|
|
VarEvalFlags eflags;
|
|
|
|
char *expanded_line;
|
2020-10-17 23:51:34 +03:00
|
|
|
const char *shellcmd = NULL;
|
2020-10-17 23:37:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For some reason - probably to make the parser impossible -
|
|
|
|
* a ';' can be used to separate commands from dependencies.
|
|
|
|
* Attempt to avoid ';' inside substitution patterns.
|
|
|
|
*/
|
|
|
|
{
|
2020-10-17 23:51:34 +03:00
|
|
|
char *semicolon = FindSemicolon(line);
|
|
|
|
if (*semicolon != '\0') {
|
2020-10-17 23:37:38 +03:00
|
|
|
/* Terminate the dependency list at the ';' */
|
2020-10-17 23:51:34 +03:00
|
|
|
*semicolon = '\0';
|
|
|
|
shellcmd = semicolon + 1;
|
|
|
|
}
|
2020-10-17 23:37:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We now know it's a dependency line so it needs to have all
|
|
|
|
* variables expanded before being parsed.
|
|
|
|
*
|
|
|
|
* XXX: Ideally the dependency line would first be split into
|
|
|
|
* its left-hand side, dependency operator and right-hand side,
|
|
|
|
* and then each side would be expanded on its own. This would
|
|
|
|
* allow for the left-hand side to allow only defined variables
|
|
|
|
* and to allow variables on the right-hand side to be undefined
|
|
|
|
* as well.
|
|
|
|
*
|
|
|
|
* Parsing the line first would also prevent that targets
|
|
|
|
* generated from variable expressions are interpreted as the
|
|
|
|
* dependency operator, such as in "target${:U:} middle: source",
|
|
|
|
* in which the middle is interpreted as a source, not a target.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* In lint mode, allow undefined variables to appear in
|
|
|
|
* dependency lines.
|
|
|
|
*
|
|
|
|
* Ideally, only the right-hand side would allow undefined
|
|
|
|
* variables since it is common to have no dependencies.
|
|
|
|
* Having undefined variables on the left-hand side is more
|
|
|
|
* unusual though. Since both sides are expanded in a single
|
|
|
|
* pass, there is not much choice what to do here.
|
|
|
|
*
|
|
|
|
* In normal mode, it does not matter whether undefined
|
|
|
|
* variables are allowed or not since as of 2020-09-14,
|
|
|
|
* Var_Parse does not print any parse errors in such a case.
|
|
|
|
* It simply returns the special empty string var_Error,
|
|
|
|
* which cannot be detected in the result of Var_Subst. */
|
|
|
|
eflags = DEBUG(LINT) ? VARE_WANTRES : VARE_UNDEFERR | VARE_WANTRES;
|
|
|
|
(void)Var_Subst(line, VAR_CMD, eflags, &expanded_line);
|
|
|
|
/* TODO: handle errors */
|
|
|
|
|
|
|
|
/* Need a fresh list for the target nodes */
|
|
|
|
if (targets != NULL)
|
|
|
|
Lst_Free(targets);
|
2020-10-18 16:02:10 +03:00
|
|
|
targets = Lst_New();
|
2020-10-17 23:37:38 +03:00
|
|
|
|
|
|
|
ParseDoDependency(expanded_line);
|
|
|
|
free(expanded_line);
|
2020-10-17 23:51:34 +03:00
|
|
|
|
|
|
|
if (shellcmd != NULL)
|
|
|
|
ParseLine_ShellCommand(shellcmd);
|
2020-10-17 23:37:38 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 23:57:08 +03:00
|
|
|
static void
|
|
|
|
ParseLine(char *line)
|
|
|
|
{
|
|
|
|
if (ParseDirective(line))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (*line == '\t') {
|
|
|
|
ParseLine_ShellCommand(line + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SYSVINCLUDE
|
|
|
|
if (IsSysVInclude(line)) {
|
|
|
|
/*
|
|
|
|
* It's an S3/S5-style "include".
|
|
|
|
*/
|
|
|
|
ParseTraditionalInclude(line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GMAKEEXPORT
|
|
|
|
if (strncmp(line, "export", 6) == 0 && ch_isspace(line[6]) &&
|
|
|
|
strchr(line, ':') == NULL) {
|
|
|
|
/*
|
|
|
|
* It's a Gmake "export".
|
|
|
|
*/
|
|
|
|
ParseGmakeExport(line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ParseVarassign(line))
|
|
|
|
return;
|
|
|
|
|
|
|
|
FinishDependencyGroup();
|
|
|
|
|
|
|
|
ParseDependency(line);
|
|
|
|
}
|
|
|
|
|
2020-09-13 12:25:52 +03:00
|
|
|
/* Parse a top-level makefile into its component parts, incorporating them
|
|
|
|
* into the global dependency graph.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2002-06-15 22:24:55 +04:00
|
|
|
* Input:
|
2020-09-13 12:25:52 +03:00
|
|
|
* name The name of the file being read
|
|
|
|
* fd The open file to parse; will be closed at the end
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
void
|
2006-12-16 11:59:29 +03:00
|
|
|
Parse_File(const char *name, int fd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-10-17 21:36:56 +03:00
|
|
|
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
|
|
|
|
2020-09-26 02:39:51 +03:00
|
|
|
assert(targets == NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
fatals = 0;
|
|
|
|
|
2020-07-28 22:13:49 +03:00
|
|
|
if (name == NULL)
|
|
|
|
name = "(stdin)";
|
2010-12-25 07:57:07 +03:00
|
|
|
|
|
|
|
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 {
|
2020-10-17 23:57:08 +03:00
|
|
|
while ((line = ParseReadLine()) != NULL) {
|
2020-09-28 23:46:11 +03:00
|
|
|
DEBUG2(PARSE, "ParseReadLine (%d): '%s'\n", curFile->lineno, line);
|
2020-10-17 23:57:08 +03:00
|
|
|
ParseLine(line);
|
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
|
|
|
*/
|
2020-10-17 21:58:26 +03:00
|
|
|
} while (ParseEOF());
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-09-26 02:35:25 +03:00
|
|
|
FinishDependencyGroup();
|
2020-09-26 02:30:16 +03:00
|
|
|
|
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,
|
2020-10-17 21:36:56 +03:00
|
|
|
"%s: Fatal errors encountered -- cannot continue",
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 00:32:30 +03:00
|
|
|
/* Initialize the parsing module. */
|
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;
|
2020-10-18 16:02:10 +03:00
|
|
|
parseIncPath = Lst_New();
|
|
|
|
sysIncPath = Lst_New();
|
|
|
|
defIncPath = Lst_New();
|
2020-10-25 16:06:12 +03:00
|
|
|
Vector_Init(&includes, sizeof(IFile *));
|
1999-09-15 12:43:21 +04:00
|
|
|
#ifdef CLEANUP
|
2020-10-18 16:02:10 +03:00
|
|
|
targCmds = Lst_New();
|
1999-09-15 12:43:21 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 00:32:30 +03:00
|
|
|
/* Clean up the parsing module. */
|
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
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Destroy(targCmds, free);
|
2020-09-27 15:26:23 +03:00
|
|
|
assert(targets == NULL);
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Destroy(defIncPath, Dir_Destroy);
|
|
|
|
Lst_Destroy(sysIncPath, Dir_Destroy);
|
|
|
|
Lst_Destroy(parseIncPath, Dir_Destroy);
|
2020-10-25 16:06:12 +03:00
|
|
|
assert(includes.len == 0);
|
|
|
|
Vector_Done(&includes);
|
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.
|
|
|
|
*
|
|
|
|
*-----------------------------------------------------------------------
|
|
|
|
*/
|
2020-09-22 07:05:41 +03:00
|
|
|
GNodeList *
|
2002-06-15 22:24:55 +04:00
|
|
|
Parse_MainName(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-09-22 07:05:41 +03:00
|
|
|
GNodeList *mainList;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-10-18 16:02:10 +03:00
|
|
|
mainList = Lst_New();
|
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.");
|
2020-08-01 17:47:49 +03:00
|
|
|
/*NOTREACHED*/
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (mainNode->type & OP_DOUBLEDEP) {
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(mainList, mainNode);
|
|
|
|
Lst_AppendAll(mainList, mainNode->cohorts);
|
2020-10-17 21:36:56 +03:00
|
|
|
} else
|
2020-08-28 07:48:56 +03:00
|
|
|
Lst_Append(mainList, mainNode);
|
2002-02-18 02:53:46 +03:00
|
|
|
Var_Append(".TARGETS", mainNode->name, VAR_GLOBAL);
|
2020-07-03 11:02:55 +03:00
|
|
|
return mainList;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|