如何获取模式规则以使文件名与Makefile中的空格匹配? [英] How to get pattern rules to match file names with spaces in Makefile?

查看:160
本文介绍了如何获取模式规则以使文件名与Makefile中的空格匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GNU make文档中,记录了%"以匹配任何非空子字符串".但是,它似乎实际上只匹配不包含空格的非空子字符串.例如,假设您这样做:

In the GNU make docs, '%' is documented to match "any nonempty substring". However, it seems it actually only matches non-empty substrings that do not contain whitespace. For example, say you do this:

mkdir /tmp/foo
cd /tmp/foo
echo 'int main() { return 0; }' > "test.c"
echo 'int main() { return 0; }' > "test space.c"

现在,您应该能够使用GNU Make的内置模式规则来构建它们:

Now, you should be able to build these using GNU Make's built-in pattern rules:

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时也会发生同样的问题.

The same problem happens when you write a 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中添加显式规则,则它会起作用:

Even if you explicitly add in a %: %.c rule, the result is the same. But if you add in an explicit rule to the Makefile, like this, it works:

test\ space: test\ space.c
    $(CC) -o "$@" "$<"     # first char is tab, of course.

是否有技巧来获取空间以使用隐式规则?

Is there a trick to get spaces to work with implicit rules?

我发送了一个错误报告: http: //lists.gnu.org/archive/html/bug-make/2011-06/msg00002.html

I've sent a bug report: http://lists.gnu.org/archive/html/bug-make/2011-06/msg00002.html

推荐答案

我不这么认为. make根深蒂固地将以空格分隔的标记列表作为字符串传递的概念.这些列表将被解析和重新解析.在UNIX世界中,目录和文件名中的空格被认为是不好的做法,这是有原因的.

I don't believe so. The notion of a list of whitespace-separated tokens being passed around as a string is pretty deeply ingrained in make. Those lists are parsed and reparsed. There's a reason why spaces in directory and file names is considered bad practice in the UNIX world.

这篇关于如何获取模式规则以使文件名与Makefile中的空格匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆