10
有谁知道如何更换所有的空格在字符串中的一个Makefile新线(GNU使)更换新线空间在生成文件
有谁知道如何更换所有的空格在字符串中的一个Makefile新线(GNU使)更换新线空间在生成文件
text := hello a b c
null :=
space := ${null} ${null}
${space} := ${space}# ${ } is a space. Neat huh?
define \n
endef
$(error [$(subst ${ },${\n},${text})])
它可能更容易 - 和清洁 - 以使用GNU make的shell
功能与sed
做更换,而不是试图内make
完全做到这一点。
STRING := foo bar baz
SPLIT := $(shell echo "${STRING}" | sed -e 's/ /\n/g')
或者,稍微好一点,如果你的shell是bash
而不是默认的sh
:
STRING := foo bar baz
SPLIT := $(shell sed -e 's/ /\n/g' <<< ${STRING})
你确定它的$ {}在最后一行 – 2011-01-19 12:51:07
是的,我在第5行定义了这个宏。`$ {space}`和`$ {}`在这里都可以正常工作。 – bobbogo 2011-01-19 13:04:03