]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Don't add GNUMAKEFLAGS to the environment
authorPaul Smith <psmith@gnu.org>
Sun, 19 Jun 2022 18:33:57 +0000 (14:33 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 19 Jun 2022 18:35:27 +0000 (14:35 -0400)
If GNUMAKEFLAGS was not present in the environment when we started,
don't add it.

* src/main.c (main): Don't mess with GNUMAKEFLAGS unless it exists.
* tests/scripts/variables/GNUMAKEFLAGS: Test this behavior.

src/main.c
tests/scripts/variables/GNUMAKEFLAGS

index 3dcdfd0015546925f991f178d74e1d6542642d20..3dcbe441621604b8d105cac8bcddd66a4ce3e7f9 100644 (file)
@@ -1413,7 +1413,7 @@ main (int argc, char **argv, char **envp)
 
         /* If this is MAKE_RESTARTS, check to see if the "already printed
            the enter statement" flag is set.  */
-        if (len == 13 && memcmp (envp[i], "MAKE_RESTARTS", 13) == 0)
+        if (len == 13 && memcmp (envp[i], STRING_SIZE_TUPLE ("MAKE_RESTARTS")) == 0)
           {
             if (*ep == '-')
               {
@@ -1480,10 +1480,13 @@ main (int argc, char **argv, char **envp)
 #endif
 
   /* Decode the switches.  */
-  decode_env_switches (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME));
+  if (lookup_variable (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME)))
+    {
+      decode_env_switches (STRING_SIZE_TUPLE (GNUMAKEFLAGS_NAME));
 
-  /* Clear GNUMAKEFLAGS to avoid duplication.  */
-  define_variable_cname (GNUMAKEFLAGS_NAME, "", o_env, 0);
+      /* Clear GNUMAKEFLAGS to avoid duplication.  */
+      define_variable_cname (GNUMAKEFLAGS_NAME, "", o_env, 0);
+    }
 
   decode_env_switches (STRING_SIZE_TUPLE (MAKEFLAGS_NAME));
 
index 30bccf68a17fa5167ca753c3f7e3a242b0df3c84..6dc9fd8c8e8d50f970208d5744313dd3907a93f4 100644 (file)
@@ -39,4 +39,16 @@ x.mk: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLA
 
 unlink('x.mk');
 
+# Ensure that we don't add GNUMAKEFLAGS to the environment if it's not there
+run_make_test(q!
+all: ; @env | grep GNUMAKEFLAGS; true
+!,
+              '', '');
+
+$ENV{GNUMAKEFLAGS} = '-Itst/bad';
+run_make_test(q!
+all: ; @env | grep GNUMAKEFLAGS; true
+!,
+              '', 'GNUMAKEFLAGS=');
+
 1;