help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multiple targets on pattern rules


From: Jaime
Subject: Multiple targets on pattern rules
Date: Mon, 22 Feb 2016 03:09:41 +0100

Hello

While adding coverage support on one of my projects, I reached a point
when make is not doing something I expect it to do. I will try to
illustrate it via this example:

#######################
.PHONY: default clean gcov
.SECONDARY:

default: bin.run

gcov: GCOV=1
gcov: bin.gcno bin.gcda

%.run %.gcda: %
        touch $*.run
        [ ! "$(GCOV)" = "1" ] || touch $*.gcda

bin: bin.o
        touch bin

%.o %.gcno: %.cc
        touch $*.o
        [ ! "$(GCOV)" = "1" ] || touch $*.gcno

%.cc:
        touch $*.cc

clean:
        rm -f bin*
#########################

When I first run make, this generates the files bin.cc, bin.o, bin and
bin.run as expected.
Then I do make gcov expecting it to generate bin.gcno and bin.gcda,
and update bin.o, bin and bin.run. However, bin is never updated.

So even when bin.o is updated in the process of generating bin.gcno,
make is not considering it as updated in regards to updating bin.

My expectations come from this paragraph from gnu make manual,
highlighting the last sentence:

----
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.
----

Can anybody explain to me what I am understanding wrong? Using make 3.81
And maybe suggest me a viable alternative for what I am trying to achieve?

Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]