summaryrefslogtreecommitdiff
path: root/src/variable.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2023-03-18 17:24:45 -0400
committerPaul Smith <psmith@gnu.org>2023-04-02 10:02:18 -0400
commita0d1e76d604df5bd006fd5ed6a69963d3c6b4d7a (patch)
tree02d739d8168207be28535f359b0a6583f231f047 /src/variable.c
parent03ecd94488b85adc38746ec3e7c2a297a522598e (diff)
downloadmake-git-a0d1e76d604df5bd006fd5ed6a69963d3c6b4d7a.tar.gz
Add support for .WARNINGS special variable
Create a new special variable, .WARNINGS, to allow per-makefile control over warnings. The command line settings will override this. Move the handling of warning flags to a new file: src/warning.c. Allow the decode to work with generic strings, and call it from decode_switches(). * Makefile.am: Add new file src/warning.c. * build_w32.bat: Ditto. * builddos.bat: Ditto. * po/POTFILES.in: Ditto. * src/makeint.h: #define for the .WARNINGS variable name. * src/warning.h: Add declarations for methods moved from main.c. Rename the enum warning_state to warning_action. * src/warning.c: New file. Move all warning encode/decode here from main.c. * src/main.c: Move methods into warning.c and call those methods instead. (main): Set .WARNINGS as a special variable. * src/job.c (construct_command_argv): Rename to warning_action. * src/read.c (tilde_expand): Ditto. * src/variable.c (set_special_var): Update warnings when the .WARNINGS special variable is set. * tests/scripts/options/warn: Check invalid warning options. * tests/scripts/variables/WARNINGS: Add tests for the .WARNINGS special variable.
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/src/variable.c b/src/variable.c
index d2cfcc94..bfaef6c1 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -198,10 +198,8 @@ check_valid_name (const floc* flocp, const char *name, size_t length)
if (cp == end)
return;
- if (warn_error (wt_invalid_var))
- ONS (fatal, flocp, _("invalid variable name '%.*s'"), (int)length, name);
-
- ONS (error, flocp, _("invalid variable name '%.*s'"), (int)length, name);
+ warning (wt_invalid_var, flocp,
+ ONS (format, 0, _("invalid variable name '%.*s'"), (int)length, name));
}
void
@@ -491,12 +489,8 @@ check_variable_reference (const char *name, size_t length)
if (cp == end)
return;
- if (warn_error (wt_invalid_ref))
- ONS (fatal, *expanding_var,
- _("invalid variable reference '%.*s'"), (int)length, name);
-
- ONS (error, *expanding_var,
- _("invalid variable reference '%.*s'"), (int)length, name);
+ warning (wt_invalid_ref, *expanding_var,
+ ONS (format, 0, _("invalid variable reference '%.*s'"), (int)length, name));
}
/* Lookup a variable whose name is a string starting at NAME
@@ -1335,11 +1329,18 @@ set_special_var (struct variable *var, enum variable_origin origin)
reset_makeflags (origin);
else if (streq (var->name, RECIPEPREFIX_NAME))
+ /* The user is resetting the command introduction prefix. This has to
+ happen immediately, so that subsequent rules are interpreted
+ properly. */
+ cmd_prefix = var->value[0]=='\0' ? RECIPEPREFIX_DEFAULT : var->value[0];
+
+ else if (streq (var->name, WARNINGS_NAME))
{
- /* The user is resetting the command introduction prefix. This has to
- happen immediately, so that subsequent rules are interpreted
- properly. */
- cmd_prefix = var->value[0]=='\0' ? RECIPEPREFIX_DEFAULT : var->value[0];
+ /* It's weird but for .WARNINGS to make sense we need to expand them
+ when they are set, even if it's a recursive variable. */
+ char *actions = allocated_expand_variable (STRING_SIZE_TUPLE (WARNINGS_NAME));
+ decode_warn_actions (actions, &var->fileinfo);
+ free (actions);
}
return var;
@@ -1499,7 +1500,7 @@ do_variable_definition (const floc *flocp, const char *varname,
{
char *s;
if (streq (varname, MAKEFLAGS_NAME)
- && (s = strstr (v->value, " -- ")))
+ && (s = strstr (v->value, " -- ")) != NULL)
/* We found a separator in MAKEFLAGS. Ignore variable
assignments: set_special_var() will reconstruct things. */
cp = mempcpy (cp, v->value, s - v->value);
@@ -1914,6 +1915,7 @@ static const struct defined_vars defined_vars[] = {
{ STRING_SIZE_TUPLE ("-*-eval-flags-*-") },
{ STRING_SIZE_TUPLE ("VPATH") },
{ STRING_SIZE_TUPLE ("GPATH") },
+ { STRING_SIZE_TUPLE (WARNINGS_NAME) },
{ NULL, 0 }
};
@@ -1927,12 +1929,9 @@ warn_undefined (const char *name, size_t len)
if (dp->len == len && memcmp (dp->name, name, len) == 0)
return;
- if (warn_error (wt_undefined_var))
- fatal (reading_file, len, _("reference to undefined variable '%.*s'"),
- (int)len, name);
- else
- error (reading_file, len, _("reference to undefined variable '%.*s'"),
- (int)len, name);
+ warning (wt_undefined_var, reading_file,
+ ONS (format, 0, _("reference to undefined variable '%.*s'"),
+ (int)len, name));
}
}