xref: /freebsd/contrib/bmake/unit-tests/comment.mk (revision 36d6566e5985030fd2f1100bd9c1387bbe0bd290)
1# $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 rillig Exp $
2#
3# Demonstrate how comments are written in makefiles.
4
5# This is a comment.
6
7#\
8This is a multiline comment.
9
10# Another multiline comment \
11that \
12goes \
13on and on.
14
15 # Comments can be indented, 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
23VAR=			# This comment makes the variable value empty.
24.if ${VAR} != ""
25.  error
26.endif
27
28# The comment does not need to start at the beginning of a word (as in the
29# shell), it can start anywhere.
30VAR=# defined but empty
31
32# The space before the comment is always trimmed.
33VAR=	value
34.if ${VAR} != "value"
35.  error
36.endif
37
38# This is NOT an escaped comment due to the double backslashes \\
39VAR=	not part of the comment
40.if ${VAR} != "not part of the comment"
41.  error
42.endif
43
44# To escape a comment sign, precede it with a backslash.
45VAR=	\#		# Both in the assignment.
46.if ${VAR} != "\#"	# And in the comparison.
47.  error
48.endif
49
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.
53WORDS=	${VAR:[#]} [#
54.if ${WORDS} != "1 [#"
55.  error
56.endif
57
58# An odd number of comment signs makes a line continuation, \\\
59no matter if it is 3 or 5 \\\\\
60or 9 backslashes. \\\\\\\\\
61This is the last line of the comment.
62VAR=	no comment anymore
63.if ${VAR} != "no comment anymore"
64.  error
65.endif
66
67all:
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.
75