开发者

GNU Make: How to export the SHELL variable to sub-makes?

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开发者_如何学JAVA 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?


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜