diff options
author | Paul Smith <psmith@gnu.org> | 2023-03-18 17:24:45 -0400 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2023-04-02 10:02:18 -0400 |
commit | a0d1e76d604df5bd006fd5ed6a69963d3c6b4d7a (patch) | |
tree | 02d739d8168207be28535f359b0a6583f231f047 /src/warning.h | |
parent | 03ecd94488b85adc38746ec3e7c2a297a522598e (diff) | |
download | make-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/warning.h')
-rw-r--r-- | src/warning.h | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/src/warning.h b/src/warning.h index 78e99893..658af93a 100644 --- a/src/warning.h +++ b/src/warning.h @@ -23,8 +23,8 @@ enum warning_type wt_max }; -/* State of a given warning. */ -enum warning_state +/* Action taken for a given warning. */ +enum warning_action { w_unset = 0, w_ignore, @@ -32,25 +32,24 @@ enum warning_state 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]; +struct warning_data + { + enum warning_action global; /* Global setting. */ + enum warning_action actions[wt_max]; /* Action for each warning type. */ + }; -/* Global warning settings. */ -extern enum warning_state warn_global; +/* Actions taken for each warning. */ +extern enum warning_action warnings[wt_max]; -/* 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]) +/* Get the current action for a given warning. */ +#define warn_get(_w) (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) +/* Set the current actin for a given warning. Can't use w_unset here. + This should only be used for temporary resetting of warnings. */ +#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) +#define warn_check(_w) (warn_get (_w) > w_ignore) /* Check if the warning is ignored. */ #define warn_ignored(_w) (warn_get (_w) == w_ignore) @@ -60,3 +59,22 @@ extern enum warning_state warn_global; /* Check if the warning is in "error" mode. */ #define warn_error(_w) (warn_get (_w) == w_error) + +void warn_init (void); +void decode_warn_actions (const char *value, const floc *flocp); +char *encode_warn_flag (char *fp); + +void warn_get_vardata (struct warning_data *data); +void warn_set_vardata (const struct warning_data *data); + +#define warning(_t,_f,_m) \ + do{ \ + if (warn_check (_t)) \ + { \ + char *_a = xstrdup (_m); \ + if (warn_error (_t)) \ + fatal (_f, strlen (_a), "%s", _a); \ + error (_f, strlen (_a), _("warning: %s"), _a); \ + free (_a); \ + } \ + }while(0) |