1 # $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
3 # Demonstrate how comments are written in makefiles.
8 This is a multiline comment.
10 # Another multiline comment \
15 # Comments can be indented with spaces, but that is rather unusual.
17 # Comments can be indented with a tab.
18 # These are not shell commands, they are just makefile comments.
20 .if 1 # There can be comments after conditions.
21 .endif # And after the closing directive.
23 VAR= # This comment makes the variable value empty.
24 # ParseGetLine removes any whitespace before the
30 # The comment does not need to start at the beginning of a word (as in the
31 # shell), it can start anywhere.
32 VAR=# defined but empty
34 # The space before the comment is always trimmed.
40 # This comment ends with 2 backslashes. An even number of backslashes does
41 # not count as a line continuation, therefore the variable assignment that
42 # follows is actively interpreted. \\
43 VAR= not part of the comment
44 .if ${VAR} != "not part of the comment"
48 # To escape a comment sign, precede it with a backslash.
49 VAR= \# # Both in the assignment.
50 .if ${VAR} != "\#" # And in the comparison.
54 # Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
55 # To keep the parsing code simple, any "[#" does not start a comment, even
56 # outside of a variable expression.
58 .if ${WORDS} != "1 [#"
62 # An odd number of backslashes makes a line continuation, \\\
63 no matter if it is 3 or 5 \\\\\
64 or 9 backslashes. \\\\\\\\\
65 This is the last line of the comment.
66 VAR= no comment anymore
67 .if ${VAR} != "no comment anymore"
72 # In the commands associated with a target, the '#' does not start a makefile
73 # comment. The '#' is just passed to the shell, like any ordinary character.
74 echo This is a shell comment: # comment
75 # If the '#' were to start a makefile comment, the following shell command
76 # would have unbalanced quotes.
77 echo This is not a shell comment: '# comment'
78 @echo A shell comment can#not start in the middle of a word.