summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--NEWS9
-rw-r--r--doc/make.texi15
-rw-r--r--main.c10
-rw-r--r--tests/ChangeLog5
-rw-r--r--tests/scripts/variables/GNUMAKEFLAGS14
6 files changed, 52 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index c31b726..fa31980 100644
--- 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 1b2e499..d190fd3 100644
--- 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.
diff --git a/doc/make.texi b/doc/make.texi
index f89f8b7..42cec7f 100644
--- a/doc/make.texi
+++ b/doc/make.texi
@@ -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 776ba7c..13ded20 100644
--- 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);
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 9e2deb3..c785d34 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -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
diff --git a/tests/scripts/variables/GNUMAKEFLAGS b/tests/scripts/variables/GNUMAKEFLAGS
index edef66e..bd6979c 100644
--- a/tests/scripts/variables/GNUMAKEFLAGS
+++ b/tests/scripts/variables/GNUMAKEFLAGS
@@ -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;