comment.mk (bmake-20201101) | : | comment.mk (bmake-20201117) | ||
---|---|---|---|---|
# $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 rillig Exp $ | # $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $ | |||
# | # | |||
# Demonstrate how comments are written in makefiles. | # Demonstrate how comments are written in makefiles. | |||
# This is a comment. | # This is a comment. | |||
#\ | #\ | |||
This is a multiline comment. | This is a multiline comment. | |||
# Another multiline comment \ | # Another multiline comment \ | |||
that \ | that \ | |||
goes \ | goes \ | |||
on and on. | on and on. | |||
# Comments can be indented, but that is rather unusual. | # Comments can be indented with spaces, but that is rather unusual. | |||
# Comments can be indented with a tab. | # Comments can be indented with a tab. | |||
# These are not shell commands, they are just makefile comments. | # These are not shell commands, they are just makefile comments. | |||
.if 1 # There can be comments after conditions. | .if 1 # There can be comments after conditions. | |||
.endif # And after the closing directive. | .endif # And after the closing directive. | |||
VAR= # This comment makes the variable value empty. | VAR= # This comment makes the variable value empty. | |||
# ParseGetLine removes any whitespace before the | ||||
# comment. | ||||
.if ${VAR} != "" | .if ${VAR} != "" | |||
. error | . error | |||
.endif | .endif | |||
# The comment does not need to start at the beginning of a word (as in the | # The comment does not need to start at the beginning of a word (as in the | |||
# shell), it can start anywhere. | # shell), it can start anywhere. | |||
VAR=# defined but empty | VAR=# defined but empty | |||
# The space before the comment is always trimmed. | # The space before the comment is always trimmed. | |||
VAR= value | VAR= value | |||
.if ${VAR} != "value" | .if ${VAR} != "value" | |||
. error | . error | |||
.endif | .endif | |||
# This is NOT an escaped comment due to the double backslashes \\ | # 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 | VAR= not part of the comment | |||
.if ${VAR} != "not part of the comment" | .if ${VAR} != "not part of the comment" | |||
. error | . error | |||
.endif | .endif | |||
# To escape a comment sign, precede it with a backslash. | # To escape a comment sign, precede it with a backslash. | |||
VAR= \# # Both in the assignment. | VAR= \# # Both in the assignment. | |||
.if ${VAR} != "\#" # And in the comparison. | .if ${VAR} != "\#" # And in the comparison. | |||
. error | . error | |||
.endif | .endif | |||
# Since 2012-03-24 the variable modifier :[#] does not need to be escaped. | # Since 2012-03-24 the variable modifier :[#] does not need to be escaped. | |||
# To keep the parsing code simple, any "[#" does not start a comment, even | # To keep the parsing code simple, any "[#" does not start a comment, even | |||
# outside of a variable expression. | # outside of a variable expression. | |||
WORDS= ${VAR:[#]} [# | WORDS= ${VAR:[#]} [# | |||
.if ${WORDS} != "1 [#" | .if ${WORDS} != "1 [#" | |||
. error | . error | |||
.endif | .endif | |||
# An odd number of comment signs makes a line continuation, \\\ | # An odd number of backslashes makes a line continuation, \\\ | |||
no matter if it is 3 or 5 \\\\\ | no matter if it is 3 or 5 \\\\\ | |||
or 9 backslashes. \\\\\\\\\ | or 9 backslashes. \\\\\\\\\ | |||
This is the last line of the comment. | This is the last line of the comment. | |||
VAR= no comment anymore | VAR= no comment anymore | |||
.if ${VAR} != "no comment anymore" | .if ${VAR} != "no comment anymore" | |||
. error | . error | |||
.endif | .endif | |||
all: | all: | |||
# In the commands associated with a target, the '#' does not start a makefile | # In the commands associated with a target, the '#' does not start a makefile | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 8 lines changed or added |