我有以下生成文件代码:
NAME := test
target1: $(addsuffix .bar,$(NAME))
target2: $(addsuffix .dar,$(NAME))
%.bar: $(INPUT)
touch $@
%.dar: %.bar
touch $@
我使用 GNU Make v3.81 执行这个 makefile,如下所示:
user@node1:/data/user/Tests/oldfile3$ rm test.*
removed `test.bar'
removed `test.txt'
user@node1:/data/user/Tests/oldfile3$ touch test.txt
user@node1:/data/user/Tests/oldfile3$ make target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$ make target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$ rm test.bar
removed `test.bar'
user@node1:/data/user/Tests/oldfile3$ make target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$
正如我所料,中间文件 test.bar 在删除后不会重建,因为 test.dar 仍然是最新的。但是当我使用 GNU Make v3.82 时:
user@node1:/data/user/Tests/oldfile3$ rm test.*
removed `test.dar'
removed `test.txt'
user@node1:/data/user/Tests/oldfile3$ touch test.txt
user@node1:/data/user/Tests/oldfile3$ mk82 target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$ mk82 target2
make: Nothing to be done for `target2'.
user@node1:/data/user/Tests/oldfile3$ rm test.bar
removed `test.bar'
user@node1:/data/user/Tests/oldfile3$ mk82 target2
touch test.bar
touch test.dar
user@node1:/data/user/Tests/oldfile3$
现在,当我删除 test.bar 并调用 make 时,它将重建 test.bar,然后重建 test.dar。test.txt 仍然比 test.dar 旧,那么为什么要重新制作依赖于 test.txt 的 test.bar 呢?如果我像这样删除 target1,则不会发生这种情况:
NAME := test
target2: $(addsuffix .dar,$(NAME))
%.bar: $(INPUT)
touch $@
%.dar: %.bar
touch $@
当我没有在任何地方指定它时,为什么它会构建 target1?
谢谢,
马丁