(是否可以/如何)将逗号分隔的行分配给 make 文件中的变量?
var1=name,name2,
name3,name4.....
对于空格分隔,我只需使用 \ 像这样
var = name1 name2 \
name3 name4
答案1
[我想您想在多行上写一长串由逗号分隔的单词,与空格分隔的单词列表相同;对于简单的作业,您可以使用var = a,b,c
]
我认为这对于标准来说是不可能的make
;通过 GNU make(Linux 上的默认设置),您可以使用该subst()
函数:
$ cat Makefile
list = first,second,\
third,fourth,\
fifth,sixth
e :=
c := ,
list := $(subst $c $e,$c,$(list))
list:; echo $(list)
$ make
echo first,second,third,fourth,fifth,sixth
first,second,third,fourth,fifth,sixth
如果您使用 GNU make,更好的方法是将列表定义为空格分隔,然后将其转换为逗号分隔:
$ cat Makefile
words = first second \
third fourth \
fifth sixth
e :=
c := ,
clist = $(subst $e $e,$c,$(strip $1))
words:; echo $(call clist,$(words))
$ make
echo first,second,third,fourth,fifth,sixth
first,second,third,fourth,fifth,sixth