]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bmake/unit-tests/comment.mk
Merge bmake-20201117
[FreeBSD/FreeBSD.git] / contrib / bmake / unit-tests / comment.mk
1 # $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
2 #
3 # Demonstrate how comments are written in makefiles.
4
5 # This is a comment.
6
7 #\
8 This is a multiline comment.
9
10 # Another multiline comment \
11 that \
12 goes \
13 on and on.
14
15  # Comments can be indented with spaces, but that is rather unusual.
16
17         # Comments can be indented with a tab.
18         # These are not shell commands, they are just makefile comments.
19
20 .if 1                   # There can be comments after conditions.
21 .endif                  # And after the closing directive.
22
23 VAR=                    # This comment makes the variable value empty.
24                         # ParseGetLine removes any whitespace before the
25                         # comment.
26 .if ${VAR} != ""
27 .  error
28 .endif
29
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
33
34 # The space before the comment is always trimmed.
35 VAR=    value
36 .if ${VAR} != "value"
37 .  error
38 .endif
39
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"
45 .  error
46 .endif
47
48 # To escape a comment sign, precede it with a backslash.
49 VAR=    \#              # Both in the assignment.
50 .if ${VAR} != "\#"      # And in the comparison.
51 .  error
52 .endif
53
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.
57 WORDS=  ${VAR:[#]} [#
58 .if ${WORDS} != "1 [#"
59 .  error
60 .endif
61
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"
68 .  error
69 .endif
70
71 all:
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.