在 GNU make 文档中,'%' 被记录为匹配“任何非空子字符串”。但是,它似乎实际上只匹配不包含空格的非空子字符串。例如,假设您这样做:
mkdir /tmp/foo
cd /tmp/foo
echo 'int main() { return 0; }' > "test.c"
echo 'int main() { return 0; }' > "test space.c"
现在,您应该能够使用 GNU Make 的内置模式规则来构建这些:
anthony@Zia:/tmp/foo$ make "test"
cc test.c -o test
anthony@Zia:/tmp/foo$ make "test space"
make: *** No rule to make target `test space'. Stop.
当您编写 makefile 时也会发生同样的问题。
anthony@Zia:/tmp/foo$ rm test
anthony@Zia:/tmp/foo$ echo 'all: test test\ space' > Makefile
anthony@Zia:/tmp/foo$ make
cc test.c -o test
make: *** No rule to make target `test space', needed by `all'. Stop.
即使您显式添加%: %.c
规则,结果也是一样的。但是,如果您向 Makefile 添加显式规则,就像这样,它可以工作:
test\ space: test\ space.c
$(CC) -o "$@" "$<" # first char is tab, of course.
有没有一个技巧可以让空间与隐式规则一起工作?
编辑
我已经发送了一个错误报告: http: //lists.gnu.org/archive/html/bug-make/2011-06/msg00002.html