Is there a way to execute a recipe more than once? In the SSCCE below it appears that the recipe is executed only once:
$ cat Makefile
.PHONY: a b
a: b b
b:
echo "beta"
$ make
echo "beta"
beta
Once you've read and understood the comments ;-), there are two ways I can think of to run a recipe twice:
@OliCharlesworth mentions the first - use a loop inside your recipe:
.PHONY: a b
a: b b
b:
for i in 1 2; do \
echo "beta" ;\
done
Note you need to be quite careful when embedding multi-line shell expressions in recipes. Unless you terminate lines with backslashes, make will treat each line as a separate shell invocation, which wouldn't work for a loop.
The other way is to duplicate your b target, so that both copies have the same recipe:
.PHONY: a b1 b2
a: b1 b2
b1 b2:
echo "beta"
This defines the b1
and b2
targets with the same recipe. Then a
depends on both b1
and b2
, so the recipe gets called twice. Note that there is no guarantee of the order in which b1
and b2
will be invoked - and they'll likely be invoked concurrently if you have a -j factor greater than 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With