Search code examples
makefile

Makefile: comma split variable as multiple arguments


Consider following makefile example:

a=1,2,3
b=$1 $2 $3
$(info $(call b,$(a)))

Run this will give me 1,2,3 as output of info function. How can I let Makefile replace a and consider it as three arguments to call, then output 1 2 3?

The only solution I can think of

comma=,
$(info $(call b,$(word 1,$(subst $(comma), ,$(a))),$(word 2,$(subst $(comma), ,$(a))),$(word 3,$(subst $(comma), ,$(a)))))

But it's painful.


Solution

  • $(eval $$(info $$(call b,$(a)))) works.

    But you can't eval just the function call, so I've put info inside too. Perhaps you could do $(eval foo := $$(call b,$(a))) and then read the variable.