In my makefile I have a recipe that produces two files. If either of those two files are out of date, the recipe should run, once. So something like this:
file1 file2 : deps
make_files
Note that the make_files
command always produces both files, and its invocation does not depend on the target (i.e., we don't use the target name or any stem in its invocation).
The problem is that make interprets this as two rules, one for file1
and one for file2
, causing it to potentially run make_files
twice if both are missing (e.g., when using make -j
), which blows up (make_files
is actually invoking make
in another subdirectory and this doesn't work if it is invoked twice concurrently).
Any fix, for example to tell make
to just run make_files
once?
Right now the hack I'm using is to make file2
depend on file1
, even though it doesn't:
file2 : file1
This causes make
to serialize the make_files
invocations. This doesn't always work well, however: in the case that both files are missing, it will run make_files
once to make them, but then if file2
has a later timestamp than file1
, it will make run make_files
again.