Home | History | Annotate | Line # | Download | only in unit-tests
comment.mk revision 1.2
      1  1.2  rillig # $NetBSD: comment.mk,v 1.2 2020/09/07 19:17:36 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.2  rillig  # Comments can be indented, 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.2  rillig .if ${VAR} != ""
     25  1.2  rillig .  error
     26  1.2  rillig .endif
     27  1.1     apb 
     28  1.2  rillig # The comment does not need to start at the beginning of a word (as in the
     29  1.2  rillig # shell), it can start anywhere.
     30  1.2  rillig VAR=# defined but empty
     31  1.2  rillig 
     32  1.2  rillig # The space before the comment is always trimmed.
     33  1.2  rillig VAR=	value
     34  1.2  rillig .if ${VAR} != "value"
     35  1.2  rillig .  error
     36  1.2  rillig .endif
     37  1.1     apb 
     38  1.1     apb # This is NOT an escaped comment due to the double backslashes \\
     39  1.2  rillig VAR=	not part of the comment
     40  1.2  rillig .if ${VAR} != "not part of the comment"
     41  1.2  rillig .  error
     42  1.2  rillig .endif
     43  1.1     apb 
     44  1.2  rillig # To escape a comment sign, precede it with a backslash.
     45  1.2  rillig VAR=	\#		# Both in the assignment.
     46  1.2  rillig .if ${VAR} != "\#"	# And in the comparison.
     47  1.2  rillig .  error
     48  1.2  rillig .endif
     49  1.2  rillig 
     50  1.2  rillig # Since 2012-03-24 the variable modifier :[#] does not need to be escaped.
     51  1.2  rillig # To keep the parsing code simple, any "[#" does not start a comment, even
     52  1.2  rillig # outside of a variable expression.
     53  1.2  rillig WORDS=	${VAR:[#]} [#
     54  1.2  rillig .if ${WORDS} != "1 [#"
     55  1.2  rillig .  error
     56  1.2  rillig .endif
     57  1.1     apb 
     58  1.2  rillig # An odd number of comment signs makes a line continuation, \\\
     59  1.2  rillig no matter if it is 3 or 5 \\\\\
     60  1.2  rillig or 9 backslashes. \\\\\\\\\
     61  1.2  rillig This is the last line of the comment.
     62  1.2  rillig VAR=	no comment anymore
     63  1.2  rillig .if ${VAR} != "no comment anymore"
     64  1.2  rillig .  error
     65  1.2  rillig .endif
     66  1.1     apb 
     67  1.2  rillig all:
     68  1.2  rillig # In the commands associated with a target, the '#' does not start a makefile
     69  1.2  rillig # comment.  The '#' is just passed to the shell, like any ordinary character.
     70  1.2  rillig 	echo This is a shell comment: # comment
     71  1.2  rillig # If the '#' were to start a makefile comment, the following shell command
     72  1.2  rillig # would have unbalanced quotes.
     73  1.2  rillig 	echo This is not a shell comment: '# comment'
     74  1.2  rillig 	@echo A shell comment can#not start in the middle of a word.
     75