如何强制Make始终执行配方 [英] How can I force Make to execute a recipe all the time
问题描述
当前的Makefile具有以下内容:
The current Makefile has something like this:
target1 : lib1.a lib2.a
target2 : lib1.a lib3.a
target3 : lib3.a
lib1.a:
$(MAKE) -C sub_dir all
我想更改此Makefile,以便无论目标依赖于lib1.a
的位置如何,它始终始终运行命令"$(MAKE) -C sub_dir all
".换句话说,在上面的示例中,target1和target2将始终运行"$(MAKE) -C sub_dir all
".有什么办法可以做到吗?
I want to change this Makefile so that wherever a target depends on lib1.a
, it always run the command "$(MAKE) -C sub_dir all
", always. Another words, in the above example, target1 and target2 will always run "$(MAKE) -C sub_dir all
". Is there any way I can do that?
我知道以下内容无效:
target1 : lib2.a
$(MAKE) -C sub_dir all
target2 : lib3.a
$(MAKE) -C sub_dir all
target3 : lib3.a
由于lib2.a没有更新,因此该命令无法运行.我有一个限制,我只能控制lib1.a,不能更改lib2.a的构建方式.
Because if lib2.a has no update, the the command does not run. I have one restriction, I only control lib1.a, I cannot change how lib2.a is built.
感谢您的帮助!
更新:我使用以下解决方案:
UPDATE: I used the following solution:
target1 : lib1.a lib2.a
target2 : lib1.a lib3.a
target3 : lib3.a
lib1.a: relay
.PHONY: relay
relay:
$(MAKE) -C sub_dir all
GNU提供帮助表示,FORCE效率不如.PHONY,但从您的解释来看,在我看来,FORCE更好.我会误会吗?
The GNU Make help says that FORCE is not as efficient as .PHONY, but from your explanation, it seems to me FORCE is better. Do I mis-understand?
推荐答案
我认为 Force Target
是您在这里寻找的东西.
I think a Force Target
is what you are looking for here.
lib1.a: FORCE
$(MAKE) -C sub_dir all
FORCE: ;
As compared to a .PHONY
rule (as suggested by @MadScientist here) this will not in-and-of-itself force all the targets that depend on lib1.a
to rebuild all the time. It will only do that if lib1.a
actually changes.
尽管有一个更好的解决方案,它可能会完全摆脱子make,并且实际上可以(直接或通过sub_dir
中包含的makefile)将lib1.a
的依赖项信息提供给此makefile,因为这样可以避免整个过程因为我无法告诉您如何确定目标是否需要更新,所以强制执行此食谱"问题.
A better solution though is likely to get rid of the sub-make entirely and actually have the dependency information for lib1.a
available to this makefile (either directly or via an included makefile in sub_dir
) because that avoids this entire "force this recipe because I can't tell you how to tell if the target needs updating" problem.
这篇关于如何强制Make始终执行配方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!