2022-07-26 15:52:53 +00:00
|
|
|
# $NetBSD: comment.mk,v 1.5 2022/05/08 06:51:27 rillig Exp $
|
2020-11-07 19:39:21 +00:00
|
|
|
#
|
|
|
|
# Demonstrate how comments are written in makefiles.
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# This is a comment.
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
#\
|
|
|
|
This is a multiline comment.
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# Another multiline comment \
|
2012-06-08 21:57:36 +00:00
|
|
|
that \
|
|
|
|
goes \
|
2020-11-07 19:39:21 +00:00
|
|
|
on and on.
|
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# Comments can be indented with spaces, but that is rather unusual.
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
# Comments can be indented with a tab.
|
2022-02-05 20:03:50 +00:00
|
|
|
# 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".
|
2020-11-07 19:39:21 +00:00
|
|
|
|
|
|
|
.if 1 # There can be comments after conditions.
|
|
|
|
.endif # And after the closing directive.
|
|
|
|
|
|
|
|
VAR= # This comment makes the variable value empty.
|
2022-07-26 15:52:53 +00:00
|
|
|
# ParseRawLine removes any whitespace before the
|
2020-11-20 03:54:37 +00:00
|
|
|
# comment.
|
2020-11-07 19:39:21 +00:00
|
|
|
.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
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# 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. \\
|
2020-11-07 19:39:21 +00:00
|
|
|
VAR= not part of the comment
|
|
|
|
.if ${VAR} != "not part of the comment"
|
|
|
|
. error
|
|
|
|
.endif
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
# 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 variable modifier :[#] does not need to be escaped.
|
|
|
|
# To keep the parsing code simple, any "[#" does not start a comment, even
|
|
|
|
# outside of a variable expression.
|
|
|
|
WORDS= ${VAR:[#]} [#
|
|
|
|
.if ${WORDS} != "1 [#"
|
|
|
|
. error
|
|
|
|
.endif
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-20 03:54:37 +00:00
|
|
|
# An odd number of backslashes makes a line continuation, \\\
|
2020-11-07 19:39:21 +00:00
|
|
|
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
|
2012-06-08 21:57:36 +00:00
|
|
|
|
2020-11-07 19:39:21 +00:00
|
|
|
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.
|