comment.mk revision 1.5 1 1.5 rillig # $NetBSD: comment.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $
2 1.2 rillig #
3 1.2 rillig # Demonstrate how comments are written in makefiles.
4 1.2 rillig
5 1.2 rillig # This is a comment.
6 1.1 apb
7 1.1 apb #\
8 1.2 rillig This is a multiline comment.
9 1.2 rillig
10 1.2 rillig # Another multiline comment \
11 1.2 rillig that \
12 1.2 rillig goes \
13 1.2 rillig on and on.
14 1.2 rillig
15 1.3 rillig # Comments can be indented with spaces, but that is rather unusual.
16 1.1 apb
17 1.2 rillig # Comments can be indented with a tab.
18 1.4 rillig # Since parse.c 1.127 from 2007-01-01, these are not shell commands,
19 1.4 rillig # they are just makefile comments. Before that commit, these comments
20 1.4 rillig # triggered the error message "Unassociated shell command".
21 1.1 apb
22 1.2 rillig .if 1 # There can be comments after conditions.
23 1.2 rillig .endif # And after the closing directive.
24 1.2 rillig
25 1.2 rillig VAR= # This comment makes the variable value empty.
26 1.5 rillig # ParseRawLine removes any whitespace before the
27 1.3 rillig # comment.
28 1.2 rillig .if ${VAR} != ""
29 1.2 rillig . error
30 1.2 rillig .endif
31 1.1 apb
32 1.2 rillig # The comment does not need to start at the beginning of a word (as in the
33 1.2 rillig # shell), it can start anywhere.
34 1.2 rillig VAR=# defined but empty
35 1.2 rillig
36 1.2 rillig # The space before the comment is always trimmed.
37 1.2 rillig VAR= value
38 1.2 rillig .if ${VAR} != "value"
39 1.2 rillig . error
40 1.2 rillig .endif
41 1.1 apb
42 1.3 rillig # This comment ends with 2 backslashes. An even number of backslashes does
43 1.3 rillig # not count as a line continuation, therefore the variable assignment that
44 1.3 rillig # follows is actively interpreted. \\
45 1.2 rillig VAR= not part of the comment
46 1.2 rillig .if ${VAR} != "not part of the comment"
47 1.2 rillig . error
48 1.2 rillig .endif
49 1.1 apb
50 1.2 rillig # To escape a comment sign, precede it with a backslash.
51 1.2 rillig VAR= \# # Both in the assignment.
52 1.2 rillig .if ${VAR} != "\#" # And in the comparison.
53 1.2 rillig . error
54 1.2 rillig .endif
55 1.2 rillig
56 1.2 rillig # Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
57 1.2 rillig # To keep the parsing code simple, any "[#" does not start a comment, even
58 1.2 rillig # outside of a variable expression.
59 1.2 rillig WORDS= ${VAR:[#]} [#
60 1.2 rillig .if ${WORDS} != "1 [#"
61 1.2 rillig . error
62 1.2 rillig .endif
63 1.1 apb
64 1.3 rillig # An odd number of backslashes makes a line continuation, \\\
65 1.2 rillig no matter if it is 3 or 5 \\\\\
66 1.2 rillig or 9 backslashes. \\\\\\\\\
67 1.2 rillig This is the last line of the comment.
68 1.2 rillig VAR= no comment anymore
69 1.2 rillig .if ${VAR} != "no comment anymore"
70 1.2 rillig . error
71 1.2 rillig .endif
72 1.1 apb
73 1.2 rillig all:
74 1.2 rillig # In the commands associated with a target, the '#' does not start a makefile
75 1.2 rillig # comment. The '#' is just passed to the shell, like any ordinary character.
76 1.2 rillig echo This is a shell comment: # comment
77 1.2 rillig # If the '#' were to start a makefile comment, the following shell command
78 1.2 rillig # would have unbalanced quotes.
79 1.2 rillig echo This is not a shell comment: '# comment'
80 1.2 rillig @echo A shell comment can#not start in the middle of a word.
81