为什么make不删除中间文件?

发布于 2024-12-27 13:40:36 字数 1986 浏览 0 评论 0原文

我遇到 GNU make 3.81 不删除中间文件的问题。该问题类似于 GNU make 不删除中间文件,但该答案并不不能解决我的问题。我已经将问题提炼到这个测试用例中:

default: 
    @echo no $@ target; exit 1

oncetwice: once twice
    @echo $@: $^

## Uncommenting the following line is sufficient to cause GNU make 3.81 to
## not delete the intermediate 'twice.dep', even if it didn't exist
## previously (i.e., was created by this invocation).
#another: twice.dep

%: %.dep
    @echo $^ >$@

## the following .INTERMEDIATE has no effect re: the twice: twice.dep
## dependency
.INTERMEDIATE: %.dep
%.dep:
    @echo $@ >$@

NB 命令块必须是制表符缩进。

也就是说,目标 once 依赖于 once.dep,而 twice 依赖于 twice.dep。另外,another也依赖于twice.dep。正是这一行导致 twice.dep 永远不会被删除,即使 make 创建了它并且尽管有 .INTERMEDIATE 行。

发布的 Makefile 给出了:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep twice.dep

取消注释 twice: twins.dep 行:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep

请注意,twice.dep 在第二次调用中没有 rm'd。

从信息页面:

.INTERMEDIATE
The targets which .INTERMEDIATE depends on are treated as intermediate files.

[...]

Intermediate files are remade using their rules just like all other
files. But intermediate files are treated differently in two ways.

The first difference [...]

**The second difference is that if make does create b in order to update
something else, it deletes b later on after it is no longer
needed. Therefore, an intermediate file which did not exist before make
also does not exist after make.**

我尝试使用命令块使 another:twice.dep 成为真正的规则。我还尝试过将 .INTERMEDIATE 指定为模式、文字文件名或两者的变体。我也尝试过使用.PHONY。 make-3.82 NEWS 似乎没有任何相关修复。我所目睹的行为看起来更像是 .SECONDARY 目标所描述的行为。

谢谢,

里斯

I'm having problems with GNU make 3.81 not deleting intermediate files. The issue is similar to GNU make Not Deleting Intermediate Files, but that answer doesn't solve my problem. I've distilled the issue to this test case:

default: 
    @echo no $@ target; exit 1

oncetwice: once twice
    @echo $@: $^

## Uncommenting the following line is sufficient to cause GNU make 3.81 to
## not delete the intermediate 'twice.dep', even if it didn't exist
## previously (i.e., was created by this invocation).
#another: twice.dep

%: %.dep
    @echo $^ >$@

## the following .INTERMEDIATE has no effect re: the twice: twice.dep
## dependency
.INTERMEDIATE: %.dep
%.dep:
    @echo $@ >$@

N.B. command blocks must be tab-indented.

That is, the target once depends on once.dep and twice depends on twice.dep. In addition, another also depends on twice.dep. It is this line that causes twice.dep to never be removed, even if make created it and despite the .INTERMEDIATE line.

The Makefile as posted gives:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep twice.dep

Uncommenting the twice: twice.dep line:

snafu$ rm -f once* twice*; make oncetwice
oncetwice: once twice
rm once.dep

Notice that twice.dep is not rm'd in the second invocation.

From the info pages:

.INTERMEDIATE
The targets which .INTERMEDIATE depends on are treated as intermediate files.

[...]

Intermediate files are remade using their rules just like all other
files. But intermediate files are treated differently in two ways.

The first difference [...]

**The second difference is that if make does create b in order to update
something else, it deletes b later on after it is no longer
needed. Therefore, an intermediate file which did not exist before make
also does not exist after make.**

I've tried making another: twice.dep a real rule with a command block. I've also tried variations of specifying .INTERMEDIATE as a pattern, a literal filename, and both. I've also tried using .PHONY. make-3.82 NEWS doesn't appear to have any relevant fixes. The behavior I'm witnessing looks more like that described for .SECONDARY targets.

Thanks,

Reece

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2025-01-03 13:40:36

您不能使用模式作为 .INTERMEDIATE 特殊目标的先决条件(如果可以,它将记录在手册中;如果手册没有说可以,那么您就不能)。

此外,GNU make 3.81 有一个错误,其中 .INTERMEDIATE 无法正常工作;该错误已在 3.82 中修复。如果您将文件更改为使用:(

.INTERMEDIATE: twice.dep

编辑:原始回复说“two.dep”)

而不是“%.dep”并且切换到GNU make 3.82,您的示例将按您的预期工作。

You cannot use a pattern as a prerequisite of the .INTERMEDIATE special target (if you could, it would be documented in the manual; if the manual doesn't say you can, then you can't).

Further, GNU make 3.81 had a bug in it where .INTERMEDIATE wasn't working properly; this bug is fixed in 3.82. If you change your file to use:

.INTERMEDIATE: twice.dep

(edit: original reply said "two.dep")

rather than "%.dep" and you switch to GNU make 3.82, your example will work as you expect.

音盲 2025-01-03 13:40:36

问题是该规则

.INTERMEDIATE: %.dep

不被解释为模式规则(因为它的左侧缺少 %),
并且 %.dep 不是文件。

例如,尝试这个 Makefile:

foo: %.bar
    cat $+ > $@ 

现在创建 a.barb.bar 并运行 make foo

The problem is that the rule

.INTERMEDIATE: %.dep

is not interpreted as a pattern rule (because it lacks a % on the left hand side),
and %.dep is not a file.

For example, try this Makefile:

foo: %.bar
    cat $+ > $@ 

Now create a.bar and b.bar and run make foo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文