]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 61218] Ensure MAKEFLAGS is expanded even with -e
authorPaul Smith <psmith@gnu.org>
Sun, 8 Jan 2023 21:40:55 +0000 (16:40 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 8 Jan 2023 21:40:55 +0000 (16:40 -0500)
If -e was given we weren't expanding MAKEFLAGS before passing it
through the environment to jobs: we don't expand variables we
receive from the environment and when -e is given we set the
origin of MAKEFLAGS to "environment override".  Check for MAKEFLAGS
specifically, which seems like a hack but I don't have a better
idea offhand.

* src/main.c (main): Drive-by: use o_default for MAKEOVERRIDES.
* src/variable.c (target_environment): Always expand MAKEFLAGS
regardless of the origin type.
* tests/scripts/options/dash-e: Create a test.

src/main.c
src/variable.c
tests/scripts/options/dash-e

index 433f5826f184e1f3bbc8a31c29ed434b0ce0deb7..cf2324d1bd92038f2d48b095977eeec4830d2588 100644 (file)
@@ -1920,7 +1920,7 @@ main (int argc, char **argv, char **envp)
          allow the user's setting of MAKEOVERRIDES to affect MAKEFLAGS, so
          a reference to this hidden variable is written instead. */
       define_variable_cname ("MAKEOVERRIDES", "${-*-command-variables-*-}",
-                             o_env, 1);
+                             o_default, 1);
 #ifdef VMS
       vms_export_dcl_symbol ("MAKEOVERRIDES", "${-*-command-variables-*-}");
 #endif
index 009ee5402c1acb52697e21e71ca193980365c0f1..7b625aee5d986f38f481ffbfed4ce8a3457b77ba 100644 (file)
@@ -1114,8 +1114,9 @@ target_environment (struct file *file, int recursive)
 
         /* If V is recursively expanded and didn't come from the environment,
            expand its value.  If it came from the environment, it should
-           go back into the environment unchanged.  */
-        if (v->recursive && v->origin != o_env && v->origin != o_env_override)
+           go back into the environment unchanged... except MAKEFLAGS.  */
+        if (v->recursive && ((v->origin != o_env && v->origin != o_env_override)
+                             || streq (v->name, MAKEFLAGS_NAME)))
           value = cp = recursively_expand_for_file (v, file);
 
         /* If this is the SHELL variable remember we already added it.  */
index 944c39dfd525eaf27e7e80eb65b39312b7197266..e4659fb2b2a6955456e0ff2cad739aaec4b08deb 100644 (file)
@@ -1,8 +1,6 @@
 #                                                                    -*-perl-*-
 
-$description = "The following test creates a makefile to ...";
-
-$details = "";
+$description = "Test the -e (environment overrides) option";
 
 $ENV{GOOGLE} = 'boggle';
 
@@ -12,4 +10,15 @@ all:; @echo "$(GOOGLE)"
 !,
               '-e', "boggle\n");
 
+# Ensure variables set on the command line have the origin correct
+# See SV 61218
+
+run_make_test(q!
+$(info FOO [$(origin FOO)]: $(value FOO))
+all: ;
+recurse: ; @$(MAKE) -f #MAKEFILE#
+!,
+              '-e --no-print-directory FOO=1 recurse',
+              "FOO [command line]: 1\nFOO [command line]: 1\n#MAKE#[1]: 'all' is up to date.");
+
 1;