views:

53

answers:

1

From the GNU Make manual:

The value of the make variable SHELL is not exported. Instead, the value of the SHELL variable from the invoking environment is passed to the sub-make. You can force make to export its value for SHELL by using the export directive, described below.

I must be doing something wrong, or not reading the manual properly, as this simple example doesn't work:

# ./Makefile
export SHELL := /bin/bash
export VALUE := exported_variable
$(info root makefile SHELL=$(SHELL))
call_sub_make:
    $(MAKE) --directory=subdir

And subdir/Makefile:

$(info subdir makefile SHELL=$(SHELL))
$(info subdir makefile VALUE=$(VALUE))
do_nothing:

Output:

$ env | grep SHELL
SHELL=/bin/bash
$ make --version
GNU Make 3.81
$ make
root makefile SHELL=/bin/bash
make --directory=subdir
subdir makefile SHELL=/bin/sh
subdir makefile VALUE=exported_variable
make[1]: Entering directory `/home/drtwox/C/make/export_shell/subdir'
make[1]: Nothing to be done for `do_nothing'.
make[1]: Leaving directory `/home/drtwox/C/make/export_shell/subdir'

VALUE is exported, why isn't SHELL?

+1  A: 

SHELL is exported (to the sub-make's environment) alright, but the manual also says

Unlike most variables, the variable SHELL is never set from the environment.

If you want to influence the sub-make's idea of SHELL, you'll have to do it like this:

call_sub_make:
    $(MAKE) --directory=subdir SHELL=$(SHELL)
slowdog