Next: , Previous: , Up: Portable Make Programming   [Contents][Index]

C.2.13 Comments in Make Macros

Avoid putting comments in macro values as far as possible. Posix specifies that the text starting from the ‘#’ sign until the end of the line is to be ignored, which has the unfortunate effect of disallowing them even within quotes. Thus, the following might lead to a syntax error at compile time:


as ‘CPPFLAGS’ may be expanded to ‘"-DCOMMENT_CHAR='’.

Most make implementations disregard this and treat single and double quotes specially here. Also, GNU make lets you put ‘#’ into a macro value by escaping it with a backslash, i.e., ‘\#’. However, neither of these usages are portable. See Comments in Make Rules, for a portable alternative.

Even without quoting involved, comments can have surprising effects, because the whitespace before them is part of the variable value:

foo = bar # trailing comment
print: ; @echo "$(foo)."

prints ‘bar .’, which is usually not intended, and can expose make bugs as described below.