From 539f513773b2e651d987a7bdbdffd8b5164d58cf Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 28 Nov 2004 23:11:23 +0000 Subject: Fix for bug #1276: Handle SHELL according to POSIX requirements. POSIX requires that the value of SHELL in the makefile NOT be exported to sub-commands. Instead, the value in the environment when make was invoked should be passed to the environment of sub-commands. Note that make still uses SHELL to _run_ sub-commands; it just doesn't change the value of the SHELL variable in the environment of sub-commands. As an extension to POSIX, if the makefile explicitly exports SHELL then GNU make _will_ use it in the environment of sub-commands. --- main.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index ca6318b..f0229ee 100644 --- a/main.c +++ b/main.c @@ -264,6 +264,10 @@ int always_make_flag = 0; int rebuilding_makefiles = 0; +/* Remember the original value of the SHELL variable, from the environment. */ + +const char *env_shell = 0; + /* The usage output. We write it this way to make life easier for the translators, especially those trying to translate to right-to-left @@ -1045,11 +1049,8 @@ main (int argc, char **argv, char **envp) #ifndef _AMIGA for (i = 0; envp[i] != 0; ++i) { - int do_not_define; - register char *ep = envp[i]; - - /* by default, everything gets defined and exported */ - do_not_define = 0; + int do_not_define = 0; + char *ep = envp[i]; while (*ep != '=') ++ep; @@ -1065,17 +1066,27 @@ main (int argc, char **argv, char **envp) machines where ptrdiff_t is a different size that doesn't widen the same. */ if (!do_not_define) - define_variable (envp[i], (unsigned int) (ep - envp[i]), - ep + 1, o_env, 1) - /* Force exportation of every variable culled from the environment. - We used to rely on target_environment's v_default code to do this. - But that does not work for the case where an environment variable - is redefined in a makefile with `override'; it should then still - be exported, because it was originally in the environment. - Another wrinkle is that POSIX says the value of SHELL set in the - makefile should not change the value of SHELL given to - subprocesses, which seems silly to me but... */ - ->export = strncmp(envp[i], "SHELL=", 6) ? v_noexport : v_export; + { + struct variable *v; + + v = define_variable (envp[i], (unsigned int) (ep - envp[i]), + ep + 1, o_env, 1); + /* Force exportation of every variable culled from the environment. + We used to rely on target_environment's v_default code to do this. + But that does not work for the case where an environment variable + is redefined in a makefile with `override'; it should then still + be exported, because it was originally in the environment. */ + v->export = v_export; + + /* Another wrinkle is that POSIX says the value of SHELL set in the + makefile should not change the value of SHELL given to + subprocesses, which seems silly to me but... */ + if (strncmp (envp[i], "SHELL=", 6) == 0) + { + v->export = v_noexport; + env_shell = xstrdup (ep + 1); + } + } } #ifdef WINDOWS32 /* -- cgit v1.2.3