Search code examples
macrosgnu-makevariadic-macros

How to do variadic macros with $(call ...) in GNU Make


I created a macro for use in makefiles along the lines of:

TODO_MSG = $(warning TODO: $(1))
$(call TODO_MSG, This part of the msg displays fine, but this part does not)

I can get around it with something like the following:

BLAH := $(shell perl -e 'print join( " ", 2..200 )'
COMMA := ,
TODO_MSG = $(warning TODO:$(1)$(strip $(foreach x,${BLAH},$(if $(${x}),${COMMA}$(${x}))))

... but I'm curious whether there is anything offering more explicit support for variadic macros.


Solution

  • Here is a remix on Beta's solution:

    TODO_MSG = $(warning TODO: $(1))
    
    test:
            $(call TODO_MSG, $(strip This part displays fine, and this does too))
    

    If there was an $(identity ...) function for Make, I'd use that; $(strip ...) was the closest I could find.