Home | History | Annotate | Line # | Download | only in unit-tests
comment.mk revision 1.3
      1  1.3  rillig # $NetBSD: comment.mk,v 1.3 2020/11/15 14:07:53 rillig Exp $
      2  1.2  rillig #
      3  1.2  rillig # Demonstrate how comments are written in makefiles.
      4  1.2  rillig 
      5  1.2  rillig # This is a comment.
      6  1.1     apb 
      7  1.1     apb #\
      8  1.2  rillig This is a multiline comment.
      9  1.2  rillig 
     10  1.2  rillig # Another multiline comment \
     11  1.2  rillig that \
     12  1.2  rillig goes \
     13  1.2  rillig on and on.
     14  1.2  rillig 
     15  1.3  rillig  # Comments can be indented with spaces, but that is rather unusual.
     16  1.1     apb 
     17  1.2  rillig 	# Comments can be indented with a tab.
     18  1.2  rillig 	# These are not shell commands, they are just makefile comments.
     19  1.1     apb 
     20  1.2  rillig .if 1			# There can be comments after conditions.
     21  1.2  rillig .endif			# And after the closing directive.
     22  1.2  rillig 
     23  1.2  rillig VAR=			# This comment makes the variable value empty.
     24  1.3  rillig 			# ParseGetLine removes any whitespace before the
     25  1.3  rillig 			# comment.
     26  1.2  rillig .if ${VAR} != ""
     27  1.2  rillig .  error
     28  1.2  rillig .endif
     29  1.1     apb 
     30  1.2  rillig # The comment does not need to start at the beginning of a word (as in the
     31  1.2  rillig # shell), it can start anywhere.
     32  1.2  rillig VAR=# defined but empty
     33  1.2  rillig 
     34  1.2  rillig # The space before the comment is always trimmed.
     35  1.2  rillig VAR=	value
     36  1.2  rillig .if ${VAR} != "value"
     37  1.2  rillig .  error
     38  1.2  rillig .endif
     39  1.1     apb 
     40  1.3  rillig # This comment ends with 2 backslashes.  An even number of backslashes does
     41  1.3  rillig # not count as a line continuation, therefore the variable assignment that
     42  1.3  rillig # follows is actively interpreted. \\
     43  1.2  rillig VAR=	not part of the comment
     44  1.2  rillig .if ${VAR} != "not part of the comment"
     45  1.2  rillig .  error
     46  1.2  rillig .endif
     47  1.1     apb 
     48  1.2  rillig # To escape a comment sign, precede it with a backslash.
     49  1.2  rillig VAR=	\#		# Both in the assignment.
     50  1.2  rillig .if ${VAR} != "\#"	# And in the comparison.
     51  1.2  rillig .  error
     52  1.2  rillig .endif
     53  1.2  rillig 
     54  1.2  rillig # Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
     55  1.2  rillig # To keep the parsing code simple, any "[#" does not start a comment, even
     56  1.2  rillig # outside of a variable expression.
     57  1.2  rillig WORDS=	${VAR:[#]} [#
     58  1.2  rillig .if ${WORDS} != "1 [#"
     59  1.2  rillig .  error
     60  1.2  rillig .endif
     61  1.1     apb 
     62  1.3  rillig # An odd number of backslashes makes a line continuation, \\\
     63  1.2  rillig no matter if it is 3 or 5 \\\\\
     64  1.2  rillig or 9 backslashes. \\\\\\\\\
     65  1.2  rillig This is the last line of the comment.
     66  1.2  rillig VAR=	no comment anymore
     67  1.2  rillig .if ${VAR} != "no comment anymore"
     68  1.2  rillig .  error
     69  1.2  rillig .endif
     70  1.1     apb 
     71  1.2  rillig all:
     72  1.2  rillig # In the commands associated with a target, the '#' does not start a makefile
     73  1.2  rillig # comment.  The '#' is just passed to the shell, like any ordinary character.
     74  1.2  rillig 	echo This is a shell comment: # comment
     75  1.2  rillig # If the '#' were to start a makefile comment, the following shell command
     76  1.2  rillig # would have unbalanced quotes.
     77  1.2  rillig 	echo This is not a shell comment: '# comment'
     78  1.2  rillig 	@echo A shell comment can#not start in the middle of a word.
     79