Wednesday, May 30, 2007

Multi-line Comments in Make

You see, this is why I hate Make. Did you know that a backslash at the end of a comment line extends the comment to the next line? For example:


# This is a comment \
and this is still a comment


This is all very nice and logical—a trailing backslash means the same thing no matter where it appears in a file—but it has all the niceness and logic just exactly backwards. The behavior of (line-based) comments in every other programming environment I know of is: a comment character (in this case '#') introduces a comment that is terminated by the end of the line; if a line is not preceded by a comment character, it is not a comment.

This may seem harmless. But consider the following:

FILES = \
file1 \
file2 \
file3

Now suppose we decide to temporarily remove file1:

FILES= \
# file1 \
file2 \
file3

Does FILES equal "file2 file3"? No! FILES is empty. And that's if you're lucky and you didn't get some weird syntax error.

No comments: