gpt4 book ai didi

makefile - 不执行虚假目标的配方

转载 作者:行者123 更新时间:2023-12-01 10:51:18 26 4
gpt4 key购买 nike

考虑从 GNU make 手册中摘录的 PHONY 目标:

Once this is done, make clean' will run the commands regardless of whether there is a file namedclean'.

为什么我没有看到我的食谱被执行,尽管在调试输出中 make 说它必须重新制作这些目标?下面是一个示例 makefile 来演示该问题:

all:
@echo Rule to build 'all'

.PHONY: clean a.clean b.clean
clean: a.clean b.clean
@echo Cleaning toplevel

%.clean:
@echo Cleaning $*

这是输出 - 注意没有提到 Cleaning $*

make: Entering directory `/tmp'
Cleaning toplevel
make: Leaving directory `/tmp'

这是 -d 的输出:

Considering target file `clean'.
File `clean' does not exist.
Considering target file `a.clean'.
File `a.clean' does not exist.
Finished prerequisites of target file `a.clean'.
Must remake target `a.clean'.
Successfully remade target file `a.clean'.
Considering target file `b.clean'.
File `b.clean' does not exist.
Finished prerequisites of target file `b.clean'.
Must remake target `b.clean'.
Successfully remade target file `b.clean'.
Finished prerequisites of target file `clean'.
Must remake target `clean'.

最佳答案

来自 the same section of the manual :

因为它知道假目标不会命名可以从其他文件重新制作的实际文件,make 会跳过隐式规则搜索假目标(请参阅隐式规则)。

是的,Make 知道它必须“重新制作”a.cleanb.clean,但是在寻找这样做的规则时,它不会考虑您的模式规则。它找不到这些目标的配方,所以它耸了耸肩,认为工作完成并继续前进。

您可以通过将模式规则设为静态 模式规则来解决此问题:

a.clean b.clean : %.clean :
@echo Cleaning $*

关于makefile - 不执行虚假目标的配方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659273/

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