xref: /freebsd/contrib/bmake/unit-tests/comment.mk (revision 548bfc56eb0b2cefa0fb8dc2478240bfef610309)
1*548bfc56SSimon J. Gerraty# $NetBSD: comment.mk,v 1.7 2024/04/23 22:51:28 rillig Exp $
2956e45f6SSimon J. Gerraty#
3956e45f6SSimon J. Gerraty# Demonstrate how comments are written in makefiles.
4956e45f6SSimon J. Gerraty
5956e45f6SSimon J. Gerraty# This is a comment.
6db29cad8SSimon J. Gerraty
7db29cad8SSimon J. Gerraty#\
8956e45f6SSimon J. GerratyThis is a multiline comment.
9db29cad8SSimon J. Gerraty
10956e45f6SSimon J. Gerraty# Another multiline comment \
11db29cad8SSimon J. Gerratythat \
12db29cad8SSimon J. Gerratygoes \
13956e45f6SSimon J. Gerratyon and on.
14956e45f6SSimon J. Gerraty
15e2eeea75SSimon J. Gerraty # Comments can be indented with spaces, but that is rather unusual.
16956e45f6SSimon J. Gerraty
17956e45f6SSimon J. Gerraty	# Comments can be indented with a tab.
189f45a3c8SSimon J. Gerraty	# Since parse.c 1.127 from 2007-01-01, these are not shell commands,
199f45a3c8SSimon J. Gerraty	# they are just makefile comments.  Before that commit, these comments
209f45a3c8SSimon J. Gerraty	# triggered the error message "Unassociated shell command".
21956e45f6SSimon J. Gerraty
22956e45f6SSimon J. Gerraty.if 1			# There can be comments after conditions.
23956e45f6SSimon J. Gerraty.endif			# And after the closing directive.
24956e45f6SSimon J. Gerraty
25956e45f6SSimon J. GerratyVAR=			# This comment makes the variable value empty.
26954401e6SSimon J. Gerraty			# ParseRawLine removes any whitespace before the
27e2eeea75SSimon J. Gerraty			# comment.
28956e45f6SSimon J. Gerraty.if ${VAR} != ""
29956e45f6SSimon J. Gerraty.  error
30956e45f6SSimon J. Gerraty.endif
31956e45f6SSimon J. Gerraty
32956e45f6SSimon J. Gerraty# The comment does not need to start at the beginning of a word (as in the
33956e45f6SSimon J. Gerraty# shell), it can start anywhere.
34956e45f6SSimon J. GerratyVAR=# defined but empty
35956e45f6SSimon J. Gerraty
36956e45f6SSimon J. Gerraty# The space before the comment is always trimmed.
37956e45f6SSimon J. GerratyVAR=	value
38956e45f6SSimon J. Gerraty.if ${VAR} != "value"
39956e45f6SSimon J. Gerraty.  error
40956e45f6SSimon J. Gerraty.endif
41db29cad8SSimon J. Gerraty
42e2eeea75SSimon J. Gerraty# This comment ends with 2 backslashes.  An even number of backslashes does
43e2eeea75SSimon J. Gerraty# not count as a line continuation, therefore the variable assignment that
44e2eeea75SSimon J. Gerraty# follows is actively interpreted. \\
45956e45f6SSimon J. GerratyVAR=	not part of the comment
46956e45f6SSimon J. Gerraty.if ${VAR} != "not part of the comment"
47956e45f6SSimon J. Gerraty.  error
48956e45f6SSimon J. Gerraty.endif
49db29cad8SSimon J. Gerraty
50956e45f6SSimon J. Gerraty# To escape a comment sign, precede it with a backslash.
51956e45f6SSimon J. GerratyVAR=	\#		# Both in the assignment.
52956e45f6SSimon J. Gerraty.if ${VAR} != "\#"	# And in the comparison.
53956e45f6SSimon J. Gerraty.  error
54956e45f6SSimon J. Gerraty.endif
55db29cad8SSimon J. Gerraty
56*548bfc56SSimon J. Gerraty# Since 2012-03-24 the modifier :[#] does not need to be escaped.
57*548bfc56SSimon J. Gerraty# To keep the parsing code simple, the "#" in "[#" does not start a comment,
58*548bfc56SSimon J. Gerraty# regardless of the syntactical context it appears in.
59956e45f6SSimon J. GerratyWORDS=	${VAR:[#]} [#
60956e45f6SSimon J. Gerraty.if ${WORDS} != "1 [#"
61956e45f6SSimon J. Gerraty.  error
62956e45f6SSimon J. Gerraty.endif
63db29cad8SSimon J. Gerraty
64e2eeea75SSimon J. Gerraty# An odd number of backslashes makes a line continuation, \\\
65956e45f6SSimon J. Gerratyno matter if it is 3 or 5 \\\\\
66956e45f6SSimon J. Gerratyor 9 backslashes. \\\\\\\\\
67956e45f6SSimon J. GerratyThis is the last line of the comment.
68956e45f6SSimon J. GerratyVAR=	no comment anymore
69956e45f6SSimon J. Gerraty.if ${VAR} != "no comment anymore"
70956e45f6SSimon J. Gerraty.  error
71956e45f6SSimon J. Gerraty.endif
72956e45f6SSimon J. Gerraty
73956e45f6SSimon J. Gerratyall:
74956e45f6SSimon J. Gerraty# In the commands associated with a target, the '#' does not start a makefile
75956e45f6SSimon J. Gerraty# comment.  The '#' is just passed to the shell, like any ordinary character.
76956e45f6SSimon J. Gerraty	echo This is a shell comment: # comment
77956e45f6SSimon J. Gerraty# If the '#' were to start a makefile comment, the following shell command
78956e45f6SSimon J. Gerraty# would have unbalanced quotes.
79956e45f6SSimon J. Gerraty	echo This is not a shell comment: '# comment'
80956e45f6SSimon J. Gerraty	@echo A shell comment can#not start in the middle of a word.
81