Home | History | Annotate | Line # | Download | only in unit-tests
varname-dot-newline.mk revision 1.5
      1 # $NetBSD: varname-dot-newline.mk,v 1.5 2023/01/17 19:42:47 rillig Exp $
      2 #
      3 # Tests for the special .newline variable, which contains a single newline
      4 # character (U+000A).
      5 
      6 
      7 # https://austingroupbugs.net/view.php?id=1549 proposes:
      8 # > After all macro expansion is complete, when an escaped <newline> is
      9 # > found in a command line in a makefile, the command line that is executed
     10 # > shall contain the <backslash>, the <newline>, and the next line, except
     11 # > that the first character of the next line shall not be included if it is
     12 # > a <tab>.
     13 #
     14 # The above quote assumes that each resulting <newline> character has a "next
     15 # line", but that's not how the .newline variable works.
     16 BACKSLASH_NEWLINE:=	\${.newline}
     17 
     18 
     19 # Contrary to the special variable named "" that is used in expressions like
     20 # ${:Usome-value}, the variable ".newline" is not protected against
     21 # modification.  Nobody exploits that though.
     22 
     23 NEWLINE:=	${.newline}
     24 
     25 .newline=	overwritten
     26 
     27 .if ${.newline} == ${NEWLINE}
     28 .  info The .newline variable cannot be overwritten.  Good.
     29 .else
     30 .  info The .newline variable can be overwritten.  Just don't do that.
     31 .endif
     32 
     33 # Restore the original value.
     34 .newline=	${NEWLINE}
     35 
     36 all:
     37 	@echo 'first${.newline}second'
     38 	@echo 'backslash newline: <${BACKSLASH_NEWLINE}>'
     39