diff --git a/src/main.c b/src/main.c index 3dcdfd00..3dcbe441 100644 --- a/src/main.c +++ b/src/main.c @@ -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)); diff --git a/tests/scripts/variables/GNUMAKEFLAGS b/tests/scripts/variables/GNUMAKEFLAGS index 30bccf68..6dc9fd8c 100644 --- a/tests/scripts/variables/GNUMAKEFLAGS +++ b/tests/scripts/variables/GNUMAKEFLAGS @@ -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;