【问题标题】:Make not executing recipes for phony targets不为虚假目标执行配方
【发布时间】:2013-11-08 16:05:00
【问题描述】:

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

完成后,make clean' will run the commands regardless of whether there is a file namedclean'。

为什么我没有看到我的配方被执行,尽管在调试输出中 make 说它必须重新制作这些目标?这是一个演示该问题的示例生成文件:

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'.

【问题讨论】:

    标签: makefile


    【解决方案1】:

    来自the same section of the manual

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      相关资源
      最近更新 更多