0

(Is it possible/How) to assign comma separated lines to a variable in make file?

var1=name,name2,
name3,name4..... 

For space separated I just have use \ like this

var = name1 name2 \
name3 name4
0

[I suppose that you want to write a long list of words separated by comma on multiple lines, the same as with space separated word lists; for a simple assignment, you can just do it with var = a,b,c]

I don't think that's possible with the standard make; with GNU make (the default on linux), you can use the subst() function for that:

$ 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

If you're using GNU make a better approach would be to the define the list as space-separated, and transform it to comma-separated later on:

$ 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.