summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2022-12-24 10:30:13 -0500
committerPaul Smith <psmith@gnu.org>2022-12-24 10:52:49 -0500
commit15dfad96d77c9445d11be939a5042675e4ca8c65 (patch)
tree34e2b52a28a894db8ecf01e15103aa511ba104e1
parent76d2e5d98dbbf655f74f6ef2f6dd3cdd45052ea0 (diff)
downloadmake-git-15dfad96d77c9445d11be939a5042675e4ca8c65.tar.gz
[SV 63439, SV 63452] Don't warn on undefined internal variables
Don't generate undefined variable warnings for variables that are internal / special to make and where the empty string is valid. Rather than defining them to empty, which could introduce unwanted behavior, keep a list of variable names which we should never warn about. * src/variable.h (warn_undefined): Convert the macro to a function. * src/variable.c (defined_vars): Always "defined" variable names. (warn_undefined): Implement as a function and check against the defined_vars before generating a warning. * src/read.c (read_all_makefiles): No need to reset warning flag. * src/vpath.c (build_vpath_lists): Ditto. * tests/scripts/options/warn-undefined-variables: Expand all the pre-defined variables to ensure warnings are not generated.
-rw-r--r--src/read.c10
-rw-r--r--src/variable.c24
-rw-r--r--src/variable.h10
-rw-r--r--src/vpath.c30
-rw-r--r--tests/scripts/options/warn-undefined-variables13
5 files changed, 45 insertions, 42 deletions
diff --git a/src/read.c b/src/read.c
index 9f2ed5cf..e8ad1234 100644
--- a/src/read.c
+++ b/src/read.c
@@ -192,15 +192,7 @@ read_all_makefiles (const char **makefiles)
char *name, *p;
size_t length;
- {
- /* Turn off --warn-undefined-variables while we expand MAKEFILES. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
-
- value = allocated_variable_expand ("$(MAKEFILES)");
-
- warn_undefined_variables_flag = save;
- }
+ value = allocated_variable_expand ("$(MAKEFILES)");
/* Set NAME to the start of next token and LENGTH to its length.
MAKEFILES is updated for finding remaining tokens. */
diff --git a/src/variable.c b/src/variable.c
index 1b1cb743..48593305 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -1782,6 +1782,30 @@ try_variable_definition (const floc *flocp, const char *line,
return vp;
}
+
+/* These variables are internal to make, and so considered "defined" for the
+ purposes of warn_undefined even if they are not really defined. */
+
+static const char *const defined_vars[] = {
+ "MAKECMDGOALS", "MAKE_RESTARTS", "MAKE_TERMOUT", "MAKE_TERMERR",
+ "MAKEOVERRIDES", ".DEFAULT", "-*-command-variables-*-", "-*-eval-flags-*-",
+ "VPATH", "GPATH",
+ NULL };
+
+void
+warn_undefined (const char *name, size_t len)
+{
+ if (warn_undefined_variables_flag)
+ {
+ const char *const *cp;
+ for (cp = defined_vars; *cp != NULL; ++cp)
+ if (memcmp (*cp, name, len) == 0 && (*cp)[len] == '\0')
+ return;
+
+ error (reading_file, len, _("warning: undefined variable '%.*s'"),
+ (int)len, name);
+ }
+}
/* Print information for variable V, prefixing it with PREFIX. */
diff --git a/src/variable.h b/src/variable.h
index d377a47f..d0cb775d 100644
--- a/src/variable.h
+++ b/src/variable.h
@@ -191,6 +191,7 @@ struct variable *define_variable_in_set (const char *name, size_t length,
int recursive,
struct variable_set *set,
const floc *flocp);
+void warn_undefined (const char* name, size_t length);
/* Define a variable in the current variable set. */
@@ -229,15 +230,6 @@ void undefine_variable_in_set (const char *name, size_t length,
#define undefine_variable_global(n,l,o) \
undefine_variable_in_set((n),(l),(o),NULL)
-/* Warn that NAME is an undefined variable. */
-
-#define warn_undefined(n,l) do{\
- if (warn_undefined_variables_flag) \
- error (reading_file, (l), \
- _("warning: undefined variable '%.*s'"), \
- (int)(l), (n)); \
- }while(0)
-
char **target_environment (struct file *file, int recursive);
struct pattern_var *create_pattern_var (const char *target,
diff --git a/src/vpath.c b/src/vpath.c
index 9c95441f..9af4213c 100644
--- a/src/vpath.c
+++ b/src/vpath.c
@@ -68,19 +68,10 @@ build_vpath_lists (void)
vpaths = new;
- /* If there is a VPATH variable with a nonnull value, construct the
- general VPATH list from it. We use variable_expand rather than just
- calling lookup_variable so that it will be recursively expanded. */
+ /* If there is a VPATH variable with a nonnull expanded value, construct the
+ general VPATH list from it. */
- {
- /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
-
- p = variable_expand ("$(strip $(VPATH))");
-
- warn_undefined_variables_flag = save;
- }
+ p = variable_expand ("$(strip $(VPATH))");
if (*p != '\0')
{
@@ -101,19 +92,10 @@ build_vpath_lists (void)
vpaths = save_vpaths;
}
- /* If there is a GPATH variable with a nonnull value, construct the
- GPATH list from it. We use variable_expand rather than just
- calling lookup_variable so that it will be recursively expanded. */
+ /* If there is a GPATH variable with a nonnull expanded value, construct the
+ GPATH list from it. */
- {
- /* Turn off --warn-undefined-variables while we expand SHELL and IFS. */
- int save = warn_undefined_variables_flag;
- warn_undefined_variables_flag = 0;
-
- p = variable_expand ("$(strip $(GPATH))");
-
- warn_undefined_variables_flag = save;
- }
+ p = variable_expand ("$(strip $(GPATH))");
if (*p != '\0')
{
diff --git a/tests/scripts/options/warn-undefined-variables b/tests/scripts/options/warn-undefined-variables
index ce15507d..9bd40865 100644
--- a/tests/scripts/options/warn-undefined-variables
+++ b/tests/scripts/options/warn-undefined-variables
@@ -4,6 +4,19 @@ $description = "Test the --warn-undefined-variables option.";
$details = "Verify that warnings are printed for referencing undefined variables.";
+# Verify that make's special variables don't warn even if they're not set
+run_make_test(q!
+vars := $(.VARIABLES) $(MAKECMDGOALS) $(MAKE_RESTARTS) $(CURDIR)
+vars += $(GNUMAKEFLAGS) $(MAKEFLAGS) $(MFLAGS) $(MAKE_COMMAND) $(MAKE)
+vars += $(MAKEFILE_LIST) $(MAKEOVERRIDES) $(-*-command-variables-*-)
+vars += $(.RECIPEPREFIX) $(.LOADED) $(.FEATURES)
+vars += $(SHELL) $(.SHELLFLAGS) $(MAKE_TERMOUT) $(MAKE_TERMERR)
+vars += $(.DEFAULT) $(.DEFAULT_GOAL) $(-*-eval-flags-*-) $(SUFFIXES)
+vars += $(VPATH) $(GPATH)
+all:;
+!,
+ '--warn-undefined-variables', "#MAKE#: 'all' is up to date.");
+
# Without --warn-undefined-variables, nothing should happen
run_make_test('
EMPTY =