Reputation: 72639
I have in my GNU makefile (among others) several rules of the form
a b c d: x
program $^
i.e. program
creates the files a, b, c and d with just one invokation.
When I run this with gmake -j 4
, make spawns four program
runs in parallel, because none of the files exist and none has a dependency on the other.
I can fix this by providing a "fake dependency chain" (for lack of a better term):
a: x
program $^
b: a
c: b
d: c
Is there a more elegant way to teach gmake to run program
only once, even in a parallel build?
EDIT: Any solution should obey the dependency on x
and do nothing if a - d
are up to date with respect to x
.
Upvotes: 0
Views: 541
Reputation: 100836
If your targets all share a common stem, then you can use pattern rules:
%.a %.b %.c %.d:
touch $*.a $*.b $*.c $*.d
If they don't then the only thing you can do is create a sentinel file:
a b c d: .sentinel ;
.sentinel: ; touch a b c d $@
Upvotes: 1