2024-05-31 08:50:11 +03:00
|
|
|
/* $NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 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
|
|
|
*
|
|
|
|
* 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
|
2021-02-02 01:16:57 +03:00
|
|
|
* handled by IncludeFile instead.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2021-12-31 04:34:45 +03:00
|
|
|
* Parse_VarAssign
|
|
|
|
* Try to parse the given line as 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
|
|
|
*
|
2023-05-10 18:57:16 +03:00
|
|
|
* Parse_MainName Populate the list of targets to create.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2010-12-25 07:57:07 +03:00
|
|
|
#include <sys/types.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>
|
|
|
|
|
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" */
|
2024-05-31 08:50:11 +03:00
|
|
|
MAKE_RCSID("$NetBSD: parse.c,v 1.728 2024/05/31 05:50:11 rillig Exp $");
|
2023-06-19 15:53:57 +03:00
|
|
|
|
|
|
|
/* Detects a multiple-inclusion guard in a makefile. */
|
|
|
|
typedef enum {
|
|
|
|
GS_START, /* at the beginning of the file */
|
|
|
|
GS_COND, /* after the guard condition */
|
|
|
|
GS_DONE, /* after the closing .endif */
|
|
|
|
GS_NO /* the file is not guarded */
|
|
|
|
} GuardState;
|
2010-12-13 06:32:25 +03:00
|
|
|
|
2024-01-07 14:39:04 +03:00
|
|
|
/* A file being parsed. */
|
2022-01-07 16:56:09 +03:00
|
|
|
typedef struct IncludedFile {
|
2021-12-13 08:25:04 +03:00
|
|
|
FStr name; /* absolute or relative to the cwd */
|
2022-02-05 02:22:19 +03:00
|
|
|
unsigned lineno; /* 1-based */
|
|
|
|
unsigned readLines; /* the number of physical lines that have
|
2022-01-08 23:21:34 +03:00
|
|
|
* been read from the file */
|
2022-02-05 02:22:19 +03:00
|
|
|
unsigned forHeadLineno; /* 1-based */
|
|
|
|
unsigned forBodyReadLines; /* the number of physical lines that have
|
2022-01-07 16:56:09 +03:00
|
|
|
* been read from the file above the body of
|
2022-01-08 23:21:34 +03:00
|
|
|
* the .for loop */
|
2022-09-24 19:13:48 +03:00
|
|
|
unsigned int condMinDepth; /* depth of nested 'if' directives, at the
|
|
|
|
* beginning of the file */
|
2022-01-02 05:39:55 +03:00
|
|
|
bool depending; /* state of doing_depend on EOF */
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2022-01-02 05:39:55 +03:00
|
|
|
Buffer buf; /* the file's content or the body of the .for
|
2022-03-03 22:55:27 +03:00
|
|
|
* loop; either empty or ends with '\n' */
|
2023-06-23 09:08:56 +03:00
|
|
|
char *buf_ptr; /* next char to be read from buf */
|
2021-12-08 02:56:06 +03:00
|
|
|
char *buf_end; /* buf_end[-1] == '\n' */
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2023-06-20 12:25:33 +03:00
|
|
|
GuardState guardState;
|
|
|
|
Guard *guard;
|
2023-06-19 15:53:57 +03:00
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
struct ForLoop *forLoop;
|
2022-01-07 16:56:09 +03:00
|
|
|
} IncludedFile;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2022-01-07 17:03:55 +03:00
|
|
|
/* Special attributes for target nodes. */
|
2020-10-18 20:19:54 +03:00
|
|
|
typedef enum ParseSpecial {
|
2020-12-05 22:46:04 +03:00
|
|
|
SP_ATTRIBUTE, /* Generic attribute */
|
|
|
|
SP_BEGIN, /* .BEGIN */
|
|
|
|
SP_DEFAULT, /* .DEFAULT */
|
|
|
|
SP_DELETE_ON_ERROR, /* .DELETE_ON_ERROR */
|
|
|
|
SP_END, /* .END */
|
|
|
|
SP_ERROR, /* .ERROR */
|
|
|
|
SP_IGNORE, /* .IGNORE */
|
|
|
|
SP_INCLUDES, /* .INCLUDES; not mentioned in the manual page */
|
|
|
|
SP_INTERRUPT, /* .INTERRUPT */
|
|
|
|
SP_LIBS, /* .LIBS; not mentioned in the manual page */
|
2021-12-28 17:06:42 +03:00
|
|
|
SP_MAIN, /* .MAIN and no user-specified targets to make */
|
2020-12-05 22:46:04 +03:00
|
|
|
SP_META, /* .META */
|
|
|
|
SP_MFLAGS, /* .MFLAGS or .MAKEFLAGS */
|
|
|
|
SP_NOMETA, /* .NOMETA */
|
|
|
|
SP_NOMETA_CMP, /* .NOMETA_CMP */
|
|
|
|
SP_NOPATH, /* .NOPATH */
|
2023-01-24 02:01:52 +03:00
|
|
|
SP_NOREADONLY, /* .NOREADONLY */
|
2020-12-05 22:46:04 +03:00
|
|
|
SP_NOT, /* Not special */
|
|
|
|
SP_NOTPARALLEL, /* .NOTPARALLEL or .NO_PARALLEL */
|
|
|
|
SP_NULL, /* .NULL; not mentioned in the manual page */
|
|
|
|
SP_OBJDIR, /* .OBJDIR */
|
|
|
|
SP_ORDER, /* .ORDER */
|
|
|
|
SP_PARALLEL, /* .PARALLEL; not mentioned in the manual page */
|
|
|
|
SP_PATH, /* .PATH or .PATH.suffix */
|
|
|
|
SP_PHONY, /* .PHONY */
|
|
|
|
SP_POSIX, /* .POSIX; not mentioned in the manual page */
|
|
|
|
SP_PRECIOUS, /* .PRECIOUS */
|
2023-01-24 02:01:52 +03:00
|
|
|
SP_READONLY, /* .READONLY */
|
2020-12-05 22:46:04 +03:00
|
|
|
SP_SHELL, /* .SHELL */
|
|
|
|
SP_SILENT, /* .SILENT */
|
|
|
|
SP_SINGLESHELL, /* .SINGLESHELL; not mentioned in the manual page */
|
|
|
|
SP_STALE, /* .STALE */
|
|
|
|
SP_SUFFIXES, /* .SUFFIXES */
|
2023-01-24 03:24:02 +03:00
|
|
|
SP_SYSPATH, /* .SYSPATH */
|
2020-12-05 22:46:04 +03:00
|
|
|
SP_WAIT /* .WAIT */
|
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
|
|
|
|
2022-01-27 09:02:59 +03:00
|
|
|
|
|
|
|
typedef enum VarAssignOp {
|
|
|
|
VAR_NORMAL, /* = */
|
|
|
|
VAR_APPEND, /* += */
|
|
|
|
VAR_DEFAULT, /* ?= */
|
|
|
|
VAR_SUBST, /* := */
|
|
|
|
VAR_SHELL /* != or :sh= */
|
|
|
|
} VarAssignOp;
|
|
|
|
|
|
|
|
typedef struct VarAssign {
|
|
|
|
char *varname; /* unexpanded */
|
|
|
|
VarAssignOp op;
|
|
|
|
const char *value; /* unexpanded */
|
|
|
|
} VarAssign;
|
|
|
|
|
|
|
|
static bool Parse_IsVar(const char *, VarAssign *);
|
2022-01-29 04:07:31 +03:00
|
|
|
static void Parse_Var(VarAssign *, GNode *);
|
2022-01-27 09:02:59 +03:00
|
|
|
|
2010-12-13 06:32:25 +03:00
|
|
|
/*
|
2022-01-07 23:50:35 +03:00
|
|
|
* The target to be made if no targets are specified in the command line.
|
|
|
|
* This is the first target defined in any of the makefiles.
|
2010-12-13 06:32:25 +03:00
|
|
|
*/
|
2022-01-07 23:50:35 +03:00
|
|
|
GNode *mainNode;
|
2010-12-13 06:32:25 +03:00
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
|
|
|
* During parsing, the targets from the left-hand side of the currently
|
2020-11-01 00:52:56 +03:00
|
|
|
* 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
|
|
|
*
|
2020-12-30 13:03:16 +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-12-30 13:03:16 +03:00
|
|
|
/*
|
|
|
|
* All shell commands for all targets, in no particular order and possibly
|
2024-05-26 00:07:48 +03:00
|
|
|
* with duplicate values. 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-12-30 13:03:16 +03:00
|
|
|
*/
|
2020-11-29 03:04:22 +03:00
|
|
|
static StringList targCmds = LST_INIT;
|
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
|
2022-01-07 17:03:55 +03:00
|
|
|
* is seen, then set to each successive source on the line.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2020-10-28 04:58:37 +03:00
|
|
|
static GNode *order_pred;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
static int parseErrors;
|
2010-12-13 06:32:25 +03:00
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
2021-01-27 02:44:56 +03:00
|
|
|
* The include chain of makefiles. At index 0 is the top-level makefile from
|
|
|
|
* the command line, followed by the included files or .for loops, up to and
|
|
|
|
* including the current file.
|
2020-09-14 22:59:47 +03:00
|
|
|
*
|
2021-01-27 02:44:56 +03:00
|
|
|
* See PrintStackTrace for how to interpret the data.
|
2020-09-14 22:59:47 +03:00
|
|
|
*/
|
2022-01-07 16:56:09 +03:00
|
|
|
static Vector /* of IncludedFile */ includes;
|
2020-10-25 16:06:12 +03:00
|
|
|
|
2021-02-05 08:46:27 +03:00
|
|
|
SearchPath *parseIncPath; /* directories for "..." includes */
|
|
|
|
SearchPath *sysIncPath; /* directories for <...> includes */
|
2020-10-31 12:47:27 +03:00
|
|
|
SearchPath *defSysIncPath; /* default for sysIncPath */
|
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
|
2023-05-10 18:57:16 +03:00
|
|
|
* if a target or source is special.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2010-12-13 06:36:39 +03:00
|
|
|
static const struct {
|
2021-12-28 18:03:10 +03:00
|
|
|
const char name[17];
|
|
|
|
ParseSpecial special; /* when used as a target */
|
|
|
|
GNodeType targetAttr; /* when used as a source */
|
1993-03-21 12:45:37 +03:00
|
|
|
} parseKeywords[] = {
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".BEGIN", SP_BEGIN, OP_NONE },
|
|
|
|
{ ".DEFAULT", SP_DEFAULT, OP_NONE },
|
|
|
|
{ ".DELETE_ON_ERROR", SP_DELETE_ON_ERROR, OP_NONE },
|
|
|
|
{ ".END", SP_END, OP_NONE },
|
|
|
|
{ ".ERROR", SP_ERROR, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".EXEC", SP_ATTRIBUTE, OP_EXEC },
|
|
|
|
{ ".IGNORE", SP_IGNORE, OP_IGNORE },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".INCLUDES", SP_INCLUDES, OP_NONE },
|
|
|
|
{ ".INTERRUPT", SP_INTERRUPT, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".INVISIBLE", SP_ATTRIBUTE, OP_INVISIBLE },
|
|
|
|
{ ".JOIN", SP_ATTRIBUTE, OP_JOIN },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".LIBS", SP_LIBS, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".MADE", SP_ATTRIBUTE, OP_MADE },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".MAIN", SP_MAIN, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".MAKE", SP_ATTRIBUTE, OP_MAKE },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".MAKEFLAGS", SP_MFLAGS, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".META", SP_META, OP_META },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".MFLAGS", SP_MFLAGS, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".NOMETA", SP_NOMETA, OP_NOMETA },
|
|
|
|
{ ".NOMETA_CMP", SP_NOMETA_CMP, OP_NOMETA_CMP },
|
|
|
|
{ ".NOPATH", SP_NOPATH, OP_NOPATH },
|
2023-01-24 02:01:52 +03:00
|
|
|
{ ".NOREADONLY", SP_NOREADONLY, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".NOTMAIN", SP_ATTRIBUTE, OP_NOTMAIN },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".NOTPARALLEL", SP_NOTPARALLEL, OP_NONE },
|
|
|
|
{ ".NO_PARALLEL", SP_NOTPARALLEL, OP_NONE },
|
|
|
|
{ ".NULL", SP_NULL, OP_NONE },
|
|
|
|
{ ".OBJDIR", SP_OBJDIR, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".OPTIONAL", SP_ATTRIBUTE, OP_OPTIONAL },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".ORDER", SP_ORDER, OP_NONE },
|
|
|
|
{ ".PARALLEL", SP_PARALLEL, OP_NONE },
|
|
|
|
{ ".PATH", SP_PATH, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".PHONY", SP_PHONY, OP_PHONY },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".POSIX", SP_POSIX, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".PRECIOUS", SP_PRECIOUS, OP_PRECIOUS },
|
2023-01-24 02:01:52 +03:00
|
|
|
{ ".READONLY", SP_READONLY, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".RECURSIVE", SP_ATTRIBUTE, OP_MAKE },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".SHELL", SP_SHELL, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".SILENT", SP_SILENT, OP_SILENT },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".SINGLESHELL", SP_SINGLESHELL, OP_NONE },
|
|
|
|
{ ".STALE", SP_STALE, OP_NONE },
|
|
|
|
{ ".SUFFIXES", SP_SUFFIXES, OP_NONE },
|
2023-01-24 03:24:02 +03:00
|
|
|
{ ".SYSPATH", SP_SYSPATH, OP_NONE },
|
2020-10-28 04:43:01 +03:00
|
|
|
{ ".USE", SP_ATTRIBUTE, OP_USE },
|
|
|
|
{ ".USEBEFORE", SP_ATTRIBUTE, OP_USEBEFORE },
|
2020-12-05 21:38:02 +03:00
|
|
|
{ ".WAIT", SP_WAIT, OP_NONE },
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
2022-04-18 18:06:27 +03:00
|
|
|
enum PosixState posix_state = PS_NOT_YET;
|
2010-12-25 07:57:07 +03:00
|
|
|
|
2023-06-20 12:25:33 +03:00
|
|
|
static HashTable /* full file name -> Guard */ guards;
|
2023-06-19 15:53:57 +03:00
|
|
|
|
2023-12-29 23:43:58 +03:00
|
|
|
|
|
|
|
static List *
|
|
|
|
Lst_New(void)
|
|
|
|
{
|
|
|
|
List *list = bmake_malloc(sizeof *list);
|
|
|
|
Lst_Init(list);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Lst_Free(List *list)
|
|
|
|
{
|
|
|
|
|
|
|
|
Lst_Done(list);
|
|
|
|
free(list);
|
|
|
|
}
|
|
|
|
|
2022-01-07 16:56:09 +03:00
|
|
|
static IncludedFile *
|
2022-01-02 05:39:55 +03:00
|
|
|
GetInclude(size_t i)
|
|
|
|
{
|
2022-09-24 19:09:04 +03:00
|
|
|
assert(i < includes.len);
|
2022-01-02 05:39:55 +03:00
|
|
|
return Vector_Get(&includes, i);
|
|
|
|
}
|
|
|
|
|
2024-01-06 02:22:06 +03:00
|
|
|
/* The makefile or the body of a .for loop that is currently being read. */
|
2022-01-07 16:56:09 +03:00
|
|
|
static IncludedFile *
|
2022-01-02 05:39:55 +03:00
|
|
|
CurFile(void)
|
|
|
|
{
|
|
|
|
return GetInclude(includes.len - 1);
|
|
|
|
}
|
|
|
|
|
2022-09-24 19:13:48 +03:00
|
|
|
unsigned int
|
|
|
|
CurFile_CondMinDepth(void)
|
|
|
|
{
|
|
|
|
return CurFile()->condMinDepth;
|
|
|
|
}
|
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
static Buffer
|
2022-06-11 01:42:47 +03:00
|
|
|
LoadFile(const char *path, int fd)
|
2020-10-31 12:47:27 +03:00
|
|
|
{
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
ssize_t n;
|
|
|
|
Buffer buf;
|
2022-01-02 00:19:37 +03:00
|
|
|
size_t bufSize;
|
|
|
|
struct stat st;
|
2020-10-31 12:47:27 +03:00
|
|
|
|
2022-01-02 00:19:37 +03:00
|
|
|
bufSize = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
|
2022-01-08 00:04:50 +03:00
|
|
|
st.st_size > 0 && st.st_size < 1024 * 1024 * 1024
|
2022-01-02 00:19:37 +03:00
|
|
|
? (size_t)st.st_size : 1024;
|
|
|
|
Buf_InitSize(&buf, bufSize);
|
2010-12-25 07:57:07 +03:00
|
|
|
|
2020-11-07 13:16:18 +03:00
|
|
|
for (;;) {
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
if (buf.len == buf.cap) {
|
2022-01-08 00:04:50 +03:00
|
|
|
if (buf.cap >= 512 * 1024 * 1024) {
|
2017-04-17 00:03:13 +03:00
|
|
|
Error("%s: file too large", path);
|
2020-12-27 14:47:04 +03:00
|
|
|
exit(2); /* Not 1 so -q can distinguish error */
|
2017-04-17 00:03:13 +03:00
|
|
|
}
|
2020-12-28 18:42:53 +03:00
|
|
|
Buf_Expand(&buf);
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
assert(buf.len < buf.cap);
|
|
|
|
n = read(fd, buf.data + buf.len, buf.cap - buf.len);
|
|
|
|
if (n < 0) {
|
2010-12-25 07:57:07 +03:00
|
|
|
Error("%s: read error: %s", path, strerror(errno));
|
2020-12-27 14:47:04 +03:00
|
|
|
exit(2); /* Not 1 so -q can distinguish error */
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
if (n == 0)
|
2010-12-25 07:57:07 +03:00
|
|
|
break;
|
2020-11-08 01:25:19 +03:00
|
|
|
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
buf.len += (size_t)n;
|
2010-12-25 23:46:18 +03:00
|
|
|
}
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
assert(buf.len <= buf.cap);
|
|
|
|
|
2024-01-03 23:24:16 +03:00
|
|
|
if (buf.len > 0 && !Buf_EndsWith(&buf, '\n'))
|
make(1): remove mmap for loading files, only allow files < 1 GiB
Using mmap is beneficial if the loaded data is read-only, or if it is
accessed in random order. Neither of these applies here. When loading
a file, make reads it strictly from top to bottom, once. During
parsing, the loaded data is modified in-place to insert '\0' and '\n'
for terminating strings and lines. Because of all of this, there is no
benefit in using mmap.
Reading the file using 2 calls to read(2) (one for the data, one for
checking for EOF) loads the data in a single pass, instead of producing
a page fault whenever the parser passes another page boundary.
Use a Buffer for loading the file data, to avoid calling bmake_realloc
directly.
Do not resize the loaded buffer at the end. Each loaded file is
short-lived anyway, and only a few files are loaded at the same time, so
there is no point in optimizing this part for low memory usage.
2020-12-28 18:21:33 +03:00
|
|
|
Buf_AddByte(&buf, '\n');
|
2010-12-25 07:57:07 +03:00
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
return buf; /* may not be null-terminated */
|
2010-12-25 07:57:07 +03:00
|
|
|
}
|
|
|
|
|
2022-01-29 12:38:26 +03:00
|
|
|
/*
|
|
|
|
* Print the current chain of .include and .for directives. In Parse_Fatal
|
|
|
|
* or other functions that already print the location, includingInnermost
|
|
|
|
* would be redundant, but in other cases like Error or Fatal it needs to be
|
|
|
|
* included.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PrintStackTrace(bool includingInnermost)
|
2021-01-27 02:44:56 +03:00
|
|
|
{
|
2022-01-07 16:56:09 +03:00
|
|
|
const IncludedFile *entries;
|
2021-01-27 02:44:56 +03:00
|
|
|
size_t i, n;
|
|
|
|
|
|
|
|
n = includes.len;
|
|
|
|
if (n == 0)
|
|
|
|
return;
|
2022-01-09 02:41:43 +03:00
|
|
|
|
2022-09-24 19:09:04 +03:00
|
|
|
entries = GetInclude(0);
|
2022-01-29 12:38:26 +03:00
|
|
|
if (!includingInnermost && entries[n - 1].forLoop == NULL)
|
2022-01-09 02:41:43 +03:00
|
|
|
n--; /* already in the diagnostic */
|
2021-01-27 02:44:56 +03:00
|
|
|
|
|
|
|
for (i = n; i-- > 0;) {
|
2022-01-07 16:56:09 +03:00
|
|
|
const IncludedFile *entry = entries + i;
|
2021-12-13 08:25:04 +03:00
|
|
|
const char *fname = entry->name.str;
|
2021-01-27 02:44:56 +03:00
|
|
|
char dirbuf[MAXPATHLEN + 1];
|
|
|
|
|
2023-05-10 19:10:02 +03:00
|
|
|
if (fname[0] != '/' && strcmp(fname, "(stdin)") != 0) {
|
|
|
|
const char *realPath = realpath(fname, dirbuf);
|
|
|
|
if (realPath != NULL)
|
|
|
|
fname = realPath;
|
|
|
|
}
|
2021-01-27 02:44:56 +03:00
|
|
|
|
2022-01-09 02:41:43 +03:00
|
|
|
if (entry->forLoop != NULL) {
|
2022-01-09 02:52:26 +03:00
|
|
|
char *details = ForLoop_Details(entry->forLoop);
|
2022-02-05 02:22:19 +03:00
|
|
|
debug_printf("\tin .for loop from %s:%u with %s\n",
|
2022-01-09 02:52:26 +03:00
|
|
|
fname, entry->forHeadLineno, details);
|
|
|
|
free(details);
|
2022-01-09 14:43:58 +03:00
|
|
|
} else if (i + 1 < n && entries[i + 1].forLoop != NULL) {
|
|
|
|
/* entry->lineno is not a useful line number */
|
|
|
|
} else
|
2022-02-05 02:22:19 +03:00
|
|
|
debug_printf("\tin %s:%u\n", fname, entry->lineno);
|
2021-01-27 02:44:56 +03:00
|
|
|
}
|
|
|
|
}
|
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. */
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 22:41:01 +03:00
|
|
|
IsEscaped(const char *line, const char *p)
|
2002-01-26 23:42:14 +03:00
|
|
|
{
|
2022-01-07 17:03:55 +03:00
|
|
|
bool escaped = false;
|
2021-12-28 19:35:43 +03:00
|
|
|
while (p > line && *--p == '\\')
|
2022-01-07 17:03:55 +03:00
|
|
|
escaped = !escaped;
|
|
|
|
return escaped;
|
2002-01-26 23:42:14 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
2023-12-19 22:33:39 +03:00
|
|
|
* Remember the location (filename and lineno) where the last command was
|
|
|
|
* added or where the node was mentioned in a .depend file.
|
2020-12-30 13:03:16 +03:00
|
|
|
*/
|
2020-09-05 18:04:09 +03:00
|
|
|
static void
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(GNode *gn)
|
2020-09-05 18:04:09 +03:00
|
|
|
{
|
2022-01-07 16:56:09 +03:00
|
|
|
IncludedFile *curFile = CurFile();
|
2021-12-13 08:25:04 +03:00
|
|
|
gn->fname = Str_Intern(curFile->name.str);
|
2022-01-08 23:21:34 +03:00
|
|
|
gn->lineno = curFile->lineno;
|
2020-09-05 18:04:09 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +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
|
2021-12-28 22:41:01 +03:00
|
|
|
FindKeyword(const char *str)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
int start = 0;
|
|
|
|
int end = sizeof parseKeywords / sizeof parseKeywords[0] - 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2022-01-02 00:04:15 +03:00
|
|
|
while (start <= end) {
|
2020-12-05 22:46:04 +03:00
|
|
|
int curr = start + (end - start) / 2;
|
|
|
|
int diff = strcmp(str, parseKeywords[curr].name);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (diff == 0)
|
|
|
|
return curr;
|
|
|
|
if (diff < 0)
|
|
|
|
end = curr - 1;
|
|
|
|
else
|
|
|
|
start = curr + 1;
|
2022-01-02 00:04:15 +03:00
|
|
|
}
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
return -1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2022-01-29 13:19:49 +03:00
|
|
|
void
|
2022-06-12 16:37:32 +03:00
|
|
|
PrintLocation(FILE *f, bool useVars, const GNode *gn)
|
2020-09-12 14:21:15 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
char dirbuf[MAXPATHLEN + 1];
|
2020-12-20 17:32:13 +03:00
|
|
|
FStr dir, base;
|
2022-06-12 16:37:32 +03:00
|
|
|
const char *fname;
|
|
|
|
unsigned lineno;
|
|
|
|
|
|
|
|
if (gn != NULL) {
|
|
|
|
fname = gn->fname;
|
|
|
|
lineno = gn->lineno;
|
|
|
|
} else if (includes.len > 0) {
|
|
|
|
IncludedFile *curFile = CurFile();
|
|
|
|
fname = curFile->name.str;
|
|
|
|
lineno = curFile->lineno;
|
|
|
|
} else
|
|
|
|
return;
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2022-01-20 22:24:53 +03:00
|
|
|
if (!useVars || fname[0] == '/' || strcmp(fname, "(stdin)") == 0) {
|
2022-02-05 02:22:19 +03:00
|
|
|
(void)fprintf(f, "\"%s\" line %u: ", fname, lineno);
|
2020-09-13 16:17:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2021-02-05 08:15:12 +03:00
|
|
|
dir = Var_Value(SCOPE_GLOBAL, ".PARSEDIR");
|
2020-12-20 17:32:13 +03:00
|
|
|
if (dir.str == NULL)
|
|
|
|
dir.str = ".";
|
|
|
|
if (dir.str[0] != '/')
|
|
|
|
dir.str = realpath(dir.str, dirbuf);
|
2020-09-13 16:17:44 +03:00
|
|
|
|
2021-02-05 08:15:12 +03:00
|
|
|
base = Var_Value(SCOPE_GLOBAL, ".PARSEFILE");
|
2020-12-20 17:32:13 +03:00
|
|
|
if (base.str == NULL)
|
|
|
|
base.str = str_basename(fname);
|
2020-09-12 14:21:15 +03:00
|
|
|
|
2022-02-05 02:22:19 +03:00
|
|
|
(void)fprintf(f, "\"%s/%s\" line %u: ", dir.str, base.str, lineno);
|
2020-12-20 17:32:13 +03:00
|
|
|
|
|
|
|
FStr_Done(&base);
|
|
|
|
FStr_Done(&dir);
|
2020-09-12 14:21:15 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 16:37:32 +03:00
|
|
|
static void MAKE_ATTR_PRINTFLIKE(5, 0)
|
|
|
|
ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn,
|
2022-02-10 00:03:13 +03:00
|
|
|
ParseErrorLevel level, const char *fmt, va_list ap)
|
1998-08-06 17:42:22 +04:00
|
|
|
{
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool fatal_warning_error_printed = false;
|
2001-01-10 18:54:00 +03:00
|
|
|
|
2008-10-29 18:37:08 +03:00
|
|
|
(void)fprintf(f, "%s: ", progname);
|
|
|
|
|
2022-06-12 16:37:32 +03:00
|
|
|
PrintLocation(f, useVars, gn);
|
2024-04-20 13:18:55 +03:00
|
|
|
fprintf(f, "%s", EvalStack_Details());
|
2022-02-10 00:03:13 +03:00
|
|
|
if (level == 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
|
|
|
|
2022-02-10 00:03:13 +03:00
|
|
|
if (level == PARSE_FATAL)
|
2022-01-07 11:37:23 +03:00
|
|
|
parseErrors++;
|
2022-02-10 00:03:13 +03:00
|
|
|
if (level == PARSE_WARNING && opts.parseWarnFatal) {
|
2022-01-07 11:37:23 +03:00
|
|
|
if (!fatal_warning_error_printed) {
|
|
|
|
Error("parsing warnings being treated as errors");
|
|
|
|
fatal_warning_error_printed = true;
|
|
|
|
}
|
|
|
|
parseErrors++;
|
2001-01-10 18:54:00 +03:00
|
|
|
}
|
2021-01-27 02:44:56 +03:00
|
|
|
|
2022-01-09 01:42:27 +03:00
|
|
|
if (DEBUG(PARSE))
|
2022-01-29 12:38:26 +03:00
|
|
|
PrintStackTrace(false);
|
1998-08-06 17:42:22 +04:00
|
|
|
}
|
|
|
|
|
2022-06-12 16:37:32 +03:00
|
|
|
static void MAKE_ATTR_PRINTFLIKE(3, 4)
|
|
|
|
ParseErrorInternal(const GNode *gn,
|
2022-02-10 00:03:13 +03:00
|
|
|
ParseErrorLevel level, const char *fmt, ...)
|
2014-09-08 00:55:34 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
(void)fflush(stdout);
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
va_start(ap, fmt);
|
2022-06-12 16:37:32 +03:00
|
|
|
ParseVErrorInternal(stderr, false, gn, level, fmt, ap);
|
2014-09-08 00:55:34 +04:00
|
|
|
va_end(ap);
|
|
|
|
|
2022-01-07 11:48:16 +03:00
|
|
|
if (opts.debug_file != stdout && opts.debug_file != stderr) {
|
2014-09-08 00:55:34 +04:00
|
|
|
va_start(ap, fmt);
|
2022-06-12 16:37:32 +03:00
|
|
|
ParseVErrorInternal(opts.debug_file, false, gn,
|
2022-02-10 00:03:13 +03:00
|
|
|
level, fmt, ap);
|
2014-09-08 00:55:34 +04:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Print a message, including location information.
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
*
|
|
|
|
* If the level is PARSE_FATAL, continue parsing until the end of the
|
|
|
|
* current top-level makefile, then exit (see Parse_File).
|
1998-08-06 17:42:22 +04:00
|
|
|
*
|
2020-12-30 13:03:16 +03:00
|
|
|
* Fmt is given without a trailing newline.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
2022-02-10 00:03:13 +03:00
|
|
|
Parse_Error(ParseErrorLevel level, const char *fmt, ...)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
va_list ap;
|
2009-01-16 23:50:24 +03:00
|
|
|
|
2010-04-30 03:12:21 +04:00
|
|
|
(void)fflush(stdout);
|
2022-01-08 00:00:49 +03:00
|
|
|
va_start(ap, fmt);
|
2022-06-12 16:37:32 +03:00
|
|
|
ParseVErrorInternal(stderr, true, NULL, level, fmt, ap);
|
1993-03-21 12:45:37 +03:00
|
|
|
va_end(ap);
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2022-01-07 11:48:16 +03:00
|
|
|
if (opts.debug_file != stdout && opts.debug_file != stderr) {
|
2007-01-02 00:47:32 +03:00
|
|
|
va_start(ap, fmt);
|
2022-06-12 16:37:32 +03:00
|
|
|
ParseVErrorInternal(opts.debug_file, true, NULL,
|
2022-02-10 00:03:13 +03:00
|
|
|
level, 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-12-30 13:03:16 +03:00
|
|
|
/*
|
2021-12-28 22:41:01 +03:00
|
|
|
* Handle an .info, .warning or .error directive. For an .error directive,
|
|
|
|
* exit immediately.
|
2020-12-30 13:03:16 +03:00
|
|
|
*/
|
2020-12-20 01:33:11 +03:00
|
|
|
static void
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleMessage(ParseErrorLevel level, const char *levelName, const char *umsg)
|
2010-04-07 04:11:27 +04:00
|
|
|
{
|
2020-12-13 04:07:54 +03:00
|
|
|
char *xmsg;
|
2020-10-17 22:10:07 +03:00
|
|
|
|
2020-12-20 01:33:11 +03:00
|
|
|
if (umsg[0] == '\0') {
|
|
|
|
Parse_Error(PARSE_FATAL, "Missing argument for \".%s\"",
|
|
|
|
levelName);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-17 22:10:07 +03:00
|
|
|
|
2023-02-15 00:38:31 +03:00
|
|
|
xmsg = Var_Subst(umsg, SCOPE_CMDLINE, VARE_WANTRES);
|
2020-12-05 22:46:04 +03:00
|
|
|
/* TODO: handle errors */
|
2020-10-17 22:10:07 +03:00
|
|
|
|
2020-12-13 04:07:54 +03:00
|
|
|
Parse_Error(level, "%s", xmsg);
|
|
|
|
free(xmsg);
|
2010-04-07 04:11:27 +04:00
|
|
|
|
2020-12-13 04:07:54 +03:00
|
|
|
if (level == PARSE_FATAL) {
|
2022-01-22 21:59:23 +03:00
|
|
|
PrintOnError(NULL, "\n");
|
2020-12-05 22:46:04 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
2010-04-07 04:11:27 +04:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
2022-01-07 23:37:25 +03:00
|
|
|
* Add the child to the parent's children, and for non-special targets, vice
|
2023-11-02 08:40:49 +03:00
|
|
|
* versa.
|
2020-12-30 13:03:16 +03:00
|
|
|
*/
|
2020-09-26 03:03:29 +03:00
|
|
|
static void
|
2021-04-03 14:08:40 +03:00
|
|
|
LinkSource(GNode *pgn, GNode *cgn, bool isSpecial)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(&pgn->cohorts))
|
|
|
|
pgn = pgn->cohorts.last->datum;
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
Lst_Append(&pgn->children, cgn);
|
|
|
|
pgn->unmade++;
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2023-11-02 08:40:49 +03:00
|
|
|
/*
|
|
|
|
* Special targets like .END do not need to be informed once the child
|
|
|
|
* target has been made.
|
|
|
|
*/
|
2020-12-05 22:46:04 +03:00
|
|
|
if (!isSpecial)
|
|
|
|
Lst_Append(&cgn->parents, pgn);
|
2020-09-14 20:44:57 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (DEBUG(PARSE)) {
|
2024-05-26 01:08:35 +03:00
|
|
|
debug_printf("Target \"%s\" depends on \"%s\"\n",
|
2021-12-27 22:06:07 +03:00
|
|
|
pgn->name, cgn->name);
|
2020-12-05 22:46:04 +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
|
2021-04-03 14:08:40 +03:00
|
|
|
LinkToTargets(GNode *gn, bool isSpecial)
|
2020-10-18 00:21:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next)
|
|
|
|
LinkSource(ln->datum, gn, isSpecial);
|
2020-10-18 00:21:37 +03:00
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-09-27 15:42:09 +03:00
|
|
|
TryApplyDependencyOperator(GNode *gn, GNodeType op)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
/*
|
2020-12-05 22:46:04 +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-12-05 22:46:04 +03:00
|
|
|
if ((op & OP_OPMASK) && (gn->type & OP_OPMASK) &&
|
|
|
|
((op & OP_OPMASK) != (gn->type & OP_OPMASK))) {
|
|
|
|
Parse_Error(PARSE_FATAL, "Inconsistent operator for %s",
|
|
|
|
gn->name);
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (op == OP_DOUBLEDEP && (gn->type & OP_OPMASK) == OP_DOUBLEDEP) {
|
|
|
|
/*
|
2023-05-10 18:57:16 +03:00
|
|
|
* If the node was on the left-hand side of a '::' operator,
|
2023-11-02 08:40:49 +03:00
|
|
|
* create a new node for the children and commands on this
|
|
|
|
* dependency line, since each of these dependency groups has
|
|
|
|
* its own attributes and commands, separate from the others.
|
2020-12-05 22:46:04 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
GNode *cohort;
|
1997-05-09 08:08:26 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* Propagate copied bits to the initial node. They'll be
|
|
|
|
* propagated back to the rest of the cohorts later.
|
|
|
|
*/
|
2022-09-27 20:46:58 +03:00
|
|
|
gn->type |= op & (unsigned)~OP_OPMASK;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
cohort = Targ_NewInternalNode(gn->name);
|
|
|
|
if (doing_depend)
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(cohort);
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Make the cohort invisible to avoid duplicating it
|
2020-12-05 22:46:04 +03:00
|
|
|
* into other variables. True, parents of this target won't
|
|
|
|
* tend to do anything with their local variables, but better
|
|
|
|
* safe than sorry.
|
|
|
|
*
|
|
|
|
* (I think this is pointless now, since the relevant list
|
|
|
|
* traversals will no longer see this node anyway. -mycroft)
|
|
|
|
*/
|
|
|
|
cohort->type = op | OP_INVISIBLE;
|
|
|
|
Lst_Append(&gn->cohorts, cohort);
|
|
|
|
cohort->centurion = gn;
|
|
|
|
gn->unmade_cohorts++;
|
|
|
|
snprintf(cohort->cohort_num, sizeof cohort->cohort_num, "#%d",
|
|
|
|
(unsigned int)gn->unmade_cohorts % 1000000);
|
|
|
|
} else {
|
2023-11-02 08:40:49 +03:00
|
|
|
gn->type |= op; /* preserve any previous flags */
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
1997-05-09 08:08:26 +04:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-09-27 15:42:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ApplyDependencyOperator(GNodeType op)
|
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next)
|
|
|
|
if (!TryApplyDependencyOperator(ln->datum, op))
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:03:45 +03:00
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Add a .WAIT node in the dependency list. After any dynamic dependencies
|
2020-12-05 22:03:45 +03:00
|
|
|
* (and filename globbing) have happened, it is given a dependency on each
|
|
|
|
* previous child, back until the previous .WAIT node. The next child won't
|
|
|
|
* be scheduled until the .WAIT node is built.
|
|
|
|
*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Give each .WAIT node a unique name (mainly for diagnostics).
|
2020-12-05 22:03:45 +03:00
|
|
|
*/
|
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceWait(bool isSpecial)
|
2020-12-05 22:03:45 +03:00
|
|
|
{
|
2022-01-09 14:28:04 +03:00
|
|
|
static unsigned wait_number = 0;
|
2022-05-07 20:25:28 +03:00
|
|
|
char name[6 + 10 + 1];
|
2020-12-05 22:03:45 +03:00
|
|
|
GNode *gn;
|
|
|
|
|
2022-05-07 20:25:28 +03:00
|
|
|
snprintf(name, sizeof name, ".WAIT_%u", ++wait_number);
|
|
|
|
gn = Targ_NewInternalNode(name);
|
2020-12-05 22:03:45 +03:00
|
|
|
if (doing_depend)
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(gn);
|
2020-12-05 22:03:45 +03:00
|
|
|
gn->type = OP_WAIT | OP_PHONY | OP_DEPENDS | OP_NOTMAIN;
|
|
|
|
LinkToTargets(gn, isSpecial);
|
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceKeyword(const char *src, ParseSpecial special)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:06:51 +03:00
|
|
|
int keywd;
|
2021-12-28 18:03:10 +03:00
|
|
|
GNodeType targetAttr;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:06:51 +03:00
|
|
|
if (*src != '.' || !ch_isupper(src[1]))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:06:51 +03:00
|
|
|
|
2021-12-28 22:41:01 +03:00
|
|
|
keywd = FindKeyword(src);
|
2020-12-05 22:06:51 +03:00
|
|
|
if (keywd == -1)
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:06:51 +03:00
|
|
|
|
2021-12-28 18:03:10 +03:00
|
|
|
targetAttr = parseKeywords[keywd].targetAttr;
|
|
|
|
if (targetAttr != OP_NONE) {
|
|
|
|
ApplyDependencyOperator(targetAttr);
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-12-05 22:06:51 +03:00
|
|
|
}
|
2021-12-28 18:03:10 +03:00
|
|
|
if (parseKeywords[keywd].special == SP_WAIT) {
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceWait(special != SP_NOT);
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/*
|
|
|
|
* In a line like ".MAIN: source1 source2", add all sources to the list of
|
|
|
|
* things to create, but only if the user didn't specify a target on the
|
|
|
|
* command line and .MAIN occurs for the first time.
|
|
|
|
*
|
|
|
|
* See HandleDependencyTargetSpecial, branch SP_MAIN.
|
|
|
|
* See unit-tests/cond-func-make-main.mk.
|
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceMain(const char *src)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
Lst_Append(&opts.create, bmake_strdup(src));
|
|
|
|
/*
|
|
|
|
* Add the name to the .TARGETS variable as well, so the user can
|
|
|
|
* employ that, if desired.
|
|
|
|
*/
|
2021-02-03 16:53:12 +03:00
|
|
|
Global_Append(".TARGETS", src);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
1995-12-16 08:03:09 +03:00
|
|
|
|
2022-02-10 00:09:24 +03:00
|
|
|
/*
|
|
|
|
* For the sources of a .ORDER target, create predecessor/successor links
|
|
|
|
* between the previous source and the current one.
|
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceOrder(const char *src)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
GNode *gn;
|
2022-02-10 00:09:24 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
gn = Targ_GetNode(src);
|
|
|
|
if (doing_depend)
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(gn);
|
2020-12-05 22:46:04 +03:00
|
|
|
if (order_pred != NULL) {
|
|
|
|
Lst_Append(&order_pred->order_succ, gn);
|
|
|
|
Lst_Append(&gn->order_pred, order_pred);
|
|
|
|
if (DEBUG(PARSE)) {
|
2021-12-27 22:06:07 +03:00
|
|
|
debug_printf(
|
2021-12-28 19:11:00 +03:00
|
|
|
"# .ORDER forces '%s' to be made before '%s'\n",
|
2021-12-27 22:06:07 +03:00
|
|
|
order_pred->name, gn->name);
|
2020-12-05 22:46:04 +03:00
|
|
|
Targ_PrintNode(order_pred, 0);
|
|
|
|
Targ_PrintNode(gn, 0);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2023-11-02 08:40:49 +03:00
|
|
|
/* The current source now becomes the predecessor for the next one. */
|
2020-12-05 22:46:04 +03:00
|
|
|
order_pred = gn;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
2006-10-16 01:17:27 +04:00
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/* The source is not an attribute, so find/create a node for it. */
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceOther(const char *src, GNodeType targetAttr,
|
2021-12-28 00:21:17 +03:00
|
|
|
ParseSpecial special)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
GNode *gn;
|
|
|
|
|
|
|
|
gn = Targ_GetNode(src);
|
|
|
|
if (doing_depend)
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(gn);
|
2021-12-28 18:03:10 +03:00
|
|
|
if (targetAttr != OP_NONE)
|
|
|
|
gn->type |= targetAttr;
|
2020-12-05 22:46:04 +03:00
|
|
|
else
|
2021-12-28 00:21:17 +03:00
|
|
|
LinkToTargets(gn, special != SP_NOT);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given the name of a source in a dependency line, figure out if it is an
|
2021-12-28 18:03:10 +03:00
|
|
|
* attribute (such as .SILENT) and if so, apply it to all targets. Otherwise
|
2020-10-05 22:27:47 +03:00
|
|
|
* 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.
|
2021-12-28 18:03:10 +03:00
|
|
|
* Otherwise, make the source a child of the targets.
|
2020-10-05 22:27:47 +03:00
|
|
|
*/
|
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySource(GNodeType targetAttr, const char *src,
|
2021-12-28 18:03:10 +03:00
|
|
|
ParseSpecial special)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-28 19:17:54 +03:00
|
|
|
if (ApplyDependencySourceKeyword(src, special))
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2021-12-28 00:21:17 +03:00
|
|
|
if (special == SP_MAIN)
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceMain(src);
|
2021-12-28 00:21:17 +03:00
|
|
|
else if (special == SP_ORDER)
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceOrder(src);
|
2020-12-05 22:46:04 +03:00
|
|
|
else
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySourceOther(src, targetAttr, special);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* If we have yet to decide on a main target to make, in the absence of any
|
2020-09-27 15:05:04 +03:00
|
|
|
* user input, we want the first target on the first dependency line that is
|
2020-12-05 22:46:04 +03:00
|
|
|
* actually a real target (i.e. isn't a .USE or .EXEC rule) to be made.
|
|
|
|
*/
|
2020-09-27 15:05:04 +03:00
|
|
|
static void
|
2022-01-07 23:37:25 +03:00
|
|
|
MaybeUpdateMainTarget(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
GNodeListNode *ln;
|
2020-09-27 15:05:04 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (mainNode != NULL)
|
|
|
|
return;
|
2020-09-27 15:05:04 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
2021-12-28 17:06:42 +03:00
|
|
|
if (GNode_IsMainCandidate(gn)) {
|
2023-11-02 08:55:22 +03:00
|
|
|
DEBUG1(MAKE, "Setting main node to \"%s\"\n",
|
|
|
|
gn->name);
|
2020-12-05 22:46:04 +03:00
|
|
|
mainNode = gn;
|
|
|
|
return;
|
|
|
|
}
|
2020-09-27 15:05:04 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:23:32 +03:00
|
|
|
static void
|
2023-08-19 14:09:02 +03:00
|
|
|
InvalidLineType(const char *line, const char *unexpanded_line)
|
2020-09-14 19:23:32 +03:00
|
|
|
{
|
2023-08-19 14:09:02 +03:00
|
|
|
if (unexpanded_line[0] == '.') {
|
|
|
|
const char *dirstart = unexpanded_line + 1;
|
2020-12-05 22:46:04 +03:00
|
|
|
const char *dirend;
|
|
|
|
cpp_skip_whitespace(&dirstart);
|
|
|
|
dirend = dirstart;
|
|
|
|
while (ch_isalnum(*dirend) || *dirend == '-')
|
|
|
|
dirend++;
|
|
|
|
Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"",
|
2020-09-14 19:23:32 +03:00
|
|
|
(int)(dirend - dirstart), dirstart);
|
2023-08-19 14:09:02 +03:00
|
|
|
} else if (strcmp(line, unexpanded_line) == 0)
|
2023-08-19 13:52:13 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Invalid line '%s'", line);
|
2023-08-19 14:09:02 +03:00
|
|
|
else
|
2023-11-02 08:55:22 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Invalid line '%s', expanded to '%s'",
|
2023-08-19 14:09:02 +03:00
|
|
|
unexpanded_line, line);
|
2020-09-14 19:23:32 +03:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:40:06 +03:00
|
|
|
static void
|
2021-12-28 20:58:41 +03:00
|
|
|
ParseDependencyTargetWord(char **pp, const char *lstart)
|
2020-09-14 19:40:06 +03:00
|
|
|
{
|
2023-11-02 08:55:22 +03:00
|
|
|
const char *p = *pp;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
while (*p != '\0') {
|
|
|
|
if ((ch_isspace(*p) || *p == '!' || *p == ':' || *p == '(')
|
|
|
|
&& !IsEscaped(lstart, p))
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
if (*p == '$') {
|
|
|
|
FStr val = Var_Parse(&p, SCOPE_CMDLINE,
|
2023-02-15 00:08:00 +03:00
|
|
|
VARE_PARSE_ONLY);
|
2023-11-02 08:40:49 +03:00
|
|
|
/* TODO: handle errors */
|
2022-01-07 12:28:35 +03:00
|
|
|
FStr_Done(&val);
|
2020-12-05 22:46:04 +03:00
|
|
|
} else
|
2023-11-02 08:55:22 +03:00
|
|
|
p++;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-09-14 19:40:06 +03:00
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
*pp += p - *pp;
|
2020-09-14 19:40:06 +03:00
|
|
|
}
|
|
|
|
|
2021-06-21 13:33:11 +03:00
|
|
|
/*
|
|
|
|
* Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER.
|
|
|
|
*
|
|
|
|
* See the tests deptgt-*.mk.
|
|
|
|
*/
|
2020-10-05 19:33:20 +03:00
|
|
|
static void
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleDependencyTargetSpecial(const char *targetName,
|
|
|
|
ParseSpecial *inout_special,
|
|
|
|
SearchPathList **inout_paths)
|
2020-10-05 19:33:20 +03:00
|
|
|
{
|
2021-12-28 00:21:17 +03:00
|
|
|
switch (*inout_special) {
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_PATH:
|
|
|
|
if (*inout_paths == NULL)
|
|
|
|
*inout_paths = Lst_New();
|
|
|
|
Lst_Append(*inout_paths, &dirSearchPath);
|
|
|
|
break;
|
2023-01-24 03:24:02 +03:00
|
|
|
case SP_SYSPATH:
|
|
|
|
if (*inout_paths == NULL)
|
|
|
|
*inout_paths = Lst_New();
|
|
|
|
Lst_Append(*inout_paths, sysIncPath);
|
|
|
|
break;
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_MAIN:
|
|
|
|
/*
|
|
|
|
* Allow targets from the command line to override the
|
|
|
|
* .MAIN node.
|
|
|
|
*/
|
|
|
|
if (!Lst_IsEmpty(&opts.create))
|
2021-12-28 00:21:17 +03:00
|
|
|
*inout_special = SP_NOT;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_BEGIN:
|
|
|
|
case SP_END:
|
|
|
|
case SP_STALE:
|
|
|
|
case SP_ERROR:
|
|
|
|
case SP_INTERRUPT: {
|
2021-01-23 15:03:25 +03:00
|
|
|
GNode *gn = Targ_GetNode(targetName);
|
2020-12-05 22:46:04 +03:00
|
|
|
if (doing_depend)
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(gn);
|
2020-12-05 22:46:04 +03:00
|
|
|
gn->type |= OP_NOTMAIN | OP_SPECIAL;
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SP_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. 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.
|
|
|
|
*/
|
|
|
|
GNode *gn = GNode_New(".DEFAULT");
|
|
|
|
gn->type |= OP_NOTMAIN | OP_TRANSFORM;
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
defaultNode = gn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SP_DELETE_ON_ERROR:
|
2021-04-03 14:08:40 +03:00
|
|
|
deleteOnError = true;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_NOTPARALLEL:
|
|
|
|
opts.maxJobs = 1;
|
|
|
|
break;
|
|
|
|
case SP_SINGLESHELL:
|
2021-04-03 14:08:40 +03:00
|
|
|
opts.compatMake = true;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_ORDER:
|
|
|
|
order_pred = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleDependencyTargetPath(const char *suffixName,
|
|
|
|
SearchPathList **inout_paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
SearchPath *path;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2021-01-23 15:03:25 +03:00
|
|
|
path = Suff_GetPath(suffixName);
|
2020-12-05 22:46:04 +03:00
|
|
|
if (path == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2021-01-23 15:03:25 +03:00
|
|
|
"Suffix '%s' not defined (yet)", suffixName);
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*inout_paths == NULL)
|
|
|
|
*inout_paths = Lst_New();
|
|
|
|
Lst_Append(*inout_paths, path);
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-07 17:03:55 +03:00
|
|
|
/* See if it's a special target and if so set inout_special to match it. */
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleDependencyTarget(const char *targetName,
|
|
|
|
ParseSpecial *inout_special,
|
|
|
|
GNodeType *inout_targetAttr,
|
|
|
|
SearchPathList **inout_paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
int keywd;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2021-01-23 15:03:25 +03:00
|
|
|
if (!(targetName[0] == '.' && ch_isupper(targetName[1])))
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* See if the target is a special target that must have it
|
|
|
|
* or its sources handled specially.
|
|
|
|
*/
|
2021-12-28 22:41:01 +03:00
|
|
|
keywd = FindKeyword(targetName);
|
2020-12-05 22:46:04 +03:00
|
|
|
if (keywd != -1) {
|
2021-12-28 00:21:17 +03:00
|
|
|
if (*inout_special == SP_PATH &&
|
2021-12-28 18:03:10 +03:00
|
|
|
parseKeywords[keywd].special != SP_PATH) {
|
2020-12-05 22:46:04 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Mismatched special targets");
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2021-12-28 18:03:10 +03:00
|
|
|
*inout_special = parseKeywords[keywd].special;
|
|
|
|
*inout_targetAttr = parseKeywords[keywd].targetAttr;
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleDependencyTargetSpecial(targetName, inout_special,
|
2020-12-05 22:46:04 +03:00
|
|
|
inout_paths);
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2021-01-23 15:03:25 +03:00
|
|
|
} else if (strncmp(targetName, ".PATH", 5) == 0) {
|
2021-12-28 00:21:17 +03:00
|
|
|
*inout_special = SP_PATH;
|
2021-12-28 22:41:01 +03:00
|
|
|
if (!HandleDependencyTargetPath(targetName + 5, inout_paths))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
2020-10-05 19:33:20 +03:00
|
|
|
|
2022-06-11 19:47:24 +03:00
|
|
|
static void
|
|
|
|
HandleSingleDependencyTargetMundane(const char *name)
|
|
|
|
{
|
|
|
|
GNode *gn = Suff_IsTransform(name)
|
|
|
|
? Suff_AddTransform(name)
|
|
|
|
: Targ_GetNode(name);
|
|
|
|
if (doing_depend)
|
|
|
|
RememberLocation(gn);
|
|
|
|
|
|
|
|
Lst_Append(targets, gn);
|
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2022-06-11 20:41:35 +03:00
|
|
|
HandleDependencyTargetMundane(const char *targetName)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-01-23 15:03:25 +03:00
|
|
|
if (Dir_HasWildcards(targetName)) {
|
2022-06-11 20:41:35 +03:00
|
|
|
StringList targetNames = LST_INIT;
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
SearchPath *emptyPath = SearchPath_New();
|
2021-12-28 19:59:09 +03:00
|
|
|
SearchPath_Expand(emptyPath, targetName, &targetNames);
|
2020-12-05 22:46:04 +03:00
|
|
|
SearchPath_Free(emptyPath);
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2022-06-11 20:41:35 +03:00
|
|
|
while (!Lst_IsEmpty(&targetNames)) {
|
|
|
|
char *targName = Lst_Dequeue(&targetNames);
|
|
|
|
HandleSingleDependencyTargetMundane(targName);
|
2022-06-11 20:58:15 +03:00
|
|
|
free(targName);
|
2022-06-11 20:41:35 +03:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
HandleSingleDependencyTargetMundane(targetName);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-12-28 22:43:42 +03:00
|
|
|
SkipExtraTargets(char **pp, const char *lstart)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-04-03 14:08:40 +03:00
|
|
|
bool warning = false;
|
2022-01-07 17:03:55 +03:00
|
|
|
const char *p = *pp;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2022-01-07 17:03:55 +03:00
|
|
|
while (*p != '\0') {
|
|
|
|
if (!IsEscaped(lstart, p) && (*p == '!' || *p == ':'))
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
2022-01-07 17:03:55 +03:00
|
|
|
if (IsEscaped(lstart, p) || (*p != ' ' && *p != '\t'))
|
2021-04-03 14:08:40 +03:00
|
|
|
warning = true;
|
2022-01-07 17:03:55 +03:00
|
|
|
p++;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2023-01-03 03:00:45 +03:00
|
|
|
if (warning) {
|
|
|
|
const char *start = *pp;
|
|
|
|
cpp_skip_whitespace(&start);
|
|
|
|
Parse_Error(PARSE_WARNING, "Extra target '%.*s' ignored",
|
|
|
|
(int)(p - start), start);
|
|
|
|
}
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2022-01-07 17:03:55 +03:00
|
|
|
*pp += p - *pp;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-01-07 17:03:55 +03:00
|
|
|
CheckSpecialMundaneMixture(ParseSpecial special)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-28 00:21:17 +03:00
|
|
|
switch (special) {
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_DEFAULT:
|
|
|
|
case SP_STALE:
|
|
|
|
case SP_BEGIN:
|
|
|
|
case SP_END:
|
|
|
|
case SP_ERROR:
|
|
|
|
case SP_INTERRUPT:
|
|
|
|
/*
|
|
|
|
* These create nodes on which to hang commands, so targets
|
|
|
|
* shouldn't be empty.
|
|
|
|
*/
|
|
|
|
case SP_NOT:
|
2022-02-10 00:09:24 +03:00
|
|
|
/* Nothing special here -- targets may be empty. */
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
2021-12-15 13:12:20 +03:00
|
|
|
default:
|
|
|
|
Parse_Error(PARSE_WARNING,
|
|
|
|
"Special and mundane targets don't mix. "
|
|
|
|
"Mundane ones ignored");
|
|
|
|
break;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-21 13:42:06 +03:00
|
|
|
/*
|
|
|
|
* In a dependency line like 'targets: sources' or 'targets! sources', parse
|
|
|
|
* the operator ':', '::' or '!' from between the targets and the sources.
|
|
|
|
*/
|
2021-12-14 03:02:57 +03:00
|
|
|
static GNodeType
|
|
|
|
ParseDependencyOp(char **pp)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-14 03:02:57 +03:00
|
|
|
if (**pp == '!')
|
|
|
|
return (*pp)++, OP_FORCE;
|
2022-07-24 23:25:23 +03:00
|
|
|
if (**pp == ':' && (*pp)[1] == ':')
|
2022-01-07 23:37:25 +03:00
|
|
|
return *pp += 2, OP_DOUBLEDEP;
|
2022-07-24 23:25:23 +03:00
|
|
|
else if (**pp == ':')
|
2021-12-14 03:02:57 +03:00
|
|
|
return (*pp)++, OP_DEPENDS;
|
2022-07-24 23:25:23 +03:00
|
|
|
else
|
|
|
|
return OP_NONE;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2020-10-19 23:51:18 +03:00
|
|
|
static void
|
2023-01-24 03:24:02 +03:00
|
|
|
ClearPaths(ParseSpecial special, SearchPathList *paths)
|
2020-10-19 23:51:18 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
if (paths != NULL) {
|
|
|
|
SearchPathListNode *ln;
|
|
|
|
for (ln = paths->first; ln != NULL; ln = ln->next)
|
|
|
|
SearchPath_Clear(ln->datum);
|
|
|
|
}
|
2023-01-24 03:24:02 +03:00
|
|
|
if (special == SP_SYSPATH)
|
|
|
|
Dir_SetSYSPATH();
|
|
|
|
else
|
|
|
|
Dir_SetPATH();
|
2020-10-19 23:51:18 +03:00
|
|
|
}
|
|
|
|
|
2022-06-11 01:23:19 +03:00
|
|
|
static char *
|
|
|
|
FindInDirOfIncludingFile(const char *file)
|
|
|
|
{
|
|
|
|
char *fullname, *incdir, *slash, *newName;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fullname = NULL;
|
|
|
|
incdir = bmake_strdup(CurFile()->name.str);
|
|
|
|
slash = strrchr(incdir, '/');
|
|
|
|
if (slash != NULL) {
|
|
|
|
*slash = '\0';
|
|
|
|
/*
|
|
|
|
* Now do lexical processing of leading "../" on the
|
|
|
|
* filename.
|
|
|
|
*/
|
|
|
|
for (i = 0; strncmp(file + i, "../", 3) == 0; i += 3) {
|
|
|
|
slash = strrchr(incdir + 1, '/');
|
|
|
|
if (slash == NULL || strcmp(slash, "/..") == 0)
|
|
|
|
break;
|
|
|
|
*slash = '\0';
|
|
|
|
}
|
|
|
|
newName = str_concat3(incdir, "/", file + i);
|
|
|
|
fullname = Dir_FindFile(newName, parseIncPath);
|
|
|
|
if (fullname == NULL)
|
|
|
|
fullname = Dir_FindFile(newName, &dirSearchPath);
|
|
|
|
free(newName);
|
|
|
|
}
|
|
|
|
free(incdir);
|
|
|
|
return fullname;
|
|
|
|
}
|
|
|
|
|
2022-06-11 01:35:05 +03:00
|
|
|
static char *
|
|
|
|
FindInQuotPath(const char *file)
|
|
|
|
{
|
|
|
|
const char *suff;
|
|
|
|
SearchPath *suffPath;
|
|
|
|
char *fullname;
|
|
|
|
|
|
|
|
fullname = FindInDirOfIncludingFile(file);
|
|
|
|
if (fullname == NULL &&
|
|
|
|
(suff = strrchr(file, '.')) != NULL &&
|
|
|
|
(suffPath = Suff_GetPath(suff)) != NULL)
|
|
|
|
fullname = Dir_FindFile(file, suffPath);
|
|
|
|
if (fullname == NULL)
|
|
|
|
fullname = Dir_FindFile(file, parseIncPath);
|
|
|
|
if (fullname == NULL)
|
|
|
|
fullname = Dir_FindFile(file, &dirSearchPath);
|
|
|
|
return fullname;
|
|
|
|
}
|
|
|
|
|
2023-06-19 20:30:56 +03:00
|
|
|
static bool
|
|
|
|
SkipGuarded(const char *fullname)
|
|
|
|
{
|
2023-06-20 12:25:33 +03:00
|
|
|
Guard *guard = HashTable_FindValue(&guards, fullname);
|
|
|
|
if (guard != NULL && guard->kind == GK_VARIABLE
|
|
|
|
&& GNode_ValueDirect(SCOPE_GLOBAL, guard->name) != NULL)
|
|
|
|
goto skip;
|
|
|
|
if (guard != NULL && guard->kind == GK_TARGET
|
|
|
|
&& Targ_FindNode(guard->name) != NULL)
|
|
|
|
goto skip;
|
2023-06-19 20:30:56 +03:00
|
|
|
return false;
|
2023-06-20 12:25:33 +03:00
|
|
|
|
|
|
|
skip:
|
|
|
|
DEBUG2(PARSE, "Skipping '%s' because '%s' is defined\n",
|
|
|
|
fullname, guard->name);
|
|
|
|
return true;
|
2023-06-19 20:30:56 +03:00
|
|
|
}
|
|
|
|
|
2022-03-26 00:16:04 +03:00
|
|
|
/*
|
|
|
|
* Handle one of the .[-ds]include directives by remembering the current file
|
|
|
|
* and pushing the included file on the stack. After the included file has
|
|
|
|
* finished, parsing continues with the including file; see Parse_PushInput
|
|
|
|
* and ParseEOF.
|
|
|
|
*
|
|
|
|
* System includes are looked up in sysIncPath, any other includes are looked
|
|
|
|
* up in the parsedir and then in the directories specified by the -I command
|
|
|
|
* line options.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
IncludeFile(const char *file, bool isSystem, bool depinc, bool silent)
|
|
|
|
{
|
|
|
|
Buffer buf;
|
|
|
|
char *fullname; /* full pathname of file */
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fullname = file[0] == '/' ? bmake_strdup(file) : NULL;
|
|
|
|
|
2022-06-11 01:35:05 +03:00
|
|
|
if (fullname == NULL && !isSystem)
|
|
|
|
fullname = FindInQuotPath(file);
|
2022-03-26 00:16:04 +03:00
|
|
|
|
|
|
|
if (fullname == NULL) {
|
|
|
|
SearchPath *path = Lst_IsEmpty(&sysIncPath->dirs)
|
|
|
|
? defSysIncPath : sysIncPath;
|
2024-05-19 23:09:40 +03:00
|
|
|
fullname = Dir_FindInclude(file, path);
|
2022-03-26 00:16:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fullname == NULL) {
|
|
|
|
if (!silent)
|
|
|
|
Parse_Error(PARSE_FATAL, "Could not find %s", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-19 20:30:56 +03:00
|
|
|
if (SkipGuarded(fullname))
|
2024-05-25 03:00:25 +03:00
|
|
|
goto done;
|
2023-06-19 15:53:57 +03:00
|
|
|
|
2022-06-11 01:35:05 +03:00
|
|
|
if ((fd = open(fullname, O_RDONLY)) == -1) {
|
2022-03-26 00:16:04 +03:00
|
|
|
if (!silent)
|
|
|
|
Parse_Error(PARSE_FATAL, "Cannot open %s", fullname);
|
2024-05-25 03:00:25 +03:00
|
|
|
goto done;
|
2022-03-26 00:16:04 +03:00
|
|
|
}
|
|
|
|
|
2022-06-11 01:42:47 +03:00
|
|
|
buf = LoadFile(fullname, fd);
|
2022-03-26 00:16:04 +03:00
|
|
|
(void)close(fd);
|
|
|
|
|
|
|
|
Parse_PushInput(fullname, 1, 0, buf, NULL);
|
|
|
|
if (depinc)
|
|
|
|
doing_depend = depinc; /* only turn it on */
|
2024-05-25 03:00:25 +03:00
|
|
|
done:
|
2022-03-26 00:16:04 +03:00
|
|
|
free(fullname);
|
|
|
|
}
|
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/* Handle a "dependency" line like '.SPECIAL:' without any sources. */
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2022-01-07 23:37:25 +03:00
|
|
|
HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-28 00:21:17 +03:00
|
|
|
switch (special) {
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_SUFFIXES:
|
|
|
|
Suff_ClearSuffixes();
|
|
|
|
break;
|
|
|
|
case SP_PRECIOUS:
|
2021-04-03 14:08:40 +03:00
|
|
|
allPrecious = true;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_IGNORE:
|
2021-04-03 14:08:40 +03:00
|
|
|
opts.ignoreErrors = true;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_SILENT:
|
2021-12-27 21:26:22 +03:00
|
|
|
opts.silent = true;
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_PATH:
|
2023-01-24 03:24:02 +03:00
|
|
|
case SP_SYSPATH:
|
|
|
|
ClearPaths(special, paths);
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_POSIX:
|
2022-04-18 18:06:27 +03:00
|
|
|
if (posix_state == PS_NOW_OR_NEVER) {
|
2022-04-18 19:09:05 +03:00
|
|
|
/*
|
|
|
|
* With '-r', 'posix.mk' (if it exists)
|
|
|
|
* can effectively substitute for 'sys.mk',
|
|
|
|
* otherwise it is an extension.
|
|
|
|
*/
|
2022-04-18 18:06:27 +03:00
|
|
|
Global_Set("%POSIX", "1003.2");
|
|
|
|
IncludeFile("posix.mk", true, false, true);
|
2022-03-26 00:16:04 +03:00
|
|
|
}
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2020-10-19 23:55:30 +03:00
|
|
|
static void
|
|
|
|
AddToPaths(const char *dir, SearchPathList *paths)
|
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
if (paths != NULL) {
|
|
|
|
SearchPathListNode *ln;
|
|
|
|
for (ln = paths->first; ln != NULL; ln = ln->next)
|
2021-01-23 14:34:41 +03:00
|
|
|
(void)SearchPath_Add(ln->datum, dir);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-10-19 23:55:30 +03:00
|
|
|
}
|
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
2022-01-01 22:44:05 +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.
|
2020-10-05 22:27:47 +03:00
|
|
|
*/
|
|
|
|
static void
|
2022-01-07 11:48:16 +03:00
|
|
|
ParseDependencySourceSpecial(ParseSpecial special, const char *word,
|
2021-04-04 13:13:09 +03:00
|
|
|
SearchPathList *paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-28 00:21:17 +03:00
|
|
|
switch (special) {
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_SUFFIXES:
|
2022-01-07 23:54:45 +03:00
|
|
|
Suff_AddSuffix(word);
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
case SP_PATH:
|
2023-11-02 08:55:22 +03:00
|
|
|
case SP_SYSPATH:
|
2020-12-05 22:46:04 +03:00
|
|
|
AddToPaths(word, paths);
|
|
|
|
break;
|
|
|
|
case SP_INCLUDES:
|
|
|
|
Suff_AddInclude(word);
|
|
|
|
break;
|
|
|
|
case SP_LIBS:
|
|
|
|
Suff_AddLib(word);
|
|
|
|
break;
|
2023-01-24 02:01:52 +03:00
|
|
|
case SP_NOREADONLY:
|
|
|
|
Var_ReadOnly(word, false);
|
|
|
|
break;
|
2020-12-05 22:46:04 +03:00
|
|
|
case SP_NULL:
|
|
|
|
Suff_SetNull(word);
|
|
|
|
break;
|
|
|
|
case SP_OBJDIR:
|
2021-04-03 14:08:40 +03:00
|
|
|
Main_SetObjdir(false, "%s", word);
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
2023-01-24 02:01:52 +03:00
|
|
|
case SP_READONLY:
|
|
|
|
Var_ReadOnly(word, true);
|
|
|
|
break;
|
2020-12-05 22:46:04 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2021-12-28 22:13:40 +03:00
|
|
|
static bool
|
|
|
|
ApplyDependencyTarget(char *name, char *nameEnd, ParseSpecial *inout_special,
|
|
|
|
GNodeType *inout_targetAttr,
|
|
|
|
SearchPathList **inout_paths)
|
|
|
|
{
|
2023-11-02 08:55:22 +03:00
|
|
|
char savedNameEnd = *nameEnd;
|
2021-12-28 22:13:40 +03:00
|
|
|
*nameEnd = '\0';
|
|
|
|
|
2021-12-28 22:41:01 +03:00
|
|
|
if (!HandleDependencyTarget(name, inout_special,
|
2021-12-28 22:13:40 +03:00
|
|
|
inout_targetAttr, inout_paths))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (*inout_special == SP_NOT && *name != '\0')
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleDependencyTargetMundane(name);
|
2021-12-28 22:13:40 +03:00
|
|
|
else if (*inout_special == SP_PATH && *name != '.' && *name != '\0')
|
|
|
|
Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", name);
|
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
*nameEnd = savedNameEnd;
|
2021-12-28 22:13:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2022-10-01 12:25:06 +03:00
|
|
|
ParseDependencyTargets(char **pp,
|
2021-04-04 13:13:09 +03:00
|
|
|
const char *lstart,
|
2021-12-28 00:21:17 +03:00
|
|
|
ParseSpecial *inout_special,
|
2021-12-28 18:03:10 +03:00
|
|
|
GNodeType *inout_targetAttr,
|
2023-08-19 14:09:02 +03:00
|
|
|
SearchPathList **inout_paths,
|
|
|
|
const char *unexpanded_line)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2022-10-01 12:25:06 +03:00
|
|
|
char *p = *pp;
|
2014-09-18 12:06:13 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (;;) {
|
2022-10-01 12:25:06 +03:00
|
|
|
char *tgt = p;
|
2022-01-07 12:35:11 +03:00
|
|
|
|
2022-10-01 12:25:06 +03:00
|
|
|
ParseDependencyTargetWord(&p, lstart);
|
2006-12-03 23:40:44 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* If the word is followed by a left parenthesis, it's the
|
2021-12-28 20:30:11 +03:00
|
|
|
* name of one or more files inside an archive.
|
2020-12-05 22:46:04 +03:00
|
|
|
*/
|
2022-10-01 12:25:06 +03:00
|
|
|
if (!IsEscaped(lstart, p) && *p == '(') {
|
|
|
|
p = tgt;
|
|
|
|
if (!Arch_ParseArchive(&p, targets, SCOPE_CMDLINE)) {
|
2020-12-05 22:46:04 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Error in archive specification: \"%s\"",
|
|
|
|
tgt);
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2022-10-01 12:25:06 +03:00
|
|
|
if (*p == '\0') {
|
2023-08-19 14:09:02 +03:00
|
|
|
InvalidLineType(lstart, unexpanded_line);
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2014-09-18 12:06:13 +04:00
|
|
|
|
2022-10-01 12:25:06 +03:00
|
|
|
if (!ApplyDependencyTarget(tgt, p, inout_special,
|
2021-12-28 18:03:10 +03:00
|
|
|
inout_targetAttr, inout_paths))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-10-05 19:54:41 +03:00
|
|
|
|
2021-12-28 00:21:17 +03:00
|
|
|
if (*inout_special != SP_NOT && *inout_special != SP_PATH)
|
2022-10-01 12:25:06 +03:00
|
|
|
SkipExtraTargets(&p, lstart);
|
2020-12-05 22:46:04 +03:00
|
|
|
else
|
2022-10-01 12:25:06 +03:00
|
|
|
pp_skip_whitespace(&p);
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2022-10-01 12:25:06 +03:00
|
|
|
if (*p == '\0')
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
2022-10-01 12:25:06 +03:00
|
|
|
if ((*p == '!' || *p == ':') && !IsEscaped(lstart, p))
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2022-10-01 12:25:06 +03:00
|
|
|
*pp = p;
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-12-28 20:39:04 +03:00
|
|
|
ParseDependencySourcesSpecial(char *start,
|
2021-12-28 00:21:17 +03:00
|
|
|
ParseSpecial special, SearchPathList *paths)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
while (*start != '\0') {
|
2023-11-02 08:55:22 +03:00
|
|
|
char savedEnd;
|
2021-12-28 20:39:04 +03:00
|
|
|
char *end = start;
|
2020-12-05 22:46:04 +03:00
|
|
|
while (*end != '\0' && !ch_isspace(*end))
|
|
|
|
end++;
|
2023-11-02 08:55:22 +03:00
|
|
|
savedEnd = *end;
|
2020-12-05 22:46:04 +03:00
|
|
|
*end = '\0';
|
2021-12-28 00:21:17 +03:00
|
|
|
ParseDependencySourceSpecial(special, start, paths);
|
2023-11-02 08:55:22 +03:00
|
|
|
*end = savedEnd;
|
|
|
|
if (savedEnd != '\0')
|
2020-12-05 22:46:04 +03:00
|
|
|
end++;
|
|
|
|
pp_skip_whitespace(&end);
|
|
|
|
start = end;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-27 09:02:59 +03:00
|
|
|
static void
|
|
|
|
LinkVarToTargets(VarAssign *var)
|
|
|
|
{
|
|
|
|
GNodeListNode *ln;
|
|
|
|
|
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next)
|
2022-01-29 04:07:31 +03:00
|
|
|
Parse_Var(var, ln->datum);
|
2022-01-27 09:02:59 +03:00
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 20:39:04 +03:00
|
|
|
ParseDependencySourcesMundane(char *start,
|
2021-12-28 18:03:10 +03:00
|
|
|
ParseSpecial special, GNodeType targetAttr)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
while (*start != '\0') {
|
2021-12-28 20:39:04 +03:00
|
|
|
char *end = start;
|
2022-01-27 09:02:59 +03:00
|
|
|
VarAssign var;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for local variable assignment,
|
|
|
|
* rest of the line is the value.
|
|
|
|
*/
|
|
|
|
if (Parse_IsVar(start, &var)) {
|
2023-11-02 08:55:22 +03:00
|
|
|
bool targetVarsEnabled = GetBooleanExpr(
|
2022-01-27 13:34:55 +03:00
|
|
|
"${.MAKE.TARGET_LOCAL_VARIABLES}", true);
|
2022-01-27 09:02:59 +03:00
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
if (targetVarsEnabled)
|
2022-01-27 09:02:59 +03:00
|
|
|
LinkVarToTargets(&var);
|
|
|
|
free(var.varname);
|
2023-11-02 08:55:22 +03:00
|
|
|
if (targetVarsEnabled)
|
2022-01-27 09:02:59 +03:00
|
|
|
return true;
|
|
|
|
}
|
2022-01-27 13:34:55 +03:00
|
|
|
|
2020-10-05 22:27:47 +03:00
|
|
|
/*
|
2020-12-05 22:46:04 +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-05 22:27:47 +03:00
|
|
|
*/
|
2020-12-05 22:46:04 +03:00
|
|
|
for (; *end != '\0' && !ch_isspace(*end); end++) {
|
|
|
|
if (*end == '(' && end > start && end[-1] != '$') {
|
|
|
|
/*
|
|
|
|
* Only stop for a left parenthesis if it
|
|
|
|
* isn't at the start of a word (that'll be
|
|
|
|
* for variable changes later) and isn't
|
|
|
|
* preceded by a dollar sign (a dynamic
|
|
|
|
* source).
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*end == '(') {
|
|
|
|
GNodeList sources = LST_INIT;
|
2021-02-05 00:33:13 +03:00
|
|
|
if (!Arch_ParseArchive(&start, &sources,
|
|
|
|
SCOPE_CMDLINE)) {
|
2020-12-05 22:46:04 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Error in source archive spec \"%s\"",
|
|
|
|
start);
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!Lst_IsEmpty(&sources)) {
|
|
|
|
GNode *gn = Lst_Dequeue(&sources);
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySource(targetAttr, gn->name,
|
2021-12-28 18:03:10 +03:00
|
|
|
special);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
Lst_Done(&sources);
|
|
|
|
end = start;
|
|
|
|
} else {
|
|
|
|
if (*end != '\0') {
|
|
|
|
*end = '\0';
|
|
|
|
end++;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2021-12-28 19:17:54 +03:00
|
|
|
ApplyDependencySource(targetAttr, start, special);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
pp_skip_whitespace(&end);
|
|
|
|
start = end;
|
2020-10-05 19:54:41 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-21 13:33:11 +03:00
|
|
|
/*
|
2022-01-07 12:49:43 +03:00
|
|
|
* From a dependency line like 'targets: sources', parse the sources.
|
2021-06-21 13:33:11 +03:00
|
|
|
*
|
|
|
|
* See the tests depsrc-*.mk.
|
|
|
|
*/
|
2021-06-21 13:29:08 +03:00
|
|
|
static void
|
2021-12-28 20:39:04 +03:00
|
|
|
ParseDependencySources(char *p, GNodeType targetAttr,
|
2021-12-28 00:21:17 +03:00
|
|
|
ParseSpecial special, SearchPathList **inout_paths)
|
2021-06-21 13:29:08 +03:00
|
|
|
{
|
2021-12-28 20:39:04 +03:00
|
|
|
if (*p == '\0') {
|
2022-01-07 23:37:25 +03:00
|
|
|
HandleDependencySourcesEmpty(special, *inout_paths);
|
2021-12-28 00:21:17 +03:00
|
|
|
} else if (special == SP_MFLAGS) {
|
2021-12-28 20:39:04 +03:00
|
|
|
Main_ParseArgLine(p);
|
2022-01-07 12:49:43 +03:00
|
|
|
return;
|
2021-12-28 00:21:17 +03:00
|
|
|
} else if (special == SP_SHELL) {
|
2021-12-28 20:39:04 +03:00
|
|
|
if (!Job_ParseShell(p)) {
|
2021-06-21 13:29:08 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"improper shell specification");
|
|
|
|
return;
|
|
|
|
}
|
2022-01-07 12:49:43 +03:00
|
|
|
return;
|
2021-12-28 00:21:17 +03:00
|
|
|
} else if (special == SP_NOTPARALLEL || special == SP_SINGLESHELL ||
|
|
|
|
special == SP_DELETE_ON_ERROR) {
|
2022-01-07 12:49:43 +03:00
|
|
|
return;
|
2021-06-21 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2023-01-24 02:01:52 +03:00
|
|
|
switch (special) {
|
|
|
|
case SP_INCLUDES:
|
|
|
|
case SP_LIBS:
|
|
|
|
case SP_NOREADONLY:
|
|
|
|
case SP_NULL:
|
|
|
|
case SP_OBJDIR:
|
|
|
|
case SP_PATH:
|
|
|
|
case SP_READONLY:
|
|
|
|
case SP_SUFFIXES:
|
2023-01-24 03:24:02 +03:00
|
|
|
case SP_SYSPATH:
|
2021-12-28 20:39:04 +03:00
|
|
|
ParseDependencySourcesSpecial(p, special, *inout_paths);
|
2021-06-21 13:29:08 +03:00
|
|
|
if (*inout_paths != NULL) {
|
|
|
|
Lst_Free(*inout_paths);
|
|
|
|
*inout_paths = NULL;
|
|
|
|
}
|
2021-12-28 00:21:17 +03:00
|
|
|
if (special == SP_PATH)
|
2021-06-21 13:29:08 +03:00
|
|
|
Dir_SetPATH();
|
2023-01-24 03:24:02 +03:00
|
|
|
if (special == SP_SYSPATH)
|
|
|
|
Dir_SetSYSPATH();
|
2023-01-24 02:01:52 +03:00
|
|
|
break;
|
|
|
|
default:
|
2021-06-21 13:29:08 +03:00
|
|
|
assert(*inout_paths == NULL);
|
2021-12-28 20:39:04 +03:00
|
|
|
if (!ParseDependencySourcesMundane(p, special, targetAttr))
|
2021-06-21 13:29:08 +03:00
|
|
|
return;
|
2023-01-24 02:01:52 +03:00
|
|
|
break;
|
2021-06-21 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
MaybeUpdateMainTarget();
|
2021-06-21 13:29:08 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
|
|
|
* Parse a dependency line consisting of targets, followed by a dependency
|
2020-10-05 22:27:47 +03:00
|
|
|
* 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,
|
2021-12-27 21:54:19 +03:00
|
|
|
* which is where the nodes found for the targets are kept.
|
2020-10-05 22:27:47 +03:00
|
|
|
*
|
|
|
|
* 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,
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
* and a target is created for each expanded word. Each of the resulting
|
|
|
|
* nodes is then linked to each of the targets as one of its children.
|
2020-10-05 22:27:47 +03:00
|
|
|
*
|
|
|
|
* Certain targets and sources such as .PHONY or .PRECIOUS are handled
|
2021-12-27 21:54:19 +03:00
|
|
|
* specially, see ParseSpecial.
|
2020-10-05 22:27:47 +03:00
|
|
|
*
|
2021-12-27 21:54:19 +03:00
|
|
|
* Transformation rules such as '.c.o' are also handled here, see
|
|
|
|
* Suff_AddTransform.
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
*
|
2024-04-24 01:51:28 +03:00
|
|
|
* Upon return, the value of expandedLine is unspecified.
|
2020-10-05 22:27:47 +03:00
|
|
|
*/
|
|
|
|
static void
|
2024-04-24 01:51:28 +03:00
|
|
|
ParseDependency(char *expandedLine, const char *unexpandedLine)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-28 22:01:36 +03:00
|
|
|
char *p;
|
2021-12-15 15:58:01 +03:00
|
|
|
SearchPathList *paths; /* search paths to alter when parsing a list
|
|
|
|
* of .PATH targets */
|
2021-12-28 18:03:10 +03:00
|
|
|
GNodeType targetAttr; /* from special sources */
|
2021-12-28 22:01:36 +03:00
|
|
|
ParseSpecial special; /* in special targets, the children are
|
|
|
|
* linked as children of the parent but not
|
|
|
|
* vice versa */
|
2022-07-24 23:25:23 +03:00
|
|
|
GNodeType op;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2024-04-24 01:51:28 +03:00
|
|
|
DEBUG1(PARSE, "ParseDependency(%s)\n", expandedLine);
|
|
|
|
p = expandedLine;
|
2020-12-05 22:46:04 +03:00
|
|
|
paths = NULL;
|
2021-12-28 22:01:36 +03:00
|
|
|
targetAttr = OP_NONE;
|
|
|
|
special = SP_NOT;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2024-04-24 01:51:28 +03:00
|
|
|
if (!ParseDependencyTargets(&p, expandedLine, &special, &targetAttr,
|
|
|
|
&paths, unexpandedLine))
|
2020-12-05 22:46:04 +03:00
|
|
|
goto out;
|
2020-10-18 23:14:27 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (!Lst_IsEmpty(targets))
|
2022-01-07 17:03:55 +03:00
|
|
|
CheckSpecialMundaneMixture(special);
|
2020-10-18 23:07:26 +03:00
|
|
|
|
2022-07-24 23:25:23 +03:00
|
|
|
op = ParseDependencyOp(&p);
|
|
|
|
if (op == OP_NONE) {
|
2024-04-24 01:51:28 +03:00
|
|
|
InvalidLineType(expandedLine, unexpandedLine);
|
2022-07-24 23:25:23 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ApplyDependencyOperator(op);
|
2020-10-18 23:07:26 +03:00
|
|
|
|
2021-12-28 22:01:36 +03:00
|
|
|
pp_skip_whitespace(&p);
|
2020-10-18 23:07:26 +03:00
|
|
|
|
2021-12-28 22:01:36 +03:00
|
|
|
ParseDependencySources(p, targetAttr, special, &paths);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (paths != NULL)
|
|
|
|
Lst_Free(paths);
|
2020-10-18 23:07:26 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* Determine the assignment operator and adjust the end of the variable
|
|
|
|
* name accordingly.
|
|
|
|
*/
|
2021-12-31 03:37:50 +03:00
|
|
|
static VarAssign
|
|
|
|
AdjustVarassignOp(const char *name, const char *nameEnd, const char *op,
|
|
|
|
const char *value)
|
2020-12-05 22:46:04 +03:00
|
|
|
{
|
|
|
|
VarAssignOp type;
|
2021-12-31 03:37:50 +03:00
|
|
|
VarAssign va;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
if (op > name && op[-1] == '+') {
|
|
|
|
op--;
|
2021-12-14 03:17:53 +03:00
|
|
|
type = VAR_APPEND;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
} 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;
|
|
|
|
while (op > name && ch_isspace(op[-1]))
|
|
|
|
op--;
|
|
|
|
|
2021-12-31 04:08:59 +03:00
|
|
|
if (op - name >= 3 && memcmp(op - 3, ":sh", 3) == 0) {
|
2020-12-05 22:46:04 +03:00
|
|
|
op -= 3;
|
2021-12-14 03:17:53 +03:00
|
|
|
type = VAR_SHELL;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 03:37:50 +03:00
|
|
|
va.varname = bmake_strsedup(name, nameEnd < op ? nameEnd : op);
|
|
|
|
va.op = type;
|
|
|
|
va.value = value;
|
|
|
|
return va;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse a variable assignment, consisting of a single-word variable name,
|
2020-10-05 22:27:47 +03:00
|
|
|
* optional whitespace, an assignment operator, optional whitespace and the
|
|
|
|
* variable value.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2020-10-29 23:37:47 +03:00
|
|
|
* 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++ =".
|
|
|
|
*
|
2020-12-05 22:46:04 +03:00
|
|
|
* Used for both lines in a file and command line arguments.
|
|
|
|
*/
|
2021-12-31 03:18:06 +03:00
|
|
|
static bool
|
2020-10-05 22:27:47 +03:00
|
|
|
Parse_IsVar(const char *p, VarAssign *out_var)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2022-01-16 12:41:28 +03:00
|
|
|
const char *nameStart, *nameEnd, *firstSpace, *eq;
|
2020-12-05 22:46:04 +03:00
|
|
|
int level = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
cpp_skip_hspace(&p); /* Skip to variable name */
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
2022-02-10 00:09:24 +03:00
|
|
|
* During parsing, the '+' of the operator '+=' is initially parsed
|
2020-12-05 22:46:04 +03:00
|
|
|
* as part of the variable name. It is later corrected, as is the
|
2022-01-16 12:41:28 +03:00
|
|
|
* ':sh' modifier. Of these two (nameEnd and eq), the earlier one
|
2020-12-05 22:46:04 +03:00
|
|
|
* determines the actual end of the variable name.
|
|
|
|
*/
|
2022-01-16 12:41:28 +03:00
|
|
|
|
2021-12-31 03:37:50 +03:00
|
|
|
nameStart = p;
|
2022-01-16 12:41:28 +03:00
|
|
|
firstSpace = NULL;
|
2020-10-04 22:36:32 +03:00
|
|
|
|
2023-12-19 22:33:39 +03:00
|
|
|
/* Scan for one of the assignment operators outside an expression. */
|
2020-12-05 22:46:04 +03:00
|
|
|
while (*p != '\0') {
|
|
|
|
char ch = *p++;
|
|
|
|
if (ch == '(' || ch == '{') {
|
|
|
|
level++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == ')' || ch == '}') {
|
|
|
|
level--;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (level != 0)
|
|
|
|
continue;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2022-01-16 12:41:28 +03:00
|
|
|
if ((ch == ' ' || ch == '\t') && firstSpace == NULL)
|
|
|
|
firstSpace = p - 1;
|
2020-12-05 22:46:04 +03:00
|
|
|
while (ch == ' ' || ch == '\t')
|
|
|
|
ch = *p++;
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2022-02-05 03:37:19 +03:00
|
|
|
if (ch == '\0')
|
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
if (ch == ':' && p[0] == 's' && p[1] == 'h') {
|
|
|
|
p += 2;
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-31 03:45:21 +03:00
|
|
|
if (ch == '=')
|
2021-12-31 03:37:50 +03:00
|
|
|
eq = p - 1;
|
2021-12-31 03:45:21 +03:00
|
|
|
else if (*p == '=' &&
|
|
|
|
(ch == '+' || ch == ':' || ch == '?' || ch == '!'))
|
2021-12-31 03:37:50 +03:00
|
|
|
eq = p;
|
2021-12-31 03:45:21 +03:00
|
|
|
else if (firstSpace != NULL)
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2021-12-31 03:45:21 +03:00
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nameEnd = firstSpace != NULL ? firstSpace : eq;
|
|
|
|
p = eq + 1;
|
|
|
|
cpp_skip_whitespace(&p);
|
|
|
|
*out_var = AdjustVarassignOp(nameStart, nameEnd, eq, p);
|
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* Check for syntax errors such as unclosed expressions or unknown modifiers.
|
|
|
|
*/
|
2020-10-05 22:27:47 +03:00
|
|
|
static void
|
2023-11-02 08:55:22 +03:00
|
|
|
VarCheckSyntax(VarAssignOp op, const char *uvalue, GNode *scope)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-23 16:50:54 +03:00
|
|
|
if (opts.strict) {
|
2023-11-02 08:55:22 +03:00
|
|
|
if (op != VAR_SUBST && strchr(uvalue, '$') != NULL) {
|
|
|
|
char *parsedValue = Var_Subst(uvalue,
|
2023-02-15 00:38:31 +03:00
|
|
|
scope, VARE_PARSE_ONLY);
|
2020-12-05 22:46:04 +03:00
|
|
|
/* TODO: handle errors */
|
2023-11-02 08:55:22 +03:00
|
|
|
free(parsedValue);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-07-31 23:22:10 +03:00
|
|
|
}
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/* Perform a variable assignment that uses the operator ':='. */
|
2020-10-18 23:29:50 +03:00
|
|
|
static void
|
2021-02-05 08:15:12 +03:00
|
|
|
VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue,
|
2020-12-20 17:48:35 +03:00
|
|
|
FStr *out_avalue)
|
2020-10-18 23:29:50 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
char *evalue;
|
|
|
|
|
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Make sure that we set the variable the first time to nothing
|
2021-02-02 01:21:33 +03:00
|
|
|
* so that it gets substituted.
|
|
|
|
*
|
|
|
|
* TODO: Add a test that demonstrates why this code is needed,
|
|
|
|
* apart from making the debug log longer.
|
2022-01-08 00:00:49 +03:00
|
|
|
*
|
2022-01-07 23:37:25 +03:00
|
|
|
* XXX: The variable name is expanded up to 3 times.
|
2020-12-05 22:46:04 +03:00
|
|
|
*/
|
2021-02-05 08:15:12 +03:00
|
|
|
if (!Var_ExistsExpand(scope, name))
|
|
|
|
Var_SetExpand(scope, name, "");
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2023-02-15 00:38:31 +03:00
|
|
|
evalue = Var_Subst(uvalue, scope, VARE_KEEP_DOLLAR_UNDEF);
|
2020-12-28 01:29:37 +03:00
|
|
|
/* TODO: handle errors */
|
|
|
|
|
2021-02-05 08:15:12 +03:00
|
|
|
Var_SetExpand(scope, name, evalue);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2021-02-02 01:06:05 +03:00
|
|
|
*out_avalue = FStr_InitOwn(evalue);
|
2020-10-18 23:29:50 +03:00
|
|
|
}
|
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/* Perform a variable assignment that uses the operator '!='. */
|
2020-10-18 23:29:50 +03:00
|
|
|
static void
|
2021-02-05 00:42:46 +03:00
|
|
|
VarAssign_EvalShell(const char *name, const char *uvalue, GNode *scope,
|
2020-12-20 17:48:35 +03:00
|
|
|
FStr *out_avalue)
|
2020-10-18 23:29:50 +03:00
|
|
|
{
|
2020-12-20 17:52:16 +03:00
|
|
|
FStr cmd;
|
2022-01-09 21:49:28 +03:00
|
|
|
char *output, *error;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2020-12-20 17:52:16 +03:00
|
|
|
cmd = FStr_InitRefer(uvalue);
|
2022-01-15 21:34:41 +03:00
|
|
|
Var_Expand(&cmd, SCOPE_CMDLINE, VARE_UNDEFERR);
|
2020-10-18 23:29:50 +03:00
|
|
|
|
2022-01-09 21:49:28 +03:00
|
|
|
output = Cmd_Exec(cmd.str, &error);
|
|
|
|
Var_SetExpand(scope, name, output);
|
|
|
|
*out_avalue = FStr_InitOwn(output);
|
|
|
|
if (error != NULL) {
|
|
|
|
Parse_Error(PARSE_WARNING, "%s", error);
|
|
|
|
free(error);
|
|
|
|
}
|
2020-10-18 23:29:50 +03:00
|
|
|
|
2020-12-20 17:52:16 +03:00
|
|
|
FStr_Done(&cmd);
|
2020-10-18 23:29:50 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
|
|
|
* Perform a variable assignment.
|
2020-10-18 23:46:42 +03:00
|
|
|
*
|
2021-04-03 17:31:44 +03:00
|
|
|
* The actual value of the variable is returned in *out_true_avalue.
|
2021-02-02 01:21:33 +03:00
|
|
|
* Especially for VAR_SUBST and VAR_SHELL this can differ from the literal
|
|
|
|
* value.
|
2020-10-18 23:46:42 +03:00
|
|
|
*
|
2021-02-02 01:21:33 +03:00
|
|
|
* Return whether the assignment was actually performed, which is usually
|
|
|
|
* the case. It is only skipped if the operator is '?=' and the variable
|
|
|
|
* already exists.
|
2020-12-30 13:03:16 +03:00
|
|
|
*/
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-10-18 23:46:42 +03:00
|
|
|
VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue,
|
2021-04-03 17:31:44 +03:00
|
|
|
GNode *scope, FStr *out_true_avalue)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2020-12-20 17:48:35 +03:00
|
|
|
FStr avalue = FStr_InitRefer(uvalue);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
if (op == VAR_APPEND)
|
2021-02-05 08:15:12 +03:00
|
|
|
Var_AppendExpand(scope, name, uvalue);
|
2020-12-05 22:46:04 +03:00
|
|
|
else if (op == VAR_SUBST)
|
2021-02-05 08:15:12 +03:00
|
|
|
VarAssign_EvalSubst(scope, name, uvalue, &avalue);
|
2020-12-05 22:46:04 +03:00
|
|
|
else if (op == VAR_SHELL)
|
2021-02-05 00:42:46 +03:00
|
|
|
VarAssign_EvalShell(name, uvalue, scope, &avalue);
|
2020-12-05 22:46:04 +03:00
|
|
|
else {
|
2022-01-07 23:37:25 +03:00
|
|
|
/* XXX: The variable name is expanded up to 2 times. */
|
2021-02-05 08:15:12 +03:00
|
|
|
if (op == VAR_DEFAULT && Var_ExistsExpand(scope, name))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-10-04 17:40:13 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/* Normal assignment -- just do it. */
|
2021-02-05 08:15:12 +03:00
|
|
|
Var_SetExpand(scope, name, uvalue);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2021-04-03 17:31:44 +03:00
|
|
|
*out_true_avalue = avalue;
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
VarAssignSpecial(const char *name, const char *avalue)
|
|
|
|
{
|
2023-02-15 09:52:58 +03:00
|
|
|
if (strcmp(name, ".MAKEOVERRIDES") == 0)
|
2021-12-15 15:58:01 +03:00
|
|
|
Main_ExportMAKEFLAGS(false); /* re-export MAKEFLAGS */
|
2020-12-05 22:46:04 +03:00
|
|
|
else if (strcmp(name, ".CURDIR") == 0) {
|
|
|
|
/*
|
|
|
|
* Someone is being (too?) clever...
|
|
|
|
* Let's pretend they know what they are doing and
|
|
|
|
* re-initialize the 'cur' CachedDir.
|
|
|
|
*/
|
|
|
|
Dir_InitCur(avalue);
|
|
|
|
Dir_SetPATH();
|
2023-02-15 09:52:58 +03:00
|
|
|
} else if (strcmp(name, ".MAKE.JOB.PREFIX") == 0)
|
2020-12-05 22:46:04 +03:00
|
|
|
Job_SetPrefix();
|
2023-02-15 09:31:51 +03:00
|
|
|
else if (strcmp(name, ".MAKE.EXPORTED") == 0)
|
2020-12-13 00:20:30 +03:00
|
|
|
Var_ExportVars(avalue);
|
2020-10-05 22:27:47 +03:00
|
|
|
}
|
|
|
|
|
2021-12-14 03:17:53 +03:00
|
|
|
/* Perform the variable assignment in the given scope. */
|
2021-12-31 03:18:06 +03:00
|
|
|
static void
|
2022-01-29 04:07:31 +03:00
|
|
|
Parse_Var(VarAssign *var, GNode *scope)
|
2020-10-05 22:27:47 +03:00
|
|
|
{
|
2021-12-15 15:58:01 +03:00
|
|
|
FStr avalue; /* actual value (maybe expanded) */
|
2020-10-05 22:27:47 +03:00
|
|
|
|
2021-02-05 00:42:46 +03:00
|
|
|
VarCheckSyntax(var->op, var->value, scope);
|
|
|
|
if (VarAssign_Eval(var->varname, var->op, var->value, scope, &avalue)) {
|
2020-12-20 17:48:35 +03:00
|
|
|
VarAssignSpecial(var->varname, avalue.str);
|
|
|
|
FStr_Done(&avalue);
|
|
|
|
}
|
2022-01-27 09:02:59 +03:00
|
|
|
}
|
2022-01-27 13:34:55 +03:00
|
|
|
|
2014-08-23 19:05:40 +04:00
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
2023-11-20 01:50:11 +03:00
|
|
|
* See if the command possibly calls a sub-make by using the
|
2020-12-30 13:03:16 +03:00
|
|
|
* expressions ${.MAKE}, ${MAKE} or the plain word "make".
|
|
|
|
*/
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-11-08 02:41:38 +03:00
|
|
|
MaybeSubMake(const char *cmd)
|
2014-07-16 19:33:41 +04:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
const char *start;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (start = cmd; *start != '\0'; start++) {
|
|
|
|
const char *p = start;
|
|
|
|
char endc;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/* XXX: What if progname != "make"? */
|
2021-12-14 03:17:53 +03:00
|
|
|
if (strncmp(p, "make", 4) == 0)
|
2020-12-05 22:46:04 +03:00
|
|
|
if (start == cmd || !ch_isalnum(p[-1]))
|
|
|
|
if (!ch_isalnum(p[4]))
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*p != '$')
|
|
|
|
continue;
|
|
|
|
p++;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*p == '{')
|
|
|
|
endc = '}';
|
|
|
|
else if (*p == '(')
|
|
|
|
endc = ')';
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
p++;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*p == '.') /* Accept either ${.MAKE} or ${MAKE}. */
|
|
|
|
p++;
|
2020-11-08 02:41:38 +03:00
|
|
|
|
2022-01-02 05:57:39 +03:00
|
|
|
if (strncmp(p, "MAKE", 4) == 0 && p[4] == endc)
|
|
|
|
return true;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2014-07-16 19:33:41 +04:00
|
|
|
}
|
|
|
|
|
2023-11-02 08:40:49 +03:00
|
|
|
/* Append the command to the target node. */
|
2020-09-26 00:13:44 +03:00
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
GNode_AddCommand(GNode *gn, char *cmd)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
if ((gn->type & OP_DOUBLEDEP) && gn->cohorts.last != NULL)
|
|
|
|
gn = gn->cohorts.last->datum;
|
|
|
|
|
|
|
|
/* if target already supplied, ignore commands */
|
|
|
|
if (!(gn->type & OP_HAS_COMMANDS)) {
|
|
|
|
Lst_Append(&gn->commands, cmd);
|
|
|
|
if (MaybeSubMake(cmd))
|
|
|
|
gn->type |= OP_SUBMAKE;
|
2021-08-14 16:37:55 +03:00
|
|
|
RememberLocation(gn);
|
2020-12-05 22:46:04 +03:00
|
|
|
} else {
|
|
|
|
Parse_Error(PARSE_WARNING,
|
2020-10-17 21:36:56 +03:00
|
|
|
"duplicate script for target \"%s\" ignored",
|
|
|
|
gn->name);
|
2022-06-12 16:37:32 +03:00
|
|
|
ParseErrorInternal(gn, PARSE_WARNING,
|
2020-12-05 22:46:04 +03:00
|
|
|
"using previous script for \"%s\" defined here",
|
|
|
|
gn->name);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
/*
|
|
|
|
* Parse a directive like '.include' or '.-include'.
|
|
|
|
*
|
|
|
|
* .include "user-makefile.mk"
|
|
|
|
* .include <system-makefile.mk>
|
|
|
|
*/
|
2006-12-08 00:07:01 +03:00
|
|
|
static void
|
2021-04-04 13:13:09 +03:00
|
|
|
ParseInclude(char *directive)
|
2006-12-08 00:07:01 +03:00
|
|
|
{
|
2021-12-04 02:29:30 +03:00
|
|
|
char endc; /* '>' or '"' */
|
|
|
|
char *p;
|
2021-04-03 14:08:40 +03:00
|
|
|
bool silent = directive[0] != 'i';
|
2021-12-04 02:13:29 +03:00
|
|
|
FStr file;
|
2006-12-08 00:07:01 +03:00
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
p = directive + (silent ? 8 : 7);
|
|
|
|
pp_skip_hspace(&p);
|
2006-12-08 00:07:01 +03:00
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
if (*p != '"' && *p != '<') {
|
2020-12-05 22:46:04 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-10-17 21:36:56 +03:00
|
|
|
".include filename must be delimited by '\"' or '<'");
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-02 08:55:22 +03:00
|
|
|
endc = *p++ == '<' ? '>' : '"';
|
2021-12-04 02:13:29 +03:00
|
|
|
file = FStr_InitRefer(p);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
while (*p != '\0' && *p != endc)
|
|
|
|
p++;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
if (*p != endc) {
|
2020-12-05 22:46:04 +03:00
|
|
|
Parse_Error(PARSE_FATAL,
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
"Unclosed .include filename. '%c' expected", endc);
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
|
|
|
}
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2021-12-04 02:13:29 +03:00
|
|
|
*p = '\0';
|
2006-12-08 00:07:01 +03:00
|
|
|
|
2022-01-15 21:34:41 +03:00
|
|
|
Var_Expand(&file, SCOPE_CMDLINE, VARE_WANTRES);
|
2021-12-04 02:29:30 +03:00
|
|
|
IncludeFile(file.str, endc == '>', directive[0] == 'd', silent);
|
|
|
|
FStr_Done(&file);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +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
|
|
|
{
|
2021-02-23 02:21:33 +03:00
|
|
|
const char *slash, *basename;
|
|
|
|
FStr dirname;
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
slash = strrchr(filename, '/');
|
|
|
|
if (slash == NULL) {
|
2021-02-23 02:21:33 +03:00
|
|
|
dirname = FStr_InitRefer(curdir);
|
2020-12-05 22:46:04 +03:00
|
|
|
basename = filename;
|
|
|
|
} else {
|
2021-02-23 02:21:33 +03:00
|
|
|
dirname = FStr_InitOwn(bmake_strsedup(filename, slash));
|
2020-12-05 22:46:04 +03:00
|
|
|
basename = slash + 1;
|
|
|
|
}
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2021-12-04 02:37:30 +03:00
|
|
|
Global_Set(dirvar, dirname.str);
|
|
|
|
Global_Set(filevar, basename);
|
2014-01-10 20:12:52 +04:00
|
|
|
|
2021-12-27 22:06:07 +03:00
|
|
|
DEBUG4(PARSE, "SetFilenameVars: ${%s} = `%s' ${%s} = `%s'\n",
|
|
|
|
dirvar, dirname.str, filevar, basename);
|
2021-02-23 02:21:33 +03:00
|
|
|
FStr_Done(&dirname);
|
2014-01-10 20:12:52 +04:00
|
|
|
}
|
2020-09-05 21:18:05 +03:00
|
|
|
|
2020-12-05 22:46:04 +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
|
2020-12-05 22:46:04 +03:00
|
|
|
* kind of .include; see For_Run.
|
|
|
|
*/
|
2020-09-05 21:18:05 +03:00
|
|
|
static const char *
|
|
|
|
GetActuallyIncludingFile(void)
|
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
size_t i;
|
2022-01-07 16:56:09 +03:00
|
|
|
const IncludedFile *incs = GetInclude(0);
|
2020-09-05 21:18:05 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (i = includes.len; i >= 2; i--)
|
2022-01-02 05:16:12 +03:00
|
|
|
if (incs[i - 1].forLoop == NULL)
|
2021-12-13 08:25:04 +03:00
|
|
|
return incs[i - 2].name.str;
|
2020-12-05 22:46:04 +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
|
2021-12-28 19:17:54 +03:00
|
|
|
SetParseFile(const char *filename)
|
1999-08-10 01:06:28 +04:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
const char *including;
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
SetFilenameVars(filename, ".PARSEDIR", ".PARSEFILE");
|
2020-09-05 21:18:05 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
including = GetActuallyIncludingFile();
|
|
|
|
if (including != NULL) {
|
|
|
|
SetFilenameVars(including,
|
|
|
|
".INCLUDEDFROMDIR", ".INCLUDEDFROMFILE");
|
|
|
|
} else {
|
2021-02-05 07:41:17 +03:00
|
|
|
Global_Delete(".INCLUDEDFROMDIR");
|
|
|
|
Global_Delete(".INCLUDEDFROMFILE");
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
1999-08-10 01:06:28 +04:00
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-11-01 02:39:01 +03:00
|
|
|
StrContainsWord(const char *str, const char *word)
|
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
size_t strLen = strlen(str);
|
|
|
|
size_t wordLen = strlen(word);
|
2021-12-28 04:27:37 +03:00
|
|
|
const char *p;
|
2020-11-01 02:39:01 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (strLen < wordLen)
|
2021-12-27 21:54:19 +03:00
|
|
|
return false;
|
2020-11-01 02:39:01 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (p = str; p != NULL; p = strchr(p, ' ')) {
|
|
|
|
if (*p == ' ')
|
|
|
|
p++;
|
2021-12-28 04:27:37 +03:00
|
|
|
if (p > str + strLen - wordLen)
|
2021-12-27 21:54:19 +03:00
|
|
|
return false;
|
2020-11-01 02:39:01 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (memcmp(p, word, wordLen) == 0 &&
|
|
|
|
(p[wordLen] == '\0' || p[wordLen] == ' '))
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-11-01 02:39:01 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* XXX: Searching through a set of words with this linear search is
|
|
|
|
* inefficient for variables that contain thousands of words.
|
|
|
|
*
|
|
|
|
* XXX: The paths in this list don't seem to be normalized in any way.
|
|
|
|
*/
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-11-01 02:39:01 +03:00
|
|
|
VarContainsWord(const char *varname, const char *word)
|
|
|
|
{
|
2021-02-05 08:15:12 +03:00
|
|
|
FStr val = Var_Value(SCOPE_GLOBAL, varname);
|
2021-04-03 14:08:40 +03:00
|
|
|
bool found = val.str != NULL && StrContainsWord(val.str, word);
|
2020-12-20 17:32:13 +03:00
|
|
|
FStr_Done(&val);
|
2020-12-05 22:46:04 +03:00
|
|
|
return found;
|
2020-11-01 02:39:01 +03:00
|
|
|
}
|
|
|
|
|
2020-12-30 13:03:16 +03:00
|
|
|
/*
|
|
|
|
* Track the makefiles we read - so makefiles can set dependencies on them.
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
* Avoid adding anything more than once.
|
|
|
|
*
|
|
|
|
* Time complexity: O(n) per call, in total O(n^2), where n is the number
|
2020-12-30 13:03:16 +03:00
|
|
|
* of makefiles that have been loaded.
|
|
|
|
*/
|
2012-04-25 00:12:16 +04:00
|
|
|
static void
|
2021-12-28 19:17:54 +03:00
|
|
|
TrackInput(const char *name)
|
2012-04-25 00:12:16 +04:00
|
|
|
{
|
2023-02-15 09:52:58 +03:00
|
|
|
if (!VarContainsWord(".MAKE.MAKEFILES", name))
|
|
|
|
Global_Append(".MAKE.MAKEFILES", name);
|
2012-04-25 00:12:16 +04:00
|
|
|
}
|
2007-10-09 00:26:36 +04:00
|
|
|
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2022-01-07 23:37:25 +03:00
|
|
|
/* Parse from the given buffer, later return to the current file. */
|
1994-03-05 03:34:29 +03:00
|
|
|
void
|
2022-02-05 02:22:19 +03:00
|
|
|
Parse_PushInput(const char *name, unsigned lineno, unsigned readLines,
|
|
|
|
Buffer buf, struct ForLoop *forLoop)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2022-01-07 16:56:09 +03:00
|
|
|
IncludedFile *curFile;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2022-01-02 05:16:12 +03:00
|
|
|
if (forLoop != NULL)
|
2021-12-13 08:25:04 +03:00
|
|
|
name = CurFile()->name.str;
|
2020-12-05 22:46:04 +03:00
|
|
|
else
|
2021-12-28 19:17:54 +03:00
|
|
|
TrackInput(name);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2022-02-05 02:22:19 +03:00
|
|
|
DEBUG3(PARSE, "Parse_PushInput: %s %s, line %u\n",
|
2022-01-02 05:16:12 +03:00
|
|
|
forLoop != NULL ? ".for loop in": "file", name, lineno);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
|
|
|
curFile = Vector_Push(&includes);
|
2021-12-13 08:25:04 +03:00
|
|
|
curFile->name = FStr_InitOwn(bmake_strdup(name));
|
2022-01-08 23:21:34 +03:00
|
|
|
curFile->lineno = lineno;
|
|
|
|
curFile->readLines = readLines;
|
|
|
|
curFile->forHeadLineno = lineno;
|
|
|
|
curFile->forBodyReadLines = readLines;
|
2022-01-02 04:54:43 +03:00
|
|
|
curFile->buf = buf;
|
2020-12-05 22:46:04 +03:00
|
|
|
curFile->depending = doing_depend; /* restore this on EOF */
|
2023-06-20 12:25:33 +03:00
|
|
|
curFile->guardState = forLoop == NULL ? GS_START : GS_NO;
|
|
|
|
curFile->guard = NULL;
|
2022-01-02 04:54:43 +03:00
|
|
|
curFile->forLoop = forLoop;
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
if (forLoop != NULL && !For_NextIteration(forLoop, &curFile->buf))
|
|
|
|
abort(); /* see For_Run */
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
curFile->buf_ptr = curFile->buf.data;
|
|
|
|
curFile->buf_end = curFile->buf.data + curFile->buf.len;
|
2022-09-24 19:13:48 +03:00
|
|
|
curFile->condMinDepth = cond_depth;
|
2021-12-28 19:17:54 +03:00
|
|
|
SetParseFile(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. */
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
|
|
|
IsInclude(const char *dir, bool 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)
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2018-04-05 03:31:10 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-05 22:07:25 +03:00
|
|
|
/* Check if the line is a SYSV include directive. */
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2018-04-05 03:31:10 +03:00
|
|
|
IsSysVInclude(const char *line)
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
if (!IsInclude(line, true))
|
|
|
|
return false;
|
2018-04-05 03:31:10 +03:00
|
|
|
|
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;) {
|
2020-11-08 01:25:19 +03:00
|
|
|
|
|
|
|
/* end of line -> it's a dependency */
|
|
|
|
if (*++p == '\0')
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-11-08 01:25:19 +03:00
|
|
|
|
|
|
|
/* '::' operator or ': ' -> it's a dependency */
|
|
|
|
if (*p == ':' || ch_isspace(*p))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2018-04-05 03:31:10 +03:00
|
|
|
}
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2018-04-05 03:31:10 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2023-12-17 11:53:54 +03:00
|
|
|
char *p; /* current position in file spec */
|
2021-04-03 14:08:40 +03:00
|
|
|
bool done = false;
|
|
|
|
bool silent = line[0] != 'i';
|
2020-12-05 22:46:04 +03:00
|
|
|
char *file = line + (silent ? 8 : 7);
|
|
|
|
char *all_files;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2021-12-27 22:06:07 +03:00
|
|
|
DEBUG1(PARSE, "ParseTraditionalInclude: %s\n", file);
|
2006-03-28 21:41:35 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
pp_skip_whitespace(&file);
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2023-02-15 00:38:31 +03:00
|
|
|
all_files = Var_Subst(file, SCOPE_CMDLINE, VARE_WANTRES);
|
2020-12-05 22:46:04 +03:00
|
|
|
/* TODO: handle errors */
|
2006-03-28 21:41:35 +04:00
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
for (file = all_files; !done; file = p + 1) {
|
2020-12-05 22:46:04 +03:00
|
|
|
/* Skip to end of line or next whitespace */
|
2023-12-17 11:53:54 +03:00
|
|
|
for (p = file; *p != '\0' && !ch_isspace(*p); p++)
|
2020-12-05 22:46:04 +03:00
|
|
|
continue;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
if (*p != '\0')
|
|
|
|
*p = '\0';
|
2020-12-05 22:46:04 +03:00
|
|
|
else
|
2021-04-03 14:08:40 +03:00
|
|
|
done = true;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
IncludeFile(file, false, false, silent);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2021-12-14 03:45:11 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
free(all_files);
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
|
|
|
|
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-12-05 22:46:04 +03:00
|
|
|
char *variable = line + 6;
|
|
|
|
char *value;
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2021-12-27 22:06:07 +03:00
|
|
|
DEBUG1(PARSE, "ParseGmakeExport: %s\n", variable);
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
pp_skip_whitespace(&variable);
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2021-01-11 00:20:46 +03:00
|
|
|
for (value = variable; *value != '\0' && *value != '='; value++)
|
2020-12-05 22:46:04 +03:00
|
|
|
continue;
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*value != '=') {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2020-09-05 22:07:25 +03:00
|
|
|
"Variable/Value missing from \"export\"");
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
*value++ = '\0'; /* terminate variable */
|
2012-03-31 04:12:24 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* Expand the value before putting it in the environment.
|
|
|
|
*/
|
2023-02-15 00:38:31 +03:00
|
|
|
value = Var_Subst(value, SCOPE_CMDLINE, VARE_WANTRES);
|
2020-12-05 22:46:04 +03:00
|
|
|
/* TODO: handle errors */
|
2020-09-22 23:19:46 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
setenv(variable, value, 1);
|
|
|
|
free(value);
|
2012-03-31 04:12:24 +04:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* When the end of the current file or .for loop is reached, continue reading
|
|
|
|
* the previous file at the previous location.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Results:
|
2021-04-03 14:08:40 +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
|
|
|
*/
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2006-12-08 00:07:01 +03:00
|
|
|
ParseEOF(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2022-01-07 16:56:09 +03:00
|
|
|
IncludedFile *curFile = CurFile();
|
2010-12-25 07:57:07 +03:00
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
doing_depend = curFile->depending;
|
|
|
|
if (curFile->forLoop != NULL &&
|
|
|
|
For_NextIteration(curFile->forLoop, &curFile->buf)) {
|
|
|
|
curFile->buf_ptr = curFile->buf.data;
|
|
|
|
curFile->buf_end = curFile->buf.data + curFile->buf.len;
|
2022-01-07 16:56:09 +03:00
|
|
|
curFile->readLines = curFile->forBodyReadLines;
|
2022-01-02 04:54:43 +03:00
|
|
|
return true;
|
2022-01-02 03:07:20 +03:00
|
|
|
}
|
2009-01-11 18:50:06 +03:00
|
|
|
|
2022-09-24 19:13:48 +03:00
|
|
|
Cond_EndFile();
|
2007-01-25 00:43:01 +03:00
|
|
|
|
2024-05-25 11:03:19 +03:00
|
|
|
if (curFile->guardState == GS_DONE) {
|
|
|
|
HashEntry *he = HashTable_CreateEntry(&guards,
|
|
|
|
curFile->name.str, NULL);
|
|
|
|
if (he->value != NULL) {
|
|
|
|
free(((Guard *)he->value)->name);
|
|
|
|
free(he->value);
|
|
|
|
}
|
|
|
|
HashEntry_Set(he, curFile->guard);
|
|
|
|
} else if (curFile->guard != NULL) {
|
2023-06-20 12:25:33 +03:00
|
|
|
free(curFile->guard->name);
|
|
|
|
free(curFile->guard);
|
2023-06-19 15:53:57 +03:00
|
|
|
}
|
|
|
|
|
2021-12-13 08:25:04 +03:00
|
|
|
FStr_Done(&curFile->name);
|
2022-01-02 04:54:43 +03:00
|
|
|
Buf_Done(&curFile->buf);
|
2022-01-09 15:43:52 +03:00
|
|
|
if (curFile->forLoop != NULL)
|
|
|
|
ForLoop_Free(curFile->forLoop);
|
2020-12-05 22:46:04 +03:00
|
|
|
Vector_Pop(&includes);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (includes.len == 0) {
|
|
|
|
/* We've run out of input */
|
2021-02-05 07:41:17 +03:00
|
|
|
Global_Delete(".PARSEDIR");
|
|
|
|
Global_Delete(".PARSEFILE");
|
|
|
|
Global_Delete(".INCLUDEDFROMDIR");
|
|
|
|
Global_Delete(".INCLUDEDFROMFILE");
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
curFile = CurFile();
|
2022-02-05 02:22:19 +03:00
|
|
|
DEBUG2(PARSE, "ParseEOF: returning to file %s, line %u\n",
|
2022-01-09 01:24:20 +03:00
|
|
|
curFile->name.str, curFile->readLines + 1);
|
2020-12-05 22:46:04 +03:00
|
|
|
|
2021-12-28 19:17:54 +03:00
|
|
|
SetParseFile(curFile->name.str);
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2020-12-19 13:57:17 +03:00
|
|
|
typedef enum ParseRawLineResult {
|
|
|
|
PRLR_LINE,
|
|
|
|
PRLR_EOF,
|
|
|
|
PRLR_ERROR
|
|
|
|
} ParseRawLineResult;
|
|
|
|
|
2020-12-19 03:20:57 +03:00
|
|
|
/*
|
2020-12-19 13:49:36 +03:00
|
|
|
* Parse until the end of a line, taking into account lines that end with
|
2021-12-08 02:56:06 +03:00
|
|
|
* backslash-newline. The resulting line goes from out_line to out_line_end;
|
|
|
|
* the line is not null-terminated.
|
2020-12-19 03:20:57 +03:00
|
|
|
*/
|
2020-12-19 13:57:17 +03:00
|
|
|
static ParseRawLineResult
|
2022-01-07 16:56:09 +03:00
|
|
|
ParseRawLine(IncludedFile *curFile, char **out_line, char **out_line_end,
|
2022-01-08 00:57:26 +03:00
|
|
|
char **out_firstBackslash, char **out_commentLineEnd)
|
2020-12-19 03:20:57 +03:00
|
|
|
{
|
2020-12-19 13:57:17 +03:00
|
|
|
char *line = curFile->buf_ptr;
|
2021-12-08 02:20:09 +03:00
|
|
|
char *buf_end = curFile->buf_end;
|
2020-12-19 13:49:36 +03:00
|
|
|
char *p = line;
|
2020-12-19 03:20:57 +03:00
|
|
|
char *line_end = line;
|
2020-12-19 13:49:36 +03:00
|
|
|
char *firstBackslash = NULL;
|
2022-01-08 00:57:26 +03:00
|
|
|
char *commentLineEnd = NULL;
|
2020-12-19 13:57:17 +03:00
|
|
|
ParseRawLineResult res = PRLR_LINE;
|
2020-12-19 03:20:57 +03:00
|
|
|
|
2022-01-07 16:56:09 +03:00
|
|
|
curFile->readLines++;
|
2020-12-19 03:27:34 +03:00
|
|
|
|
2020-12-19 03:20:57 +03:00
|
|
|
for (;;) {
|
2020-12-19 13:49:36 +03:00
|
|
|
char ch;
|
|
|
|
|
2021-12-08 02:20:09 +03:00
|
|
|
if (p == buf_end) {
|
2020-12-19 13:57:17 +03:00
|
|
|
res = PRLR_EOF;
|
2020-12-19 03:20:57 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-19 13:49:36 +03:00
|
|
|
ch = *p;
|
2022-01-08 01:08:09 +03:00
|
|
|
if (ch == '\0' || (ch == '\\' && p[1] == '\0')) {
|
2020-12-19 13:49:36 +03:00
|
|
|
Parse_Error(PARSE_FATAL, "Zero byte read from file");
|
2024-04-01 15:26:02 +03:00
|
|
|
exit(2);
|
2020-12-19 03:20:57 +03:00
|
|
|
}
|
|
|
|
|
2020-12-19 13:49:36 +03:00
|
|
|
/* Treat next character after '\' as literal. */
|
2020-12-19 03:20:57 +03:00
|
|
|
if (ch == '\\') {
|
2020-12-19 13:49:36 +03:00
|
|
|
if (firstBackslash == NULL)
|
|
|
|
firstBackslash = p;
|
2020-12-22 11:05:08 +03:00
|
|
|
if (p[1] == '\n') {
|
2022-01-07 16:56:09 +03:00
|
|
|
curFile->readLines++;
|
2021-12-08 02:20:09 +03:00
|
|
|
if (p + 2 == buf_end) {
|
2020-12-22 11:05:08 +03:00
|
|
|
line_end = p;
|
|
|
|
*line_end = '\n';
|
|
|
|
p += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 13:49:36 +03:00
|
|
|
p += 2;
|
|
|
|
line_end = p;
|
2021-12-08 02:20:09 +03:00
|
|
|
assert(p <= buf_end);
|
2020-12-19 03:20:57 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-12-19 13:49:36 +03:00
|
|
|
* Remember the first '#' for comment stripping, unless
|
|
|
|
* the previous char was '[', as in the modifier ':[#]'.
|
2020-12-19 03:20:57 +03:00
|
|
|
*/
|
2022-01-08 00:57:26 +03:00
|
|
|
if (ch == '#' && commentLineEnd == NULL &&
|
2020-12-19 13:49:36 +03:00
|
|
|
!(p > line && p[-1] == '['))
|
2022-01-08 00:57:26 +03:00
|
|
|
commentLineEnd = line_end;
|
2020-12-19 03:20:57 +03:00
|
|
|
|
2020-12-19 13:49:36 +03:00
|
|
|
p++;
|
2020-12-19 03:20:57 +03:00
|
|
|
if (ch == '\n')
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* We are not interested in trailing whitespace. */
|
|
|
|
if (!ch_isspace(ch))
|
2020-12-19 13:49:36 +03:00
|
|
|
line_end = p;
|
2020-12-19 03:20:57 +03:00
|
|
|
}
|
|
|
|
|
2020-12-19 13:57:17 +03:00
|
|
|
curFile->buf_ptr = p;
|
2022-01-08 00:40:56 +03:00
|
|
|
*out_line = line;
|
2020-12-19 03:20:57 +03:00
|
|
|
*out_line_end = line_end;
|
2020-12-19 13:49:36 +03:00
|
|
|
*out_firstBackslash = firstBackslash;
|
2022-01-08 00:57:26 +03:00
|
|
|
*out_commentLineEnd = commentLineEnd;
|
2020-12-19 13:57:17 +03:00
|
|
|
return res;
|
2020-12-19 03:20:57 +03:00
|
|
|
}
|
|
|
|
|
2020-12-19 13:18:46 +03:00
|
|
|
/*
|
|
|
|
* Beginning at start, unescape '\#' to '#' and replace backslash-newline
|
|
|
|
* with a single space.
|
|
|
|
*/
|
2020-12-18 22:02:37 +03:00
|
|
|
static void
|
2020-12-20 21:23:24 +03:00
|
|
|
UnescapeBackslash(char *line, char *start)
|
2020-12-19 02:18:08 +03:00
|
|
|
{
|
2022-01-08 12:55:32 +03:00
|
|
|
const char *src = start;
|
2020-12-19 13:18:46 +03:00
|
|
|
char *dst = start;
|
|
|
|
char *spaceStart = line;
|
2020-12-18 22:02:37 +03:00
|
|
|
|
|
|
|
for (;;) {
|
2020-12-19 13:18:46 +03:00
|
|
|
char ch = *src++;
|
2020-12-18 22:02:37 +03:00
|
|
|
if (ch != '\\') {
|
|
|
|
if (ch == '\0')
|
|
|
|
break;
|
2020-12-19 13:18:46 +03:00
|
|
|
*dst++ = ch;
|
2020-12-18 22:02:37 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-19 13:18:46 +03:00
|
|
|
ch = *src++;
|
2020-12-18 22:02:37 +03:00
|
|
|
if (ch == '\0') {
|
2022-01-08 00:40:56 +03:00
|
|
|
/* Delete '\\' at the end of the buffer. */
|
2020-12-19 13:18:46 +03:00
|
|
|
dst--;
|
2020-12-18 22:02:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:40:56 +03:00
|
|
|
/* Delete '\\' from before '#' on non-command lines. */
|
|
|
|
if (ch == '#' && line[0] != '\t')
|
2020-12-19 13:18:46 +03:00
|
|
|
*dst++ = ch;
|
2022-01-08 00:40:56 +03:00
|
|
|
else if (ch == '\n') {
|
2022-01-08 12:55:32 +03:00
|
|
|
cpp_skip_hspace(&src);
|
2022-01-08 00:40:56 +03:00
|
|
|
*dst++ = ' ';
|
|
|
|
} else {
|
|
|
|
/* Leave '\\' in the buffer for later. */
|
2020-12-19 13:18:46 +03:00
|
|
|
*dst++ = '\\';
|
|
|
|
*dst++ = ch;
|
2022-01-08 00:40:56 +03:00
|
|
|
/* Keep an escaped ' ' at the line end. */
|
|
|
|
spaceStart = dst;
|
2020-12-18 22:02:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 02:18:08 +03:00
|
|
|
/* Delete any trailing spaces - eg from empty continuations */
|
2020-12-19 13:18:46 +03:00
|
|
|
while (dst > spaceStart && ch_isspace(dst[-1]))
|
|
|
|
dst--;
|
|
|
|
*dst = '\0';
|
2020-12-18 22:02:37 +03:00
|
|
|
}
|
|
|
|
|
2021-12-28 19:17:54 +03:00
|
|
|
typedef enum LineKind {
|
2020-12-19 15:48:59 +03:00
|
|
|
/*
|
2020-12-19 18:29:28 +03:00
|
|
|
* Return the next line that is neither empty nor a comment.
|
2020-12-19 15:48:59 +03:00
|
|
|
* Backslash line continuations are folded into a single space.
|
|
|
|
* A trailing comment, if any, is discarded.
|
|
|
|
*/
|
2021-12-28 19:17:54 +03:00
|
|
|
LK_NONEMPTY,
|
2020-12-19 15:48:59 +03:00
|
|
|
|
|
|
|
/*
|
2020-12-19 18:29:28 +03:00
|
|
|
* Return the next line, even if it is empty or a comment.
|
2020-12-19 19:05:33 +03:00
|
|
|
* Preserve backslash-newline to keep the line numbers correct.
|
2020-12-19 15:48:59 +03:00
|
|
|
*
|
|
|
|
* Used in .for loops to collect the body of the loop while waiting
|
|
|
|
* for the corresponding .endfor.
|
|
|
|
*/
|
2021-12-28 19:17:54 +03:00
|
|
|
LK_FOR_BODY,
|
2020-12-19 15:48:59 +03:00
|
|
|
|
|
|
|
/*
|
2020-12-19 19:05:33 +03:00
|
|
|
* Return the next line that starts with a dot.
|
2020-12-19 15:48:59 +03:00
|
|
|
* Backslash line continuations are folded into a single space.
|
|
|
|
* A trailing comment, if any, is discarded.
|
|
|
|
*
|
|
|
|
* Used in .if directives to skip over irrelevant branches while
|
|
|
|
* waiting for the corresponding .endif.
|
|
|
|
*/
|
2021-12-28 19:17:54 +03:00
|
|
|
LK_DOT
|
|
|
|
} LineKind;
|
2007-01-02 00:47:32 +03:00
|
|
|
|
2022-01-09 00:28:59 +03:00
|
|
|
/*
|
|
|
|
* Return the next "interesting" logical line from the current file. The
|
|
|
|
* returned string will be freed at the end of including the file.
|
|
|
|
*/
|
2007-01-02 00:47:32 +03:00
|
|
|
static char *
|
2021-12-28 19:17:54 +03:00
|
|
|
ReadLowLevelLine(LineKind kind)
|
1994-03-05 03:34:29 +03:00
|
|
|
{
|
2022-01-07 16:56:09 +03:00
|
|
|
IncludedFile *curFile = CurFile();
|
2022-01-08 23:21:34 +03:00
|
|
|
ParseRawLineResult res;
|
2020-12-05 22:46:04 +03:00
|
|
|
char *line;
|
|
|
|
char *line_end;
|
2020-12-19 13:49:36 +03:00
|
|
|
char *firstBackslash;
|
2022-01-08 00:57:26 +03:00
|
|
|
char *commentLineEnd;
|
2006-12-16 11:59:29 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (;;) {
|
2022-01-08 23:21:34 +03:00
|
|
|
curFile->lineno = curFile->readLines + 1;
|
|
|
|
res = ParseRawLine(curFile,
|
2022-01-08 00:57:26 +03:00
|
|
|
&line, &line_end, &firstBackslash, &commentLineEnd);
|
2020-12-19 13:57:17 +03:00
|
|
|
if (res == PRLR_ERROR)
|
2020-12-19 03:20:57 +03:00
|
|
|
return NULL;
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2022-01-08 00:57:26 +03:00
|
|
|
if (line == line_end || line == commentLineEnd) {
|
2020-12-19 13:57:17 +03:00
|
|
|
if (res == PRLR_EOF)
|
2020-12-05 22:46:04 +03:00
|
|
|
return NULL;
|
2021-12-28 19:17:54 +03:00
|
|
|
if (kind != LK_FOR_BODY)
|
2020-12-19 15:24:46 +03:00
|
|
|
continue;
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/* We now have a line of data */
|
2020-12-22 11:51:30 +03:00
|
|
|
assert(ch_isspace(*line_end));
|
2020-12-05 22:46:04 +03:00
|
|
|
*line_end = '\0';
|
1994-03-05 03:34:29 +03:00
|
|
|
|
2021-12-28 19:17:54 +03:00
|
|
|
if (kind == LK_FOR_BODY)
|
2020-12-19 19:05:33 +03:00
|
|
|
return line; /* Don't join the physical lines. */
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2021-12-28 19:17:54 +03:00
|
|
|
if (kind == LK_DOT && line[0] != '.')
|
2020-12-19 19:05:33 +03:00
|
|
|
continue;
|
2007-01-02 00:47:32 +03:00
|
|
|
break;
|
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2022-01-08 00:57:26 +03:00
|
|
|
if (commentLineEnd != NULL && line[0] != '\t')
|
|
|
|
*commentLineEnd = '\0';
|
2022-01-08 01:08:09 +03:00
|
|
|
if (firstBackslash != NULL)
|
|
|
|
UnescapeBackslash(line, firstBackslash);
|
2020-12-05 22:46:04 +03:00
|
|
|
return line;
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2021-12-28 19:17:54 +03:00
|
|
|
SkipIrrelevantBranches(void)
|
2020-12-19 20:54:29 +03:00
|
|
|
{
|
2022-01-09 00:28:59 +03:00
|
|
|
const char *line;
|
2020-12-19 20:54:29 +03:00
|
|
|
|
2023-11-02 08:40:49 +03:00
|
|
|
while ((line = ReadLowLevelLine(LK_DOT)) != NULL)
|
2021-12-29 08:01:35 +03:00
|
|
|
if (Cond_EvalLine(line) == CR_TRUE)
|
2022-01-09 00:28:59 +03:00
|
|
|
return true;
|
|
|
|
return false;
|
2020-12-19 20:54:29 +03:00
|
|
|
}
|
|
|
|
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-12-19 20:49:11 +03:00
|
|
|
ParseForLoop(const char *line)
|
|
|
|
{
|
|
|
|
int rval;
|
2022-02-05 02:22:19 +03:00
|
|
|
unsigned forHeadLineno;
|
|
|
|
unsigned bodyReadLines;
|
2022-01-07 23:09:58 +03:00
|
|
|
int forLevel;
|
2020-12-19 20:49:11 +03:00
|
|
|
|
|
|
|
rval = For_Eval(line);
|
|
|
|
if (rval == 0)
|
2021-04-03 14:08:40 +03:00
|
|
|
return false; /* Not a .for line */
|
2020-12-19 20:49:11 +03:00
|
|
|
if (rval < 0)
|
2021-04-03 14:08:40 +03:00
|
|
|
return true; /* Syntax error - error printed, ignore line */
|
2020-12-19 20:49:11 +03:00
|
|
|
|
2022-01-09 01:42:27 +03:00
|
|
|
forHeadLineno = CurFile()->lineno;
|
|
|
|
bodyReadLines = CurFile()->readLines;
|
|
|
|
|
2022-01-02 04:54:43 +03:00
|
|
|
/* Accumulate the loop body until the matching '.endfor'. */
|
2022-01-07 23:09:58 +03:00
|
|
|
forLevel = 1;
|
2020-12-19 20:49:11 +03:00
|
|
|
do {
|
2021-12-28 19:17:54 +03:00
|
|
|
line = ReadLowLevelLine(LK_FOR_BODY);
|
2020-12-19 20:49:11 +03:00
|
|
|
if (line == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
2021-12-09 23:13:09 +03:00
|
|
|
"Unexpected end of file in .for loop");
|
2020-12-19 20:49:11 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-01-07 23:09:58 +03:00
|
|
|
} while (For_Accum(line, &forLevel));
|
2020-12-19 20:49:11 +03:00
|
|
|
|
2022-01-08 23:21:34 +03:00
|
|
|
For_Run(forHeadLineno, bodyReadLines);
|
2022-01-02 04:54:43 +03:00
|
|
|
return true;
|
2020-12-19 20:49:11 +03:00
|
|
|
}
|
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
2020-12-15 02:48:03 +03:00
|
|
|
* Read an entire line from the input file.
|
|
|
|
*
|
2023-11-02 08:40:49 +03:00
|
|
|
* Empty lines, .if and .for are handled by this function, while variable
|
|
|
|
* assignments, other directives, dependency lines and shell commands are
|
|
|
|
* handled by the caller.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
2022-01-08 12:55:32 +03:00
|
|
|
* Return a line without trailing whitespace, or NULL for EOF. The returned
|
|
|
|
* string will be freed at the end of including the file.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
static char *
|
2021-12-28 19:17:54 +03:00
|
|
|
ReadHighLevelLine(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-19 20:49:11 +03:00
|
|
|
char *line;
|
2023-06-19 15:53:57 +03:00
|
|
|
CondResult condResult;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (;;) {
|
2023-06-19 15:53:57 +03:00
|
|
|
IncludedFile *curFile = CurFile();
|
2021-12-28 19:17:54 +03:00
|
|
|
line = ReadLowLevelLine(LK_NONEMPTY);
|
2022-04-18 18:06:27 +03:00
|
|
|
if (posix_state == PS_MAYBE_NEXT_LINE)
|
|
|
|
posix_state = PS_NOW_OR_NEVER;
|
|
|
|
else
|
|
|
|
posix_state = PS_TOO_LATE;
|
2020-12-05 22:46:04 +03:00
|
|
|
if (line == NULL)
|
|
|
|
return NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2024-04-14 15:30:47 +03:00
|
|
|
DEBUG2(PARSE, "Parsing line %u: %s\n", curFile->lineno, line);
|
2023-06-20 12:25:33 +03:00
|
|
|
if (curFile->guardState != GS_NO
|
|
|
|
&& ((curFile->guardState == GS_START && line[0] != '.')
|
|
|
|
|| curFile->guardState == GS_DONE))
|
|
|
|
curFile->guardState = GS_NO;
|
2020-12-05 22:46:04 +03:00
|
|
|
if (line[0] != '.')
|
|
|
|
return line;
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2023-06-19 15:53:57 +03:00
|
|
|
condResult = Cond_EvalLine(line);
|
2023-06-20 12:25:33 +03:00
|
|
|
if (curFile->guardState == GS_START) {
|
|
|
|
Guard *guard;
|
2023-06-21 17:33:36 +03:00
|
|
|
if (condResult != CR_ERROR
|
2023-06-20 12:25:33 +03:00
|
|
|
&& (guard = Cond_ExtractGuard(line)) != NULL) {
|
|
|
|
curFile->guardState = GS_COND;
|
|
|
|
curFile->guard = guard;
|
2023-06-19 15:53:57 +03:00
|
|
|
} else
|
2023-06-20 12:25:33 +03:00
|
|
|
curFile->guardState = GS_NO;
|
2023-06-19 15:53:57 +03:00
|
|
|
}
|
|
|
|
switch (condResult) {
|
2021-12-29 08:01:35 +03:00
|
|
|
case CR_FALSE: /* May also mean a syntax error. */
|
2021-12-28 19:17:54 +03:00
|
|
|
if (!SkipIrrelevantBranches())
|
2020-12-15 02:48:03 +03:00
|
|
|
return NULL;
|
2020-12-05 22:46:04 +03:00
|
|
|
continue;
|
2021-12-29 08:01:35 +03:00
|
|
|
case CR_TRUE:
|
2020-12-05 22:46:04 +03:00
|
|
|
continue;
|
2021-12-29 08:01:35 +03:00
|
|
|
case CR_ERROR: /* Not a conditional line */
|
2020-12-19 20:49:11 +03:00
|
|
|
if (ParseForLoop(line))
|
2020-12-05 22:46:04 +03:00
|
|
|
continue;
|
2020-12-19 20:49:11 +03:00
|
|
|
break;
|
1994-03-05 03:34:29 +03:00
|
|
|
}
|
2020-12-05 22:46:04 +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-12-05 22:46:04 +03:00
|
|
|
GNodeListNode *ln;
|
2020-10-17 20:16:54 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (targets == NULL)
|
|
|
|
return;
|
2020-10-17 20:16:54 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
2020-10-17 20:16:54 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
Suff_EndTransform(gn);
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
Lst_Free(targets);
|
|
|
|
targets = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1996-11-06 20:58:58 +03:00
|
|
|
|
2024-05-26 00:07:48 +03:00
|
|
|
#ifdef CLEANUP
|
|
|
|
void Parse_RegisterCommand(char *cmd)
|
|
|
|
{
|
|
|
|
Lst_Append(&targCmds, cmd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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-12-05 22:46:04 +03:00
|
|
|
cpp_skip_whitespace(&p);
|
|
|
|
if (*p == '\0')
|
|
|
|
return; /* skip empty commands */
|
2020-09-26 00:13:44 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (targets == NULL) {
|
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"Unassociated shell command \"%s\"", p);
|
|
|
|
return;
|
|
|
|
}
|
2020-09-26 00:13:44 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
{
|
|
|
|
char *cmd = bmake_strdup(p);
|
|
|
|
GNodeListNode *ln;
|
2020-09-26 00:13:44 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (ln = targets->first; ln != NULL; ln = ln->next) {
|
|
|
|
GNode *gn = ln->datum;
|
2021-12-28 19:17:54 +03:00
|
|
|
GNode_AddCommand(gn, cmd);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2024-05-26 00:07:48 +03:00
|
|
|
Parse_RegisterCommand(cmd);
|
2020-12-05 22:46:04 +03:00
|
|
|
}
|
2020-09-25 23:57:22 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2022-09-03 03:50:07 +03:00
|
|
|
static void
|
2023-06-01 09:25:34 +03:00
|
|
|
HandleBreak(const char *arg)
|
2022-09-03 03:50:07 +03:00
|
|
|
{
|
|
|
|
IncludedFile *curFile = CurFile();
|
|
|
|
|
2023-06-01 09:25:34 +03:00
|
|
|
if (arg[0] != '\0')
|
|
|
|
Parse_Error(PARSE_FATAL,
|
|
|
|
"The .break directive does not take arguments");
|
|
|
|
|
2022-09-03 03:50:07 +03:00
|
|
|
if (curFile->forLoop != NULL) {
|
|
|
|
/* pretend we reached EOF */
|
|
|
|
For_Break(curFile->forLoop);
|
2022-09-24 19:13:48 +03:00
|
|
|
cond_depth = CurFile_CondMinDepth();
|
2022-09-03 03:50:07 +03:00
|
|
|
ParseEOF();
|
|
|
|
} else
|
|
|
|
Parse_Error(PARSE_FATAL, "break outside of for loop");
|
|
|
|
}
|
|
|
|
|
2020-12-13 00:35:21 +03:00
|
|
|
/*
|
2020-12-13 04:51:08 +03:00
|
|
|
* See if the line starts with one of the known directives, and if so, handle
|
|
|
|
* the directive.
|
2020-12-13 00:35:21 +03:00
|
|
|
*/
|
2021-04-03 14:08:40 +03:00
|
|
|
static bool
|
2020-10-17 23:37:38 +03:00
|
|
|
ParseDirective(char *line)
|
|
|
|
{
|
2023-12-17 11:53:54 +03:00
|
|
|
char *p = line + 1;
|
2021-12-05 02:47:09 +03:00
|
|
|
const char *arg;
|
|
|
|
Substring dir;
|
2020-10-17 23:37:38 +03:00
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
pp_skip_whitespace(&p);
|
|
|
|
if (IsInclude(p, false)) {
|
|
|
|
ParseInclude(p);
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-12-13 00:35:21 +03:00
|
|
|
}
|
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
dir.start = p;
|
|
|
|
while (ch_islower(*p) || *p == '-')
|
|
|
|
p++;
|
|
|
|
dir.end = p;
|
2020-12-13 04:07:54 +03:00
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
if (*p != '\0' && !ch_isspace(*p))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2020-12-13 04:07:54 +03:00
|
|
|
|
2023-12-17 11:53:54 +03:00
|
|
|
pp_skip_whitespace(&p);
|
|
|
|
arg = p;
|
2020-12-13 04:07:54 +03:00
|
|
|
|
2022-09-03 03:50:07 +03:00
|
|
|
if (Substring_Equals(dir, "break"))
|
2023-06-01 09:25:34 +03:00
|
|
|
HandleBreak(arg);
|
2022-09-03 03:50:07 +03:00
|
|
|
else if (Substring_Equals(dir, "undef"))
|
2021-12-05 02:47:09 +03:00
|
|
|
Var_Undef(arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "export"))
|
2020-12-27 08:06:17 +03:00
|
|
|
Var_Export(VEM_PLAIN, arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "export-env"))
|
2020-12-27 08:06:17 +03:00
|
|
|
Var_Export(VEM_ENV, arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "export-literal"))
|
2020-12-13 04:41:12 +03:00
|
|
|
Var_Export(VEM_LITERAL, arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "unexport"))
|
2021-04-03 14:08:40 +03:00
|
|
|
Var_UnExport(false, arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "unexport-env"))
|
2021-04-03 14:08:40 +03:00
|
|
|
Var_UnExport(true, arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "info"))
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleMessage(PARSE_INFO, "info", arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "warning"))
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleMessage(PARSE_WARNING, "warning", arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else if (Substring_Equals(dir, "error"))
|
2021-12-28 22:41:01 +03:00
|
|
|
HandleMessage(PARSE_FATAL, "error", arg);
|
2021-12-14 04:18:14 +03:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
2020-10-17 23:37:38 +03:00
|
|
|
}
|
|
|
|
|
2021-12-31 03:18:06 +03:00
|
|
|
bool
|
|
|
|
Parse_VarAssign(const char *line, bool finishDependencyGroup, GNode *scope)
|
2020-10-17 23:37:38 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
VarAssign var;
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (!Parse_IsVar(line, &var))
|
2021-04-03 14:08:40 +03:00
|
|
|
return false;
|
2021-12-31 03:18:06 +03:00
|
|
|
if (finishDependencyGroup)
|
|
|
|
FinishDependencyGroup();
|
|
|
|
Parse_Var(&var, scope);
|
2022-01-29 04:07:31 +03:00
|
|
|
free(var.varname);
|
2021-04-03 14:08:40 +03:00
|
|
|
return true;
|
2020-10-17 23:37:38 +03:00
|
|
|
}
|
|
|
|
|
2023-06-19 15:53:57 +03:00
|
|
|
void
|
|
|
|
Parse_GuardElse(void)
|
|
|
|
{
|
|
|
|
IncludedFile *curFile = CurFile();
|
|
|
|
if (cond_depth == curFile->condMinDepth + 1)
|
2023-06-20 12:25:33 +03:00
|
|
|
curFile->guardState = GS_NO;
|
2023-06-19 15:53:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Parse_GuardEndif(void)
|
|
|
|
{
|
|
|
|
IncludedFile *curFile = CurFile();
|
2023-06-20 12:25:33 +03:00
|
|
|
if (cond_depth == curFile->condMinDepth
|
|
|
|
&& curFile->guardState == GS_COND)
|
|
|
|
curFile->guardState = GS_DONE;
|
2023-06-19 15:53:57 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 23:51:34 +03:00
|
|
|
static char *
|
|
|
|
FindSemicolon(char *p)
|
|
|
|
{
|
2023-12-17 11:53:54 +03:00
|
|
|
int depth = 0;
|
2020-10-17 23:51:34 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
for (; *p != '\0'; p++) {
|
|
|
|
if (*p == '\\' && p[1] != '\0') {
|
|
|
|
p++;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-17 23:51:34 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (*p == '$' && (p[1] == '(' || p[1] == '{'))
|
2023-12-17 11:53:54 +03:00
|
|
|
depth++;
|
|
|
|
else if (depth > 0 && (*p == ')' || *p == '}'))
|
|
|
|
depth--;
|
|
|
|
else if (depth == 0 && *p == ';')
|
2020-12-05 22:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return p;
|
2020-10-17 23:51:34 +03:00
|
|
|
}
|
|
|
|
|
2020-10-17 23:37:38 +03:00
|
|
|
static void
|
2021-04-04 12:58:51 +03:00
|
|
|
ParseDependencyLine(char *line)
|
2020-10-17 23:37:38 +03:00
|
|
|
{
|
2021-04-04 14:56:43 +03:00
|
|
|
VarEvalMode emode;
|
2020-12-05 22:46:04 +03:00
|
|
|
char *expanded_line;
|
|
|
|
const char *shellcmd = NULL;
|
|
|
|
|
|
|
|
{
|
|
|
|
char *semicolon = FindSemicolon(line);
|
|
|
|
if (*semicolon != '\0') {
|
|
|
|
/* Terminate the dependency list at the ';' */
|
|
|
|
*semicolon = '\0';
|
|
|
|
shellcmd = semicolon + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2023-11-02 08:40:49 +03:00
|
|
|
* We now know it's a dependency line, so it needs to have all
|
2020-12-05 22:46:04 +03:00
|
|
|
* 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
|
2023-11-20 01:50:11 +03:00
|
|
|
* generated from expressions are interpreted as the
|
2020-12-05 22:46:04 +03:00
|
|
|
* dependency operator, such as in "target${:U\:} middle: source",
|
|
|
|
* in which the middle is interpreted as a source, not a target.
|
|
|
|
*/
|
|
|
|
|
2021-12-15 15:58:01 +03:00
|
|
|
/*
|
|
|
|
* In lint mode, allow undefined variables to appear in dependency
|
|
|
|
* lines.
|
2020-12-05 22:46:04 +03:00
|
|
|
*
|
2021-12-15 15:58:01 +03:00
|
|
|
* Ideally, only the right-hand side would allow undefined variables
|
|
|
|
* since it is common to have optional 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.
|
2020-12-05 22:46:04 +03:00
|
|
|
*
|
2021-12-15 15:58:01 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
2021-04-04 14:56:43 +03:00
|
|
|
emode = opts.strict ? VARE_WANTRES : VARE_UNDEFERR;
|
2023-02-15 00:38:31 +03:00
|
|
|
expanded_line = Var_Subst(line, SCOPE_CMDLINE, emode);
|
2020-12-05 22:46:04 +03:00
|
|
|
/* TODO: handle errors */
|
|
|
|
|
|
|
|
/* Need a fresh list for the target nodes */
|
|
|
|
if (targets != NULL)
|
|
|
|
Lst_Free(targets);
|
|
|
|
targets = Lst_New();
|
2020-10-17 23:37:38 +03:00
|
|
|
|
2023-08-19 14:09:02 +03:00
|
|
|
ParseDependency(expanded_line, line);
|
2020-12-05 22:46:04 +03:00
|
|
|
free(expanded_line);
|
2020-10-17 23:51:34 +03:00
|
|
|
|
2020-12-05 22:46:04 +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)
|
|
|
|
{
|
2020-12-13 00:35:21 +03:00
|
|
|
if (line[0] == '.' && ParseDirective(line))
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2020-12-13 05:01:43 +03:00
|
|
|
if (line[0] == '\t') {
|
2020-12-05 22:46:04 +03:00
|
|
|
ParseLine_ShellCommand(line + 1);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (IsSysVInclude(line)) {
|
|
|
|
ParseTraditionalInclude(line);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
if (strncmp(line, "export", 6) == 0 && ch_isspace(line[6]) &&
|
|
|
|
strchr(line, ':') == NULL) {
|
|
|
|
ParseGmakeExport(line);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2021-12-31 03:18:06 +03:00
|
|
|
if (Parse_VarAssign(line, true, SCOPE_GLOBAL))
|
2020-12-05 22:46:04 +03:00
|
|
|
return;
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
FinishDependencyGroup();
|
2020-10-17 23:57:08 +03:00
|
|
|
|
2021-04-04 12:58:51 +03:00
|
|
|
ParseDependencyLine(line);
|
2020-10-17 23:57:08 +03:00
|
|
|
}
|
|
|
|
|
2023-11-02 08:40:49 +03:00
|
|
|
/* Interpret a top-level makefile. */
|
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
|
|
|
{
|
2022-01-02 00:41:50 +03:00
|
|
|
char *line;
|
2022-01-02 04:54:43 +03:00
|
|
|
Buffer buf;
|
2010-12-25 07:57:07 +03:00
|
|
|
|
2022-06-11 01:42:47 +03:00
|
|
|
buf = LoadFile(name, fd != -1 ? fd : STDIN_FILENO);
|
2022-01-02 00:41:50 +03:00
|
|
|
if (fd != -1)
|
|
|
|
(void)close(fd);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
assert(targets == NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2022-01-08 23:21:34 +03:00
|
|
|
Parse_PushInput(name, 1, 0, buf, NULL);
|
1999-08-10 01:06:28 +04:00
|
|
|
|
2020-12-05 22:46:04 +03:00
|
|
|
do {
|
2021-12-28 19:17:54 +03:00
|
|
|
while ((line = ReadHighLevelLine()) != NULL) {
|
2020-12-05 22:46:04 +03:00
|
|
|
ParseLine(line);
|
|
|
|
}
|
|
|
|
} while (ParseEOF());
|
|
|
|
|
|
|
|
FinishDependencyGroup();
|
|
|
|
|
2021-08-14 16:32:12 +03:00
|
|
|
if (parseErrors != 0) {
|
2020-12-05 22:46:04 +03:00
|
|
|
(void)fflush(stdout);
|
|
|
|
(void)fprintf(stderr,
|
2022-01-22 21:59:23 +03:00
|
|
|
"%s: Fatal errors encountered -- cannot continue\n",
|
2020-12-05 22:46:04 +03:00
|
|
|
progname);
|
2022-01-22 21:59:23 +03:00
|
|
|
PrintOnError(NULL, "");
|
2020-12-05 22:46:04 +03: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
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
mainNode = NULL;
|
|
|
|
parseIncPath = SearchPath_New();
|
|
|
|
sysIncPath = SearchPath_New();
|
|
|
|
defSysIncPath = SearchPath_New();
|
2022-01-07 16:56:09 +03:00
|
|
|
Vector_Init(&includes, sizeof(IncludedFile));
|
2023-06-19 15:53:57 +03:00
|
|
|
HashTable_Init(&guards);
|
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
|
2023-06-19 15:53:57 +03:00
|
|
|
HashIter hi;
|
|
|
|
|
2024-04-27 20:33:46 +03:00
|
|
|
Lst_DoneFree(&targCmds);
|
2020-12-05 22:46:04 +03:00
|
|
|
assert(targets == NULL);
|
|
|
|
SearchPath_Free(defSysIncPath);
|
|
|
|
SearchPath_Free(sysIncPath);
|
|
|
|
SearchPath_Free(parseIncPath);
|
|
|
|
assert(includes.len == 0);
|
|
|
|
Vector_Done(&includes);
|
2023-06-19 15:53:57 +03:00
|
|
|
HashIter_Init(&hi, &guards);
|
2024-05-31 08:50:11 +03:00
|
|
|
while (HashIter_Next(&hi)) {
|
2023-06-20 12:25:33 +03:00
|
|
|
Guard *guard = hi.entry->value;
|
|
|
|
free(guard->name);
|
|
|
|
free(guard);
|
|
|
|
}
|
2023-06-19 15:53:57 +03:00
|
|
|
HashTable_Done(&guards);
|
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
|
|
|
|
2023-05-10 18:57:16 +03:00
|
|
|
/* Populate the list with the single main target to create, or error out. */
|
2020-11-29 03:04:22 +03:00
|
|
|
void
|
|
|
|
Parse_MainName(GNodeList *mainList)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2020-12-05 22:46:04 +03:00
|
|
|
if (mainNode == NULL)
|
|
|
|
Punt("no target to make.");
|
2020-11-08 01:25:19 +03:00
|
|
|
|
2021-01-21 17:30:01 +03:00
|
|
|
Lst_Append(mainList, mainNode);
|
|
|
|
if (mainNode->type & OP_DOUBLEDEP)
|
2020-12-05 22:46:04 +03:00
|
|
|
Lst_AppendAll(mainList, &mainNode->cohorts);
|
make(1): clean up make.h, meta.c, parse.c, str.c
The main changes are in the comments, which have been shortened and
corrected.
Some local variables changed their names.
In ParseErrorInternal, the scope of va_start is now narrower.
In ParseDoDependency, the type of tOp has been fixed.
ParseGetLine doesn't take flags anymore but instead a parsing mode.
Previously, the flags had not been combined anyway.
At the beginning of Parse_File, fatals is already guaranteed to be 0, and
even if not, it would be wrong to just discard the fatal errors.
2020-11-15 15:02:44 +03:00
|
|
|
|
2021-02-03 16:53:12 +03:00
|
|
|
Global_Append(".TARGETS", mainNode->name);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2020-11-01 03:24:57 +03:00
|
|
|
|
|
|
|
int
|
2021-08-14 16:32:12 +03:00
|
|
|
Parse_NumErrors(void)
|
2020-11-01 03:24:57 +03:00
|
|
|
{
|
2021-08-14 16:32:12 +03:00
|
|
|
return parseErrors;
|
2020-11-01 03:24:57 +03:00
|
|
|
}
|