强制make从文件中查找过时的条件 [英] Force make to find out-of-date condition from file
问题描述
(这类似于 GNU make:执行目标但从文件中获取依赖项,但略有不同).
(this is similar to GNU make: Execute target but take dependency from file but slightly different).
当我尝试强制建立目标时,make会自动认为该目标已过时,并强制运行依赖该目标的所有目标.
When I try to force to build a target, make automatically thinks that this target is out of date and forces a run of all targets which depend on it.
在我的情况下,目标是一个递归的make调用,它需要做很多工作,并且可能只是返回什么都没做":
In my case, the target is a recursive make call which does a lot of work and might just return with "nothing to be done":
.PHONY: intermediate.dat
intermediate.dat:
$(MAKE) expensive_chain_which_finally_creates_intermediate.dat
step1.dat: intermediate.dat
sleep 10
step2.dat: step1.dat
sleep 15
step3.dat: step2.dat
sleep 10
all: step3.dat
sleep 5
在这种情况下,"make all"运行40秒钟,尽管没有更改middle.dat(递归make返回没事做").但是,如果 if 进行了递归的make更新中间体.dat,则目标应已过期.
In this case, "make all" runs for 40 seconds although intermediate.dat might not have changed (recursive make returned "nothing to be done"). However, if the recursive make updated intermediate.dat, the target shall be out of date.
真的没有办法做到吗?
问候 divB
推荐答案
使intermediate.dat
依赖成为假冒的目标,而不是成为假冒本身.
Make intermediate.dat
depend on a phony target instead of being phony itself.
.PHONY : always-remake
intermediate.dat : always-remake
IIRC,我上次解决该问题时,.PHONY未能按预期工作,因此我使用了:
IIRC, the last time I solved the problem, the .PHONY didn't work as intended and I used:
always-remake :
@true
相反.但是,我不记得为什么,所以请首先尝试.PHONY.
instead. However, I can't recall why, so try the .PHONY first.
使intermediate.dat
本身为伪音的问题是make
从不检查伪音文件的存在/日期,这是您想要的行为.您仅需要触发重建规则,这是通过已过期的先决条件完成的.假的前提条件总是过时的,所以它可以完成工作.
The problem with making intermediate.dat
itself phony is that make
never checks the existence/date of a phony file, which is behaviour that you want. You only need to trigger the rebuild rule, which is done by a prerequisite that is out of date; a phony prerequisite is always out of date, so it does the job.
这篇关于强制make从文件中查找过时的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!