summaryrefslogtreecommitdiff
path: root/usr.bin/make/parse.c
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-09-14 21:23:58 +0000
committerrillig <rillig@NetBSD.org>2020-09-14 21:23:58 +0000
commitf583eeb5acbe55a56ccb3e35db2377767bb64f96 (patch)
tree79dc62203d67601ecda60ad00a998d092e001814 /usr.bin/make/parse.c
parentb6cf9e0918e0a3fc202c1dc98ce715afec39ff65 (diff)
make(1): in lint mode, allow undefined variables in dependency lines
This is needed to get past the first few seconds in a src/build.sh run. The nest obstacle is src/tools/Makefile.gnuhost:30, where the variable MODULE is undefined even though that file says in line 3 that MODULE is expected to be set. It has been saying this since 2001, but since make didn't have the corresponding check enabled, this didn't break the build.
Diffstat (limited to 'usr.bin/make/parse.c')
-rw-r--r--usr.bin/make/parse.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index fdab4bc6c85..936bcff0736 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.319 2020/09/14 19:59:47 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.320 2020/09/14 21:23:58 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.319 2020/09/14 19:59:47 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.320 2020/09/14 21:23:58 rillig Exp $");
/* types and constants */
@@ -3067,10 +3067,40 @@ Parse_File(const char *name, int fd)
/*
* We now know it's a dependency line so it needs to have all
- * variables expanded before being parsed. Tell the variable
- * module to complain if some variable is undefined...
+ * variables expanded before being parsed.
+ *
+ * XXX: Ideally the dependency line would first be split into
+ * its left-hand side, dependency operator and right-hand side,
+ * and then each side would be expanded on its own. This would
+ * allow for the left-hand side to allow only defined variables
+ * and to allow variables on the right-hand side to be undefined
+ * as well.
+ *
+ * Parsing the line first would also prevent that targets
+ * generated from variable expressions are interpreted as the
+ * dependency operator, such as in "target${:U:} middle: source",
+ * in which the middle is interpreted as a source, not a target.
*/
- line = Var_Subst(line, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES);
+ {
+ /* In lint mode, allow undefined variables to appear in
+ * dependency lines.
+ *
+ * Ideally, only the right-hand side would allow undefined
+ * variables since it is common to have no dependencies.
+ * Having undefined variables on the left-hand side is more
+ * unusual though. Since both sides are expanded in a single
+ * pass, there is not much choice what to do here.
+ *
+ * In normal mode, it does not matter whether undefined
+ * variables are allowed or not since as of 2020-09-14,
+ * Var_Parse does not print any parse errors in such a case.
+ * It simply returns the special empty string var_Error,
+ * which cannot be detected in the result of Var_Subst. */
+ VarEvalFlags eflags = DEBUG(LINT)
+ ? VARE_WANTRES
+ : VARE_UNDEFERR|VARE_WANTRES;
+ line = Var_Subst(line, VAR_CMD, eflags);
+ }
/*
* Need a list for the target nodes