为Makefile中的规则命名

时间:2013-08-12 12:53:43

标签: makefile

简单地说,我想在Makefile中为规则命名:

A.ext : B.ext
    compute A.ext from B.ext

所以我得到这样的东西:

.PHONY : my_rule
A.ext : my_rule
my_rule : B.ext
    compute A.ext from B.ext

但这还不等同于第一个,因为即使B.ext没有改变,my_rule总是被执行。我怎样才能实现等价?

这是make -d的修剪输出:

Considering target file `A.ext'.
  Considering target file `my_rule'.
   File `my_rule' does not exist.
    Considering target file `B.ext'.
     Finished prerequisites of target file `B.ext'.
    No need to remake target `B.ext'.
   Finished prerequisites of target file `my_rule'.
  Must remake target `my_rule'.

(我想要的原因是我有另一条规则C.ext :| my_rule。)

1 个答案:

答案 0 :(得分:1)

.PHONY : my_rule
my_rule: A.ext
A.ext : B.ext
    compute A.ext from B.ext

better

.PHONY : my_rule
my_rule: A.ext
A.ext : B.ext
    compute $@ from $<