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/warning.h | |
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/warning.h')
-rw-r--r-- | src/warning.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/warning.h b/src/warning.h new file mode 100644 index 00000000..778ee407 --- /dev/null +++ b/src/warning.h @@ -0,0 +1,60 @@ +/* Control warning output in GNU Make. +Copyright (C) 2023 Free Software Foundation, Inc. +This file is part of GNU Make. + +GNU Make is free software; you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see <https://www.gnu.org/licenses/>. */ + +/* Types of warnings we can show. */ +enum warning_type + { + wt_undefined_var = 0, /* Reference an undefined variable name. */ + wt_max + }; + +/* State of a given warning. */ +enum warning_state + { + w_unset = 0, + w_ignore, + w_warn, + w_error + }; + +/* The default state of warnings. */ +extern enum warning_state default_warnings[wt_max]; + +/* Current state of warnings. */ +extern enum warning_state warnings[wt_max]; + +/* Global warning settings. */ +extern enum warning_state warn_global; + +/* Get the current state of a given warning. */ +#define warn_get(_w) (warnings[_w] != w_unset ? warnings[_w] \ + : warn_global != w_unset ? warn_global \ + : default_warnings[_w]) + +/* Set the current state of a given warning. Can't use w_unset here. */ +#define warn_set(_w,_f) do{ warnings[_w] = (_f); } while (0) + +/* True if we should check for the warning in the first place. */ +#define warn_check(_w) (warn_get (_w) > w_ignore) + +/* Check if the warning is ignored. */ +#define warn_ignored(_w) (warn_get (_w) == w_ignore) + +/* Check if the warning is in "warn" mode. */ +#define warn_warned(_w) (warn_get (_w) == w_warn) + +/* Check if the warning is in "error" mode. */ +#define warn_error(_w) (warn_get (_w) == w_error) |