% 不匹配规则中的零个或多个字符?
% not matching zero or more characters in rule?
根据 Defining and Redefining Pattern Rules 上的手册(如果我没看错的话):
‘%’ character matching any sequence of zero or more characters...
但以下内容不匹配 bench.cpp
和 bench2.cpp
:
bench%.o : bench%.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR='"$(PREFIX)/share/cryptopp"' -c $<
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $<
这是我在 运行 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
以上,bench.cpp
和bench2.cpp
都应该有-DCRYPTOPP_DATA_DIR='"/usr/local/share/cryptopp"'
。我也尝试过使用星号 (*
),但并不开心。
如何制定同时匹配 bench.cpp
和 bench2.cpp
的规则?
根据您提供的 link
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.
因此 %
不匹配空字符串。
‘%’ character matching any sequence of zero or more characters...
指的是vpath
的定义完全不同
恐怕您必须使用 bench1
而不是 bench
。或者你可以使用宏来定义 2 条规则,但只写一次。
好吧,我偶然发现了有关此文档的适当部分。
根据 4.4 Using Wildcard Characters in File Names,在这种情况下我可能应该使用星号。
并且根据 Stallman 和 GNUMake 手册,%
不是用于指定文件名的通配符:
A single file name can specify many files using wildcard characters.
The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’ ...
根据 Defining and Redefining Pattern Rules 上的手册(如果我没看错的话):
‘%’ character matching any sequence of zero or more characters...
但以下内容不匹配 bench.cpp
和 bench2.cpp
:
bench%.o : bench%.cpp
$(CXX) $(CXXFLAGS) -DCRYPTOPP_DATA_DIR='"$(PREFIX)/share/cryptopp"' -c $<
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $<
这是我在 运行 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
以上,bench.cpp
和bench2.cpp
都应该有-DCRYPTOPP_DATA_DIR='"/usr/local/share/cryptopp"'
。我也尝试过使用星号 (*
),但并不开心。
如何制定同时匹配 bench.cpp
和 bench2.cpp
的规则?
根据您提供的 link
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.
因此 %
不匹配空字符串。
‘%’ character matching any sequence of zero or more characters...
指的是vpath
的定义完全不同
恐怕您必须使用 bench1
而不是 bench
。或者你可以使用宏来定义 2 条规则,但只写一次。
好吧,我偶然发现了有关此文档的适当部分。
根据 4.4 Using Wildcard Characters in File Names,在这种情况下我可能应该使用星号。
并且根据 Stallman 和 GNUMake 手册,%
不是用于指定文件名的通配符:
A single file name can specify many files using wildcard characters. The wildcard characters in make are ‘*’, ‘?’ and ‘[…]’ ...