用makefile中的换行替换空格

Sur*_*ran 13 string makefile

有谁知道如何将字符串中的所有空格替换为Makefile中的新行(GNU make)

bob*_*ogo 22

text := hello a b c

null :=
space := ${null} ${null}
${space} := ${space}# ${ } is a space. Neat huh?

define \n


endef

$(error [$(subst ${ },${\n},${text})])
Run Code Online (Sandbox Code Playgroud)


Dan*_*ing 6

shell使用 GNU Make 的函数来进行替换可能更容易,也更干净sed,而不是尝试完全在make.

STRING := foo bar baz
SPLIT  := $(shell echo "${STRING}" | sed -e 's/ /\n/g')
Run Code Online (Sandbox Code Playgroud)

或者,如果您的 shell 不是bash默认的,则稍微好一点sh

STRING := foo bar baz
SPLIT  := $(shell sed -e 's/ /\n/g' <<< ${STRING})
Run Code Online (Sandbox Code Playgroud)