Reputation: 102246
According to the manual on Defining and Redefining Pattern Rules (and if I am reading it correctly):
‘%’ character matching any sequence of zero or more characters...
But the following is not matching both bench.cpp
and bench2.cpp
:
bench%.o : bench%.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR='"$(PREFIX)/share/cryptopp"' -c $<
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $<
Here's what I see when running make:
$ rm bench*.o
$ make static dynamic cryptest.exe PREFIX=/usr/local
make: Nothing to be done for `static'.
make: Nothing to be done for `dynamic'.
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -c bench.cpp
g++ -DNDEBUG -g -O2 -fPIC -march=native -pipe -DCRYPTOPP_DATA_DIR='"/usr/local/share/cryptopp"' -c bench2.cpp
Above, both bench.cpp
and bench2.cpp
should have -DCRYPTOPP_DATA_DIR='"/usr/local/share/cryptopp"'
. I also tried using the asterisk (*
) with no joy.
How do I craft a rule that matches both bench.cpp
and bench2.cpp
?
Upvotes: 1
Views: 176
Reputation: 102246
Well, I happened to stumble across the proper section of the documentation on this.
According to 4.4 Using Wildcard Characters in File Names, I should probably use an asterisk in this case.
And according to Stallman and the GNUMake manual, %
is not a wildcard for specifying file names:
A single file name can specify many files using wildcard characters. The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’ ...
Upvotes: 1
Reputation: 22596
According to the link you provided
A pattern rule contains the character ‘%’ (exactly one of them) in the target; otherwise, it looks exactly like an ordinary rule. The target is a pattern for matching file names; the ‘%’ matches any nonempty substring, while other characters match only themselves.
So %
doesn't match empty strings.
‘%’ character matching any sequence of zero or more characters...
refers to the definition of vpath
which is totally different.
I'm afraid you'll have to use bench1
instead of bench
. Alternatively you can use macro to defines 2 rules but write it only once.
Upvotes: 1