带有空格的Makefile字符串 [英] Makefile string with spaces

查看:469
本文介绍了带有空格的Makefile字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var := 'C:/some/path here' labas
all:
    @echo $(words $(var))

这将返回3. 如何使其返回2?还是make不符合我的想法?

This returns 3. How to make it return 2? Or make does not work the way I think??

推荐答案

如果您认为make对任何类型的引号都有兴趣,那么Make绝对不会按照您的想法工作:).在几乎每种情况下,make都会忽略(即像其他字符一样对待普通字符)单引号和双引号字符,并且所有make函数都可以在简单的空格定界符中工作,而无需考虑引号字符.

Make definitely doesn't work the way you think, if you think that make has any interest in quotes of any type :). Make ignores (i.e., treats as normal characters like any other) both single- and double-quote characters in virtually every situation, and all make functions work in simple whitespace delimiters without regard to quote characters.

通常,将make与任何在目标名称中需要空格的系统一起使用是不切实际的.只是行不通:太多的make都是基于空白作为分隔符,并且没有通用,通用的方法来逃逸可在任何地方使用的空白.

In general, it's not practical to use make with any system that requires spaces in target names. It just doesn't work: too much of make is based on whitespace as a separator character and there's no general, common way to escape the whitespace that works everywhere.

在非常特殊的情况下,您可以玩这样的把戏:

In your very particular case you can play a trick like this:

E :=
S := $E $E

path := C:/some/path here
xpath := $(subst $S,^,$(path))

var := $(xpath) labas
all:
        @echo $(words $(var))
        @echo $(subst ^,$S,$(var))

基本上,这会创建一个包含空格的变量$S,然后用其他一些非空格字符替换变量path中的所有空格(在这里我选择了^,但是您可以选择自己喜欢的,只需注意它必须是保证不会出现在路径中的字符.

Basically, this creates a variable $S which contains a space, then it substitutes all spaces in the variable path with some other, non-space character (here I chose ^ but you can pick what you like, just note it has to be a character which is guaranteed to not appear in the path).

现在此路径不包含空格,因此您可以将其与make函数一起使用.

Now this path doesn't contain whitespace so you can use it with make functions.

这具有主要缺点:不仅在这里可见复杂性,而且请注意,这些路径不能在目标名称中使用,因为它们实际上并不存在于磁盘上.

This has major downsides: not only the complexity visible here, but note these paths cannot be used in target names since they won't actually exist on disk.

通常,您不应简单地将包含空格的路径与make一起使用.如果必须使用包含空格的路径,则很可能make不是您要使用的正确工具.

In general, you should simply not use paths containing whitespace with make. If you must use paths containing whitespace, then very likely make is not the right tool for you to be using.

这篇关于带有空格的Makefile字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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