aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/unit-tests/comment.mk
blob: fea0f0b3d8170a1f07df6017b921fb444b5d9aa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# $NetBSD: comment.mk,v 1.7 2024/04/23 22:51:28 rillig Exp $
#
# Demonstrate how comments are written in makefiles.

# This is a comment.

#\
This is a multiline comment.

# Another multiline comment \
that \
goes \
on and on.

 # Comments can be indented with spaces, but that is rather unusual.

	# Comments can be indented with a tab.
	# Since parse.c 1.127 from 2007-01-01, these are not shell commands,
	# they are just makefile comments.  Before that commit, these comments
	# triggered the error message "Unassociated shell command".

.if 1			# There can be comments after conditions.
.endif			# And after the closing directive.

VAR=			# This comment makes the variable value empty.
			# ParseRawLine removes any whitespace before the
			# comment.
.if ${VAR} != ""
.  error
.endif

# The comment does not need to start at the beginning of a word (as in the
# shell), it can start anywhere.
VAR=# defined but empty

# The space before the comment is always trimmed.
VAR=	value
.if ${VAR} != "value"
.  error
.endif

# This comment ends with 2 backslashes.  An even number of backslashes does
# not count as a line continuation, therefore the variable assignment that
# follows is actively interpreted. \\
VAR=	not part of the comment
.if ${VAR} != "not part of the comment"
.  error
.endif

# To escape a comment sign, precede it with a backslash.
VAR=	\#		# Both in the assignment.
.if ${VAR} != "\#"	# And in the comparison.
.  error
.endif

# Since 2012-03-24 the modifier :[#] does not need to be escaped.
# To keep the parsing code simple, the "#" in "[#" does not start a comment,
# regardless of the syntactical context it appears in.
WORDS=	${VAR:[#]} [#
.if ${WORDS} != "1 [#"
.  error
.endif

# An odd number of backslashes makes a line continuation, \\\
no matter if it is 3 or 5 \\\\\
or 9 backslashes. \\\\\\\\\
This is the last line of the comment.
VAR=	no comment anymore
.if ${VAR} != "no comment anymore"
.  error
.endif

all:
# In the commands associated with a target, the '#' does not start a makefile
# comment.  The '#' is just passed to the shell, like any ordinary character.
	echo This is a shell comment: # comment
# If the '#' were to start a makefile comment, the following shell command
# would have unbalanced quotes.
	echo This is not a shell comment: '# comment'
	@echo A shell comment can#not start in the middle of a word.