diff options
author | Paul Smith <psmith@gnu.org> | 2023-02-26 18:04:14 -0500 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2023-04-01 11:13:12 -0400 |
commit | 2611e1991fabe2a3ae929c6ebd4afbd4f550f306 (patch) | |
tree | 0733d2ff7f545c8ba0b4c032a309cde459dfdfce /src/variable.c | |
parent | 9db74434cd34b2b875b3f9bfbab4f1e0b682e27c (diff) | |
download | make-git-2611e1991fabe2a3ae929c6ebd4afbd4f550f306.tar.gz |
Introduce a --warn command line option
Replace the singleton --warn-undefined-variables with infrastructure
to manage multiple warnings: the --warn option can take an action
"ignore", "warn", or "error" (which will apply to all warnings), or
a specific warning type and an action for that type. Multiple
options can be provided and are consolidated.
* NEWS: Announce the new option.
* doc/make.1: Document in the man page.
* doc/make.texi (Warnings): Document in the user's manual.
* Makefile.am: Add new header warning.h.
* src/warning.h: Define enum for actions and warning types, and
macros to test whether they are set. Keep the default settings
separate so that we can correctly reconstruct MAKEFLAGS.
* src/makeint.h: Remove deprecated warn_undefined_variables_flag.
* src/main.c: Create global variables to hold warning settings.
(switches): Add a new switch for --warn.
(initialize_warnings): Set the default warning actions.
(main): Call initialize_warnings().
(encode_warning_state, decode_warning_state): Convert warning states
between strings and enums.
(encode_warning_name, decode_warning_name): Convert warning names
between strings and enums.
(decode_warn_flags): Convert a --warn option into enum values. If
deprecated warn_undefined_variables_flag is set convert it to --warn.
(decode_switches): Don't remove duplicates of --warn since order
matters. Call decode_warn_flags() to handle --warn.
(define_makeflags): Special-case handling of --warn options written
to MAKEFLAGS: write out the current settings.
* src/read.c (tilde_expand): Use new warning control macros.
* src/variable.c (warn_undefined): Ditto.
* src/job.c (construct_command_argv): Ditto.
* tests/scripts/options/warn: Rename from warn-undefined-variables
and add tests for --warn.
* tests/scripts/variables/MAKEFLAGS: Expect the new behavior.
Diffstat (limited to 'src/variable.c')
-rw-r--r-- | src/variable.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/variable.c b/src/variable.c index e2a529de..f1911759 100644 --- a/src/variable.c +++ b/src/variable.c @@ -30,6 +30,7 @@ this program. If not, see <https://www.gnu.org/licenses/>. */ #include "pathstuff.h" #endif #include "hash.h" +#include "warning.h" /* Incremented every time we enter target_environment(). */ unsigned long long env_recursion = 0; @@ -1868,15 +1869,19 @@ static const struct defined_vars defined_vars[] = { void warn_undefined (const char *name, size_t len) { - if (warn_undefined_variables_flag) + if (warn_check (wt_undefined_var)) { const struct defined_vars *dp; for (dp = defined_vars; dp->name != NULL; ++dp) if (dp->len == len && memcmp (dp->name, name, len) == 0) return; - error (reading_file, len, _("warning: undefined variable '%.*s'"), - (int)len, name); + 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); } } |