GNU Make:如何将 SHELL 变量导出到子 make?
来自 GNU Make 手册:
make 变量 SHELL 的值 未导出。相反,值 来自调用的 SHELL 变量 环境被传递给子make。 您可以强制 make 导出其值 对于 SHELL,使用导出 指令,如下所述。
我一定做错了什么,或者没有正确阅读手册,因为这个简单的例子不起作用:
# ./Makefile
export SHELL := /bin/bash
export VALUE := exported_variable
$(info root makefile SHELL=$(SHELL))
call_sub_make:
$(MAKE) --directory=subdir
并且 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 被导出,为什么不是 SHELL?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SHELL 已导出(到子 make 的环境),但是
如果你想影响子品牌的 SHELL 想法,你必须这样做:
SHELL is exported (to the sub-make's environment) alright, but the manual also says
If you want to influence the sub-make's idea of SHELL, you'll have to do it like this: