Using make's ''Remaking Makefiles'' feature I am generating parts of my makefile with include
directives (see Makefile: defining rules and prerequisites in recipes). Now I'm stuck with being unable to see how I can express dependencies between included makefiles. They seem to be all evaluated at once.
Consider the following minimal makefile that illustrates my problem:
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
If I now run make
I will get:
$ cat foo.make
FOO:=blub bla baz
$ cat bar.make
BAR:=
Why? Since bar.make
depends on foo.make
, shouldn't the evaluation of bar.make
wait until it successfully included foo.make
?
And how do I fix this problem and make sure that bar.make
is either re-evaluated later or only evaluated once foo.make
exists, is included and can define the variable BAR
?
The reason I cannot combine foo.make
and bar.make
into a single makefile and rule is two-fold:
Firstly, in my real setup, bar.make
depends on more intermediate targets which in turn transitively depend on foo.make
. So at the time foo.make
can be created, the content of bar.make
cannot yet be made.
Secondly, in my real setup, foo.make
and bar.make
do not just define variables but also eval()
define/endef
blocks. So I have to write:
-include makefile_with_prerequisite_variables
define MYDEF
sometarget-$1: $(TARGET_$1_PREREQUISITES)
[...]
endf
-include makefile_with_eval_call_statements
The content of makefile_with_prerequisite_variables
and makefile_with_eval_call_statements
cannot go into a single makefile snippet:
- If I would put
makefile_with_eval_call_statements
aboveMYDEF
together withmakefile_with_prerequisite_variables
then the$eval( $call( MYDEF))
statements in it would not work becauseMYDEF
is only declared afterward. - If I would put
makefile_with_prerequisite_variables
belowMYDEF
together withmakefile_with_eval_call_statements
then the recipes defined inMYDEF
would not have proper prerequisits because the$(TARGET_$1_PREREQUISITES)
variables would then be declared afterward bymakefile_with_prerequisite_variables
.
In summary, I need to include two different makefiles where one depends upon the other. I do not know how I can express this relationship such that the content of one makefile would only be created after the other makefile is up-to-date and included into the main makefile.