Linux makefile进程变量,包含项目列表,其中一个项目是带空格的带引号的字符串

Linux makefile进程变量,包含项目列表,其中一个项目是带空格的带引号的字符串,linux,makefile,gnu,Linux,Makefile,Gnu,以以下makefile片段为例: VAR_LIST = "item1" "item2" "item 3 that has spaces" "item4" ARGS = $(addprefix echo ,$(VAR_LIST)) 我试图实现的是ARGS包含: echo“item1”echo“item2”echo“item3,其中包含空格“echo”item4” 我不知道如何解决像addprefix这样的函数作用于空格…不确定使用make是否可以轻松实现所需的内容,因为引用字符串对处理单词的ma

以以下makefile片段为例:

VAR_LIST = "item1" "item2" "item 3 that has spaces" "item4"
ARGS = $(addprefix echo ,$(VAR_LIST))
我试图实现的是ARGS包含:

echo“item1”echo“item2”echo“item3,其中包含空格“echo”item4”


我不知道如何解决像addprefix这样的函数作用于空格…

不确定使用
make
是否可以轻松实现所需的内容,因为引用字符串对处理单词的
make
函数没有影响:
是单词的一部分


我会使用shell或python脚本来实现这一点。

不确定使用
make
是否可以轻松实现您需要的内容,因为引用字符串对处理单词的
make
函数没有影响:
是单词的一部分


我会使用shell或python脚本来实现这一点。

您可以在GNUmake内部的帮助下完成这一点。它不像完整编程语言那样简单,但至少它是可移植的,并且独立于外部shell风格和工具

include gmtt/gmtt.mk

VAR_LIST = "item1" "item2" "item 3 that has spaces" "item4"

# make a prefix-list by splitting at ". This will yield superfluous space 
# characters between the items, but we can eliminate them later
prefix-list := $(call chop-str-spc,$(VAR_LIST),A $(-alnum-as-str))
$(info $(prefix-list))

# Now we select the data payload from the prefix-list. Spaces inside items 
# are still encoded as $(-spacereplace) characters, which is good as we have  
# a normal make list this way
string-list := $(call get-sufx-val,$(prefix-list),A,,100)
$(info $(string-list))

# Using get-sufx-val() is fine, but we can have it even simpler, by dropping
# the prefix, as we have only one in the list anyway:
string-list := $(call drop-prfx,$(prefix-list))

# Now step through the list with a normal for loop, converting $(-spacereplace)
# back to real spaces 
$(foreach item,$(string-list),$(if $(strip $(call spc-unmask,$(item))),\
   $(info [$(call spc-unmask,$(item))])))
输出:

$ make
 A¤item1 A¤§ A¤item2 A¤§ A¤item§3§that§has§spaces A¤§ A¤item4
item1 § item2 § item§3§that§has§spaces § item4
[item1]
[item2]
[item 3 that has spaces]
[item4]

你可以在GNUmake的帮助下完成这项工作。它不像完整编程语言那样简单,但至少它是可移植的,并且独立于外部shell风格和工具

include gmtt/gmtt.mk

VAR_LIST = "item1" "item2" "item 3 that has spaces" "item4"

# make a prefix-list by splitting at ". This will yield superfluous space 
# characters between the items, but we can eliminate them later
prefix-list := $(call chop-str-spc,$(VAR_LIST),A $(-alnum-as-str))
$(info $(prefix-list))

# Now we select the data payload from the prefix-list. Spaces inside items 
# are still encoded as $(-spacereplace) characters, which is good as we have  
# a normal make list this way
string-list := $(call get-sufx-val,$(prefix-list),A,,100)
$(info $(string-list))

# Using get-sufx-val() is fine, but we can have it even simpler, by dropping
# the prefix, as we have only one in the list anyway:
string-list := $(call drop-prfx,$(prefix-list))

# Now step through the list with a normal for loop, converting $(-spacereplace)
# back to real spaces 
$(foreach item,$(string-list),$(if $(strip $(call spc-unmask,$(item))),\
   $(info [$(call spc-unmask,$(item))])))
输出:

$ make
 A¤item1 A¤§ A¤item2 A¤§ A¤item§3§that§has§spaces A¤§ A¤item4
item1 § item2 § item§3§that§has§spaces § item4
[item1]
[item2]
[item 3 that has spaces]
[item4]

你想用这个来解决的更大的问题是什么?@MaximEgorushkin我想要一个makefile用户可以填写的doxygen配置变量。这些项看起来像
“VAR=Some Value”
。然后我需要将它们转换成如下内容:
;echo“VAR=Some Value”
,其中分号是列表分隔符。然后我将其导入doxygen命令。请参见此处的第一个答案:。这有意义吗?@MaximEgorushkin我可以让用户添加这样的项目:
;echo“VAR=some value”
。。。但这看起来像是一个可怕的语法强加给用户。。。现在我说的是,他们只能使用没有空格的值(这基本上是可以的)。不确定你需要的东西是否可以通过make轻松实现。我会使用shell或python脚本来实现它。@MaximEgorushkin是的,我想我同意你的看法。可能有一些可怕的make函数集可以应用,但它确实很复杂(如果可能的话)。我看到了一些非常聪明/可怕的代码!。。。但正如你所说,使用脚本我只是没有想到这一点,好主意-请随意添加一个答案:)你想用这个解决什么更大的问题?@MaximeGroushkin我想要一个doxygen配置变量,makefile用户可以填写。这些项看起来像
“VAR=Some Value”
。然后我需要将它们转换成如下内容:
;echo“VAR=Some Value”
,其中分号是列表分隔符。然后我将其导入doxygen命令。请参见此处的第一个答案:。这有意义吗?@MaximEgorushkin我可以让用户添加这样的项目:
;echo“VAR=some value”
。。。但这看起来像是一个可怕的语法强加给用户。。。现在我说的是,他们只能使用没有空格的值(这基本上是可以的)。不确定你需要的东西是否可以通过make轻松实现。我会使用shell或python脚本来实现它。@MaximEgorushkin是的,我想我同意你的看法。可能有一些可怕的make函数集可以应用,但它确实很复杂(如果可能的话)。我看到了一些非常聪明/可怕的代码!。。。但正如你所说,使用脚本我只是没有想到这一点,好主意-请随意添加一个答案:)这是可行的(见我的答案)-一个人可以争论复杂性,但我认为电池包含的属性大于缺少优雅。这是可行的(见我的答案)-一个人可以争论复杂性,但我认为电池包含的属性大于缺少优雅。哇。。。。你能做到这一点真是太神奇了。。。。但是代码真的不好-我几乎不能理解它,所以对于将来的维护,这不是我的第一选择。但是代码是+1!你是指这个代码还是库中它后面的代码?All make编程基本上是一个非常简单的函数范例,只有一种数据类型,字符串。前缀列表是处理集合的一种方法。哇。。。。你能做到这一点真是太神奇了。。。。但是代码真的不好-我几乎不能理解它,所以对于将来的维护,这不是我的第一选择。但是代码是+1!你是指这个代码还是库中它后面的代码?All make编程基本上是一个非常简单的函数范例,只有一种数据类型,字符串。前缀列表是处理集合的一种方法。