From 03ecd94488b85adc38746ec3e7c2a297a522598e Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 26 Feb 2023 18:24:30 -0500 Subject: Add new warnings invalid-var and invalid-ref The "invalid-var" warning triggers if the makefile attempts to assign a value to an invalid variable name (a name containing whitespace). The "invalid-ref" warning triggers if the makefile attempts to reference an invalid variable name. Both new warnings have a default action of "warn". * NEWS: Add these new warnings. * doc/make.1: Document them in the man page. * doc/make.texi (Warnings): Document them in the user's manual. * src/warning.h: Add enum values for the new warning types. * src/main.c (initialize_warnings): Initialize the new warnings. * src/variable.h (undefine_variable_in_set, undefine_variable_global): Ask callers to provide a struct floc specifying where the variable is undefined. * src/read.c (do_undefine): Pass floc when undefining. * src/variable.c (check_valid_name): If invalid-var is enabled, check the variable name. (define_variable_in_set): Call it. (undefine_variable_in_set): Ditto. (check_variable_reference): If invalid-ref is enabled, check the variable reference. (lookup_variable): Call it. (lookup_variable_in_set): Ditto. * tests/scripts/options/warn: Add tests for the new warning types. --- doc/make.1 | 10 ++++++++++ doc/make.texi | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/make.1 b/doc/make.1 index 933a8273..8a407b03 100644 --- a/doc/make.1 +++ b/doc/make.1 @@ -374,6 +374,10 @@ can be an action; one of or .I error to set the default action for all warnings, or it can be a specific warning: +.I invalid-var +(assigning to an invalid variable name), +.I invalid-ref +(referencing an invalid variable name), or .I undefined-var (referencing an undefined variable). The behavior of each warning can be set by adding @@ -387,6 +391,12 @@ is provided the action for all warnings is If no .B \-\-warn option is provided the default action for +.I invalid-var +and +.I invalid-ref +is +.I warn +and the default action for .I undefined-var is .IR ignore . diff --git a/doc/make.texi b/doc/make.texi index 31db623b..b3cc57a0 100644 --- a/doc/make.texi +++ b/doc/make.texi @@ -9313,6 +9313,12 @@ GNU Make can detect some types of incorrect usage in makefiles and show warnings about them. Currently these issues can be detected: @table @samp +@item invalid-var +Assigning to an invalid variable name (e.g., a name containing whitespace). + +@item invalid-ref +Using an invalid variable name in a variable reference. + @item undefined-var Referencing a variable that has not been defined. @end table @@ -9331,8 +9337,9 @@ Show a warning about the usage and continue processing the makefile. Show an error for the usage and immediately stop processing the makefile. @end table -The default action when no warning control options are provided for -@samp{undefined-var} is @samp{warn}. +The default action of GNU Make when no warning control options are provided +is @samp{ignore} for @samp{undefined-var}, and @samp{warn} for +@samp{invalid-var} and @samp{invalid-ref}. To modify this default behavior, you can use the @code{--warn} option. This option can be specified on the command line, or by adding it to the -- cgit v1.2.1