gpt4 book ai didi

makefile - GNU 制作 : How to export the SHELL variable to sub-makes?

转载 作者:行者123 更新时间:2023-12-04 06:50:16 24 4
gpt4 key购买 nike

来自 GNU Make 手册:

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.



我一定是做错了什么,或者没有正确阅读手册,因为这个简单的例子不起作用:
# ./Makefile
export SHELL := /bin/bash
export VALUE := exported_variable
$(info root makefile SHELL=$(SHELL))
call_sub_make:
$(MAKE) --directory=subdir

和子目录/Makefile:
$(info subdir makefile SHELL=$(SHELL))
$(info subdir makefile VALUE=$(VALUE))
do_nothing:

输出:
$ 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?

最佳答案

SHELL 导出(到 sub-make 的环境)没问题,但是 the manual还说

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



如果你想影响 SHELL 的 sub-make 的想法,你必须这样做:
call_sub_make:
$(MAKE) --directory=subdir SHELL=$(SHELL)

关于makefile - GNU 制作 : How to export the SHELL variable to sub-makes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3226815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com