首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >GNU v3.82重新构建目标,而v3.81不构建目标

GNU v3.82重新构建目标,而v3.81不构建目标
EN

Stack Overflow用户
提问于 2013-10-15 14:35:04
回答 1查看 154关注 0票数 0

我有以下makefile代码:

代码语言:javascript
复制
NAME := test

target1: $(addsuffix .bar,$(NAME))
target2: $(addsuffix .dar,$(NAME))

%.bar: $(INPUT)
    touch $@

%.dar: %.bar
    touch $@

我使用GNU Make v3.81执行这个makefile,如下所示:

代码语言:javascript
复制
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时:

代码语言:javascript
复制
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,则不会发生这种情况:

代码语言:javascript
复制
NAME := test

target2: $(addsuffix .dar,$(NAME))

%.bar: $(INPUT)
    touch $@

%.dar: %.bar
    touch $@

当我没有在任何地方指定target1时,它为什么要构建它呢?

谢谢,

马丁

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-15 14:42:13

test.bar不是一个中间文件,因为它被明确地提到为target1的先决条件。它不必只在决定构建的一组目标和先决条件中明确提到,只需要在makefile的某个地方显式地提到它。

毕竟,下一次您将要求构建target1,然后make将不得不重新构建test.bar,而如果它没有被删除的话,它就不需要重建了。

ETA:我认为GNU 3.81中的行为是一个错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19383935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档