1 # $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 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, 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.
28 # The comment does not need to start at the beginning of a word (as in the
29 # shell), it can start anywhere.
30 VAR=# defined but empty
32 # The space before the comment is always trimmed.
38 # This is NOT an escaped comment due to the double backslashes \\
39 VAR= not part of the comment
40 .if ${VAR} != "not part of the comment"
44 # To escape a comment sign, precede it with a backslash.
45 VAR= \# # Both in the assignment.
46 .if ${VAR} != "\#" # And in the comparison.
50 # Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
51 # To keep the parsing code simple, any "[#" does not start a comment, even
52 # outside of a variable expression.
54 .if ${WORDS} != "1 [#"
58 # An odd number of comment signs makes a line continuation, \\\
59 no matter if it is 3 or 5 \\\\\
60 or 9 backslashes. \\\\\\\\\
61 This is the last line of the comment.
62 VAR= no comment anymore
63 .if ${VAR} != "no comment anymore"
68 # In the commands associated with a target, the '#' does not start a makefile
69 # comment. The '#' is just passed to the shell, like any ordinary character.
70 echo This is a shell comment: # comment
71 # If the '#' were to start a makefile comment, the following shell command
72 # would have unbalanced quotes.
73 echo This is not a shell comment: '# comment'
74 @echo A shell comment can#not start in the middle of a word.