Saturday, March 12, 2022

[SOLVED] How to pass comma character in makefile function

Issue

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

The manual says:

Commas and unmatched parentheses or braces cannot appear in the text of an argument as written; leading spaces cannot appear in the text of the first argument as written. These characters can be put into the argument value by variable substitution.

So, you need to put comma into a variable, and use it in the argument. E.g:

print = echo '$(1)'
comma:= ,

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


Answered By - oguz ismail
Answer Checked By - Senaida (WPSolving Volunteer)