Reputation: 13
I'm having trouble understanding what seems to be a basic make
behavior, having multiple prerequisites with some common stem be matched by one rule.
I tried reading the Pattern intro chapter and seem to be misunderstanding some fundamentals.
all: prefix-variant1.so prefix-variant2.so
prefix-%.so : %.o
@echo "variant with prerequisite succeeded"
when I run make
, I get the following error:
make: *** No rule to make target 'prefix-variant1.so', needed by 'all'. Stop.
What am I doing wrong?
Upvotes: 1
Views: 279
Reputation: 15091
What am I doing wrong?
Keep in mind that make allows to have many concurrent pattern/suffix rules. For example, an object file %.o
can be created by a C compiler from %.c
, or by C++ compiler from %.cpp
, or even by Fortran from %.f
and so on, and so on.
Therefore, a pattern rule is only taken into account if a corresponding prerequisite file exists (or can be built, see Chained Rules). In your case it's variant1.o
. If no such file exists in the current directory, and no other rule is suitable for building it from source, make ignores the rule and says that there's "no rule to make target".
Upvotes: 2