为什么不删除中间文件? [英] Why is make not deleting intermediate files?

查看:86
本文介绍了为什么不删除中间文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了GNU make 3.81无法删除中间文件的问题.该问题类似于 GNU不删除中间文件,但该答案并没有解决不了我的问题.我已将此问题简化为该测试用例:

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.

也就是说,目标once取决于once.dep,而twice取决于twice.dep.另外,another也依赖于twice.dep.这是导致twice.dep永远不会被删除的行,即使make创建了它,尽管存在.INTERMEDIATE行.

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.

发布的Makefile给出:

The Makefile as posted gives:

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

取消注释twice: twice.dep行:

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

请注意,两次.dep在第二次调用中均未删除.

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

从信息页面:

.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'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.

谢谢

Reece

推荐答案

您不能将模式用作.INTERMEDIATE特殊目标的前提条件(如果可以,它将在手册中进行记录;如果没有,说可以,那你就不能).

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).

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

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

(原始回复说"two.dep")

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

而不是%.dep",而是切换到GNU make 3.82,您的示例将按预期运行.

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

这篇关于为什么不删除中间文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆