Reset GNUMAKEFLAGS after parsing.
authorPaul Smith <psmith@gnu.org>
Sun, 29 Sep 2013 17:15:00 +0000 (13:15 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 29 Sep 2013 17:15:00 +0000 (13:15 -0400)
If we don't do this we'll continually add flags on recursion.  This
is mainly for users to set in their environment before invoking make.

ChangeLog
NEWS
doc/make.texi
main.c
tests/ChangeLog
tests/scripts/variables/GNUMAKEFLAGS

index c31b726a22436704455bbbfe950ecb00ad477294..fa31980c738d6d897ee702cffff2e04ca54293a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-29  Paul Smith  <psmith@gnu.org>
+
+       * main.c (main): Clear GNUMAKEFLAGS after parsing, to avoid
+       proliferation of options.
+       * NEWS: Document it.
+       * doc/make.texi (Options/Recursion): Ditto.
+
 2013-09-23  Eli Zaretskii  <eliz@gnu.org>
 
        * w32/compat/posixfcn.c: Fix the forgotten OUTPUT_SYNC conditional.
diff --git a/NEWS b/NEWS
index 1b2e49923ad66922d08d8deb26135c4be193c3d5..d190fd3350e8fde115ae2676e36a4ec9d8fc5485 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -73,7 +73,8 @@ http://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=101&set
 * New variable: $(GNUMAKEFLAGS) will be parsed for make flags, just like
   MAKEFLAGS is.  It can be set in the environment or the makefile, containing
   GNU make-specific flags to allow your makefile to be portable to other
-  versions of make.  GNU make never sets or modifies GNUMAKEFLAGS.
+  versions of make.  Once this variable is parsed, GNU make will set it to the
+  empty string so that flags will not be duplicated on recursion.
 
 * New variable: `MAKE_HOST' gives the name of the host architecture
   make was compiled for.  This is the same value you see after 'Built for'
@@ -81,8 +82,10 @@ http://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=101&set
 
 * Behavior of MAKEFLAGS and MFLAGS is more rigorously defined.  All simple
   flags are grouped together in the first word of MAKEFLAGS.  No options that
-  accept arguments appear there.  If no simple flags are present MAKEFLAGS
-  begins with a space.  MFLAGS never begins with "- ".
+  accept arguments appear in the first word.  If no simple flags are present
+  MAKEFLAGS begins with a space.  Flags with both short and long versions
+  always use the short versions in MAKEFLAGS.  Flags are listed in
+  alphabetical order using ASCII ordering.  MFLAGS never begins with "- ".
 
 * Setting the -r and -R options in MAKEFLAGS inside a makefile now works as
   expected, removing all built-in rules and variables, respectively.
index f89f8b77e669f12395c65abb6094c9e9dad31a18..42cec7febe3ce6f1363252249c4c72090b24e209 100644 (file)
@@ -4808,10 +4808,17 @@ to GNU @code{make}, and hence do not want to add GNU
 @code{make}-specific flags to the @code{MAKEFLAGS} variable, you can
 add them to the @code{GNUMAKEFLAGS} variable instead.  This variable
 is parsed just before @code{MAKEFLAGS}, in the same way as
-@code{MAKEFLAGS}.  Note, however, that when @code{make} constructs
-@code{MAKEFLAGS} to pass to a recursive @code{make} it will include
-all flags.  GNU @code{make} never sets the @code{GNUMAKEFLAGS}
-variable itself.
+@code{MAKEFLAGS}.  When @code{make} constructs @code{MAKEFLAGS} to
+pass to a recursive @code{make} it will include all flags, even those
+taken from @code{GNUMAKEFLAGS}.  As a result, after parsing
+@code{GNUMAKEFLAGS} GNU @code{make} sets this variable to the empty
+string to avoid duplicating flags during recursion.
+
+It's best to use @code{GNUMAKEFLAGS} only with flags which won't
+materially change the behavior of your makefiles.  If your makefiles
+require GNU make anyway then simply use @code{MAKEFLAGS}.  Flags such
+as @samp{--no-print-directory} or @samp{--output-sync} may be
+appropriate for @code{GNUMAKEFLAGS}.
 
 @node -w Option,  , Options/Recursion, Recursion
 @subsection The @samp{--print-directory} Option
diff --git a/main.c b/main.c
index 776ba7ce704e21133a457c298c9aaa5f6c75e00a..13ded20cac699f6478fd333f613d974fba953a3b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1396,6 +1396,10 @@ main (int argc, char **argv, char **envp)
   /* Decode the switches.  */
 
   decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
+
+  /* Clear GNUMAKEFLAGS to avoid duplication.  */
+  define_variable_cname ("GNUMAKEFLAGS", "", o_env, 0);
+
   decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
 
   /* In output sync mode we need to sync any output generated by reading the
@@ -1931,12 +1935,16 @@ main (int argc, char **argv, char **envp)
 
     /* Decode switches again, for variables set by the makefile.  */
     decode_env_switches (STRING_SIZE_TUPLE ("GNUMAKEFLAGS"));
+
+    /* Clear GNUMAKEFLAGS to avoid duplication.  */
+    define_variable_cname ("GNUMAKEFLAGS", "", o_override, 0);
+
     decode_env_switches (STRING_SIZE_TUPLE ("MAKEFLAGS"));
 #if 0
     decode_env_switches (STRING_SIZE_TUPLE ("MFLAGS"));
 #endif
 
-    /* Reset in case the switches changed our minds.  */
+    /* Reset in case the switches changed our mind.  */
     syncing = (output_sync == OUTPUT_SYNC_LINE
                || output_sync == OUTPUT_SYNC_TARGET);
 
index 9e2deb37532e2cfb868980e2071f9c48582843c1..c785d34b55bd07026bb0ba50cb99d46b26ca62f7 100644 (file)
@@ -1,3 +1,8 @@
+2013-09-29  Paul Smith  <psmith@gnu.org>
+
+       * scripts/variables/GNUMAKEFLAGS: Verify that GNUMAKEFLAGS is
+       cleared and options are not duplicated.
+
 2013-09-23  Paul Smith  <psmith@gnu.org>
 
        * scripts/options/print-directory: Rename dash-w to
index edef66e3d96a7727c11fe9caac001bb87611fba2..bd6979cfc3746dfcbf4c324569772593116e87ed 100644 (file)
@@ -23,4 +23,18 @@ all: ; @echo $(MAKEFLAGS)
 echo erR --trace --no-print-directory
 erR --trace --no-print-directory");
 
+# Verify that re-exec / recursion doesn't duplicate flags from GNUMAKEFLAGS
+
+$extraENV{GNUMAKEFLAGS} = '-I/tmp -Oline';
+
+run_make_test(q!
+recurse: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; #MAKEPATH# -f #MAKEFILE# all
+all: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS
+-include x.mk
+x.mk: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; echo > $@
+!,
+              "", "x.mk\nMAKEFLAGS = -I/tmp -Oline\nGNUMAKEFLAGS =\nrecurse\nMAKEFLAGS = -I/tmp -Oline\nGNUMAKEFLAGS =\n#MAKE#[1]: Entering directory '#PWD#'\nall\nMAKEFLAGS = w -I/tmp -Oline\nGNUMAKEFLAGS =\n#MAKE#[1]: Leaving directory '#PWD#'\n");
+
+unlink('x.mk');
+
 1;