# Strip anything past '#'. '#' characters cannot be escaped
# in Makefiles, so we don't have to be smart.
+ # FIXME: Actually, '#' *can* be escaped in GNU make ...
+ # FIXME: Should we adapt our code?
$val =~ s/#.*$//s;
# Strip backslashes.
$val =~ s/\\$/ /mg;
# VAR = foo # com bar
# Furthermore keeping '#' would not be portable if the variable is
# output on multiple lines.
- map { s/ ?#.*// } @values;
+ # But we have to preserve escaped '#', so that a definition line:
+ # hash = \#
+ # remains possible. To make our life easier, we just assume that
+ # any tailed comment must be separated with whitespace from the
+ # actual variable value.
+ map { s/^#.*//; s/[ \t]+#.*// } @values;
return join (' ', @values);
}
var5 = ok \
# ko
+var6 = \# \
+\#\\\\\# seen # not seen
+
+var6 += \# \# # again not seen
+
.PHONY: test
test:
test -z '$(var1)'
# Use '[', not 'test', here, so that spurious comments
# are ensured to cause syntax errors.
[ $(var5) = ok ]
+ test '$(var6)' = '# #\\# seen # #'
# Yes, this file ends with a backslash-newline. So what?
\
EOF
cat > Makefile.am << 'EOF'
-VAR = valA# comA ## com C
+VAR = valA # comA ## com C
VAR += valB # comB
if COND1
VAR += val1 # com1
if COND2
VAR += val2 # com2
endif COND2
+VAR2 = # this will be happily ignored
+VAR2 += x
+VAR2 += # this will be happily ignored too
+VAR2 += y
.PHONY: test
test:
is $(VAR) == valA valB val1 valC val2
+ is $(VAR2) == x y
EOF
$ACLOCAL