make : rule call rule
In a makefile, can I call a rule from another rule?
Similar to:
rule1:
echo "bye"
rule2:
date
rule3:
@echo "hello"
rule1
Solution 1:
Either use dependencies or recursive making to connect from one rule to another.
Dependencies would be done like this (though the order will be different):
rule1:
echo "bye"
rule2:
date
rule3: rule1
@echo "hello"
Recursive make would be done like this (though it does involve a subprocess):
rule1:
echo "bye"
rule2:
date
rule3:
@echo "hello"
$(MAKE) rule1
Neither is perfect; indeed, with recursive make you can get into significant problems if you build a loop. You also probably ought to add a .PHONY
rule so as to mark those rules above as synthetic, so that a stray rule1
(etc.) in the directory won't cause confusion.
Solution 2:
Just add a new rule with the ordering you want..
rule1:
echo "bye"
rule2:
date
rule3:
@echo "hello"
rule4: rule3 rule1