考虑到摘自PHONY目标的GNU make手册:
完成此操作后,
make clean' will run the commands regardless of whether there is a file named
清除'。
为什么我没有看到我的食谱被执行,事件虽然在调试输出中说它必须重新制作这些目标?下面是一个示例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'.
答案 0 :(得分:6)
来自the same section of the manual:
由于它知道虚假目标没有命名可以从其他文件重新创建的实际文件,因此跳过对虚假目标的隐式规则搜索(参见隐式规则)。
所以是的,Make知道它必须“重新制作”a.clean
和b.clean
,但在查找规则时,它不会考虑您的模式规则。它找不到这些目标的配方,所以它耸耸肩,考虑完成的工作并继续前进。
您可以通过使模式规则成为静态模式规则来解决此问题:
a.clean b.clean : %.clean :
@echo Cleaning $*