使用make的''Remaking Makefiles''功能我使用include
指令(请参阅Makefile: defining rules and prerequisites in recipes)生成部分makefile。现在我一直无法看到如何表达包含的makefile之间的依赖关系。他们似乎都是一次全部评估。Makefile:声明包含文件之间的依赖关系
考虑以下简单的Makefile,说明我的问题:
all:
-include foo.make
-include bar.make
foo.make: Makefile
echo FOO:=blub bla baz > foo.make
bar.make: Makefile foo.make
echo BAR:=$(FOO) > bar.make
如果我现在运行make
我会得到:
$ cat foo.make
FOO:=blub bla baz
$ cat bar.make
BAR:=
为什么?由于bar.make
取决于foo.make
,因此bar.make
的评估不应等到它成功包含foo.make
?
如何解决此问题并确保bar.make
要么稍后重新评估,要么仅评估一次foo.make
存在,已包含并可定义变量BAR
?
我不能结合foo.make
和bar.make
成一个单一的生成文件和规则的原因有两方面:
首先,我真正的设置,bar.make
取决于这又传递地依赖于foo.make
多个中间目标。因此,在创建foo.make
时,bar.make
的内容仍不能创建。
其次,在我的真实设置中,foo.make
和bar.make
不只是定义变量,而且还包括eval()
define/endef
块。所以我必须写:
-include makefile_with_prerequisite_variables
define MYDEF
sometarget-$1: $(TARGET_$1_PREREQUISITES)
[...]
endf
-include makefile_with_eval_call_statements
的makefile_with_prerequisite_variables
和makefile_with_eval_call_statements
内容不能去到一个单一的makefile片段:
- 如果我把
makefile_with_eval_call_statements
以上MYDEF
与makefile_with_prerequisite_variables
然后在$eval($call(MYDEF))
语句组合在一起它不会工作,因为MYDEF
仅在之后被宣布。 - 如果我把
makefile_with_prerequisite_variables
下面MYDEF
与makefile_with_eval_call_statements
在一起,然后在MYDEF
定义的食谱不会有正确的prerequisits因为$(TARGET_$1_PREREQUISITES)
变量,然后由makefile_with_prerequisite_variables
声明之后。
总之,我需要包含两个不同的makefile,其中一个取决于另一个。我不知道如何表达这种关系,以至于只有在其他makefile是最新的并且包含在主makefile中后才会创建一个makefile的内容。
你又一次拯救了我的一天!如果我能给你更多的赞扬,我会。你的建议都非常有价值。非常感谢! – josch