非伪造的Makefile目标作为虚假目标的依赖?

时间:2016-05-04 00:23:34

标签: makefile

我如何拥有一个昂贵的目标,而不是PHONY作为PHONY规则的依赖项?

e.g:

bin/expensive:
    gcc ...

.PHONY: mundane
mundane: bin/expensive
    bin/expensive -o mundane

但每次运行make mundane时,bin/expensive目标都会重建。

如果我直接运行make bin/expensive,那么我会收到“是最新的”消息,不会浪费额外的时间。

这种行为有什么办法吗?

编辑1: 使用实际的完整makefile

export SHELL=/bin/bash -xe

bin/expensive:
        $(info making expensive)
        mkdir -p bin/
        date > bin/expensive

.PHONY: mundane
mundane: bin/expensive
        $(info making phony mundane)
        cat bin/expensive

首先运行:

$ make mundane
making expensive
mkdir -p bin/
+ mkdir -p bin/
date > bin/expensive
+ date
making phony mundane
cat bin/expensive
+ cat bin/expensive
Thu May  5 23:49:58 PDT 2016

后续运行:

$ make mundane
making phony mundane
cat bin/expensive
+ cat bin/expensive
Thu May  5 23:49:58 PDT 2016
哼......好吧,它确实有效,就像我想的那样。让我按照关于评论的建议和明天的整个Makefile过去,因为我肯定有一个bug。

0 个答案:

没有答案