'How to pass comma character in makefile function

In Makefile there is defined a print function, which takes print text as argument and then print it. My question is that how to pass comma character as a text part to print it ? For example below is relevant makefile section where comma is not printable.

print = echo '$(1)'

help:
        @$(call print, He lives in Paris, does not he?)

Now if run makefile like:

$ make help 

It prints

$  He lives in Paris

instead of

$  He lives in Paris, does not he?

I know in makefile comma uses as argument separate, but how I can make it as printable. I used different escape character combination to pass comma as text message like \, /, $$, ',' "," but nothing works



Solution 1:[1]

You could do something like this:

print = echo '$(1)' | sed 's/(\(.*\))/\1/'

help:
        @$(call print, (He lives in Paris, does not he?))

Output becomes:

$ make help
 He lives in Paris, does not he?

You have to tweak the regex in sed if you include parenthesis in your string.

Solution 2:[2]

Same as the answer of ogus ismail, but with slight optimization:

  • You can use a comma itself as a variable name
, := ,
msg = echo '$1'
help:; @$(call msg,He lives in Paris$(,) does not he?)

Source

Solution 3:[3]

if you want to have parenthesis inside the argument you can use a more elaborate sed script to strip the parenthesis.

define print 
        echo "`echo \"$(1)\" | sed -e 's/^(\|)$$//g'`";
endef

help:
        @$(call print,(He lives in Paris, does not he? in a (house) with parenthesis inside))

Basically you are supposed to change $(1) with echo \"$(1)\" | sed -e 's/^(\|)$$//g'.

Disclaimer: This is from a blog of mine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 laenkeio
Solution 2
Solution 3