Home | History | Annotate | Line # | Download | only in unit-tests
      1  1.7  rillig # $NetBSD: varname-dot-newline.mk,v 1.7 2024/06/15 22:06:31 rillig Exp $
      2  1.1  rillig #
      3  1.5  rillig # Tests for the special .newline variable, which contains a single newline
      4  1.5  rillig # character (U+000A).
      5  1.5  rillig 
      6  1.5  rillig 
      7  1.5  rillig # https://austingroupbugs.net/view.php?id=1549 proposes:
      8  1.5  rillig # > After all macro expansion is complete, when an escaped <newline> is
      9  1.5  rillig # > found in a command line in a makefile, the command line that is executed
     10  1.5  rillig # > shall contain the <backslash>, the <newline>, and the next line, except
     11  1.5  rillig # > that the first character of the next line shall not be included if it is
     12  1.5  rillig # > a <tab>.
     13  1.3  rillig #
     14  1.5  rillig # The above quote assumes that each resulting <newline> character has a "next
     15  1.5  rillig # line", but that's not how the .newline variable works.
     16  1.5  rillig BACKSLASH_NEWLINE:=	\${.newline}
     17  1.5  rillig 
     18  1.5  rillig 
     19  1.6     sjg # Check that .newline is read-only
     20  1.3  rillig 
     21  1.3  rillig NEWLINE:=	${.newline}
     22  1.3  rillig 
     23  1.7  rillig .if make(try-to-modify)
     24  1.7  rillig # A '?=' assignment is fine.  This pattern can be used to provide the variable
     25  1.7  rillig # to older or other variants of make that don't know that variable.
     26  1.7  rillig .newline?=	fallback
     27  1.7  rillig # expect+1: Cannot overwrite ".newline" as it is read-only
     28  1.3  rillig .newline=	overwritten
     29  1.7  rillig # expect+1: Cannot append to ".newline" as it is read-only
     30  1.7  rillig .newline+=	appended
     31  1.7  rillig # expect+1: Cannot delete ".newline" as it is read-only
     32  1.7  rillig .undef .newline
     33  1.7  rillig .endif
     34  1.3  rillig 
     35  1.6     sjg .if ${.newline} != ${NEWLINE}
     36  1.6     sjg .  error The .newline variable can be overwritten.  It should be read-only.
     37  1.3  rillig .endif
     38  1.1  rillig 
     39  1.1  rillig all:
     40  1.7  rillig 	@${MAKE} -f ${MAKEFILE} try-to-modify || true
     41  1.3  rillig 	@echo 'first${.newline}second'
     42  1.5  rillig 	@echo 'backslash newline: <${BACKSLASH_NEWLINE}>'
     43