varname-dot-newline.mk revision 1.7 1 # $NetBSD: varname-dot-newline.mk,v 1.7 2024/06/15 22:06:31 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 # Check that .newline is read-only
20
21 NEWLINE:= ${.newline}
22
23 .if make(try-to-modify)
24 # A '?=' assignment is fine. This pattern can be used to provide the variable
25 # to older or other variants of make that don't know that variable.
26 .newline?= fallback
27 # expect+1: Cannot overwrite ".newline" as it is read-only
28 .newline= overwritten
29 # expect+1: Cannot append to ".newline" as it is read-only
30 .newline+= appended
31 # expect+1: Cannot delete ".newline" as it is read-only
32 .undef .newline
33 .endif
34
35 .if ${.newline} != ${NEWLINE}
36 . error The .newline variable can be overwritten. It should be read-only.
37 .endif
38
39 all:
40 @${MAKE} -f ${MAKEFILE} try-to-modify || true
41 @echo 'first${.newline}second'
42 @echo 'backslash newline: <${BACKSLASH_NEWLINE}>'
43