Reputation: 1551
I have two makefiles
Makefile 1:
all: run1 temp1 clean1
run1:
command1
temp1:
command2
clean1:
command3
Makefile 2:
all: run2 temp2 clean2
run2:
command4
temp2:
command5
clean2:
command6
I want to create a new Makefile which can include both Makefile 1 and 2.
Makefile:
include Makefile_1
include Makefile_2
Now the sequence of targets should be : run1 temp1 clean1 run2 temp2 clean2
Does including the makefile works? Note both makefiles have common 'all' target.
Upvotes: 0
Views: 175
Reputation: 100806
If you include multiple makefiles and they define the same target, then the prerequisites of the targets are appended in the order in which they targets are parsed (of course only one target at most can have a recipe associated with it).
In your example if you write:
include Makefile_1
include Makefile_2
Then, it'll be the same as if you wrote:
all: run1 temp1 clean1 run2 temp2 clean2
Note, the only way to be 100% sure that make will build targets in a specific order is either (a) never using -j
to enable parallel builds, or else (b) define proper prerequisite relationships between your targets.
Upvotes: 2