当创建最重要的目标时,告诉'make'忽略依赖关系 [英] telling 'make' to ignore dependencies when the top target has been created

查看:93
本文介绍了当创建最重要的目标时,告诉'make'忽略依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下类型的管道:

I'm running the following kind of pipeline:

digestA: hugefileB hugefileC
    cat $^ > $@
    rm $^

hugefileB:
    touch $@

hugefileC:
    touch $@

目标 hugefileB hugefileC 很大,需要很长时间才能计算出来(并且需要Make的功能).但是一旦创建了 digestA ,就无需保留其依赖项:它将删除那些依赖项以释放磁盘空间.

The targets hugefileB and hugefileC are very big and take a long time to compute (and need the power of Make). But once digestA has been created, there is no need to keep its dependencies: it deletes those dependencies to free up disk space.

现在,如果我再次调用'make',则将重建 hugefileB hugefileC ,而 digestA 已经可以.

Now, if I invoke 'make' again, hugefileB and hugefileC will be rebuilt, whereas digestA is already ok.

有什么办法告诉'make'避免重新编译依赖项?

Is there any way to tell 'make' to avoid to re-comile the dependencies ?

注意:我不想在'digestA'规则中建立两个依赖关系.

NOTE: I don't want to build the two dependencies inside the rules for 'digestA'.

推荐答案

使用中级文件" 的功能:

与所有其他文件一样,使用其规则重新制作中间文件.但是中间文件在两种方式上有所不同.

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

第一个区别是如果中间文件不存在会发生什么.如果普通文件b不存在,并且make考虑依赖于b的目标,则它总是创建b,然后从b更新目标. 但是,如果b是中间文件,则make可以单独放置.除非b的某些先决条件比该目标新,或者有其他原因更新该目标,否则它不会费心更新b或最终目标.

The first difference is what happens if the intermediate file does not exist. If an ordinary file b does not exist, and make considers a target that depends on b, it invariably creates b and then updates the target from b. But if b is an intermediate file, then make can leave well enough alone. It won't bother updating b, or the ultimate target, unless some prerequisite of b is newer than that target or there is some other reason to update that target.

第二个区别是,如果make确实创建b是为了更新其他内容,那么它将在以后不再需要b时将其删除. 因此,make之前不存在的中间文件在make之后也不存在. make通过打印显示要删除哪个文件的rm -f命令向您报告删除.

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. make reports the deletion to you by printing a rm -f command showing which file it is deleting.

通常,如果文件在makefile中被提及为目标或先决条件,则该文件不能为中间文件. 但是,您可以通过将文件列出为特殊目标.INTERMEDIATE的先决条件来将文件明确标记为中间文件.即使该文件以其他方式明确提及,此方法仍然有效.

Ordinarily, a file cannot be intermediate if it is mentioned in the makefile as a target or prerequisite. However, you can explicitly mark a file as intermediate by listing it as a prerequisite of the special target .INTERMEDIATE. This takes effect even if the file is mentioned explicitly in some other way.

您可以通过将中间文件标记为辅助文件来防止中间文件的自动删除.为此,请将其列出为特殊目标.SECONDARY的先决条件.当文件为辅助文件时,make不会仅仅因为该文件不存在而创建该文件,而是make不会自动删除该文件.将文件标记为辅助文件也将其标记为中间文件.

You can prevent automatic deletion of an intermediate file by marking it as a secondary file. To do this, list it as a prerequisite of the special target .SECONDARY. When a file is secondary, make will not create the file merely because it does not already exist, but make does not automatically delete the file. Marking a file as secondary also marks it as intermediate.

因此,将以下行添加到Makefile中就足够了:

So, adding the following line to the Makefile should be enough:

.INTERMEDIATE : hugefileB hugefileC

首次调用make:

$ make
touch hugefileB
touch hugefileC
cat hugefileB hugefileC > digestA
rm hugefileB hugefileC

下次:

$ make
make: `digestA' is up to date.

这篇关于当创建最重要的目标时,告诉'make'忽略依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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