gpt4 book ai didi

makefile - .EXPORT_ALL_VARIABLES 仅在设为 'phony' 时才有效

转载 作者:行者123 更新时间:2023-12-02 22:16:05 26 4
gpt4 key购买 nike

docs提供:

'.EXPORT_ALL_VARIABLES'

Simply by being mentioned as a target, this tells 'make' to export all variables to child processes by default. *Note Communicating Variables to a Sub-'make': Variables/Recursion.

但是,以下 makefile 表明,只有将 .EXPORT_ALL_VARIABLES 设为虚假目标,然后只有,它才会具有所需的结果对 makefile 的影响,即导出所有变量。

Makefile(版本 1)是:

ifeq "$(MAKELEVEL)" "0"

foo=bar

.DEFAULT:;

all: .EXPORT_ALL_VARIABLES
@$(MAKE)

else

all:
@echo 'foo is: $(foo)'

endif

运行,我们得到:

make[1]: Entering directory '/home/myname'
foo is:
make[1]: Leaving directory '/home/myname'

Makefile(版本 2)是:

ifeq "$(MAKELEVEL)" "0"

foo=bar

.DEFAULT:;

all: .EXPORT_ALL_VARIABLES
@$(MAKE)

# This line is added in THIS version.
.PHONY: .EXPORT_ALL_VARIABLES

else

all:
@echo 'foo is: $(foo)'

endif

运行,我们得到:

make[1]: Entering directory '/home/myname'
foo is: bar
make[1]: Leaving directory '/home/myname'

现在,这两个版本的 makefile 之间的唯一区别是,在第二个版本中,.EXPORT_ALL_VARIABLES 是伪造的。

为什么需要“虚伪”才能工作?

最佳答案

Simply by being mentioned as a target,

为什么需要“虚伪”才能工作?

事实并非如此。您没有声明.EXPORT_ALL_VARIABLES作为目标,您将其声明为先决条件:

all: .EXPORT_ALL_VARIABLES

这是先决条件,而不是目标。如果您将其声明为目标:

.EXPORT_ALL_VARIABLES:

然后它就会起作用,你不必声明它是假的。

更准确的问题是,为什么声明 .EXPORT_ALL_VARIABLES即使没有将其声明为目标,也将其视为虚假作品?发生这种情况是因为被标记为虚假的事物被假定为目标,即使它们没有明确提及。这可能是也可能不是错误,具体取决于您如何解释 .PHONY 的意图.

您最近的问题似乎遵循一种模式:阅读文档,然后编写一个 makefile,该文件执行与文档所述类似但不相同的操作,观察它不能按描述的方式工作,然后询问为什么不这样做。

关于makefile - .EXPORT_ALL_VARIABLES 仅在设为 'phony' 时才有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31900167/

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