> Date: Sun, 19 Feb 2012 09:57:03 +0200 > From: Shachar Shemesh <shac...@liveu.tv> > > To see the bug: run "make clean" and "make". /tmp/runlog shows one line > saying "run", which means that the t1 t2 rule was only invoked once. Now > run make clean and "make -j10". The /tmp/runlog now has two lines, showing > that the rule was invoked twice. > > Make -d reveals that the rule was considered twice. Once as "t1", and > another time, before the first one had a chance to complete, as "t2". Make > does not realize that t1 and t2 are built by the same rule, and schedules > the receipt a second time.
Make cannot possibly realize that the same rule builds both t1 and t2, because that's not what your rule says. It says that _either_ one of them is built by invoking the recipe in that rule. So it invokes the rule twice, one each for each one of them. In sequential execution, once the rule was invoked for the first of the two targets, the second already exists, so Make makes a shortcut by not building it. By contrast, in parallel execution, none of the two exist, so Make tries to build them both in parallel, and ends up invoking the same commands twice. If you really want to tell Make that both targets are made by the same rule, the only method you have is to use pattern rules, as explained in this excerpt from the Make manual: Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and recipe. If a pattern rule has multiple targets, `make' knows that the rule's recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets. When searching for a pattern rule to match a target, the target patterns of a rule other than the one that matches the target in need of a rule are incidental: `make' worries only about giving a recipe and prerequisites to the file presently in question. However, when this file's recipe is run, the other targets are marked as having been updated themselves. An example is given later in the manual: This pattern rule has two targets: %.tab.c %.tab.h: %.y bison -d $< _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make