posix-varassign.mk revision 1.1 1 1.1 rillig # $NetBSD: posix-varassign.mk,v 1.1 2025/04/13 09:29:33 rillig Exp $
2 1.1 rillig #
3 1.1 rillig # https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html#tag_20_76_13_05
4 1.1 rillig #
5 1.1 rillig # Test that variable assignments work in the same way as in default mode.
6 1.1 rillig #
7 1.1 rillig # The assignment operators "::=" and ":::=" are intentionally not supported,
8 1.1 rillig # as they would introduce the distinction between eagerly and lazily evaluated
9 1.1 rillig # macros, in addition to the eagerly and lazily evaluated assignments, and
10 1.1 rillig # this would add too much complexity to the user's mental model, for too
11 1.1 rillig # little benefit.
12 1.1 rillig
13 1.1 rillig .POSIX:
14 1.1 rillig
15 1.1 rillig
16 1.1 rillig VAR= value
17 1.1 rillig .if ${VAR} != "value"
18 1.1 rillig . error
19 1.1 rillig .endif
20 1.1 rillig
21 1.1 rillig
22 1.1 rillig # Deviation from POSIX: The "::=" assignment operator is not supported,
23 1.1 rillig # instead, the variable named "VAR:" is defined.
24 1.1 rillig VAR= before
25 1.1 rillig VAR::= posix-immediate-expansion
26 1.1 rillig .if ${VAR} != "before"
27 1.1 rillig . error
28 1.1 rillig .elif ${${:UVAR\:}} != "posix-immediate-expansion"
29 1.1 rillig . error
30 1.1 rillig .endif
31 1.1 rillig
32 1.1 rillig
33 1.1 rillig # Deviation from POSIX: The ":::=" assignment operator is not supported,
34 1.1 rillig # instead, the variable named "VAR::" is defined.
35 1.1 rillig VAR:::= posix-delayed-expansion
36 1.1 rillig .if ${VAR} != "before"
37 1.1 rillig . error
38 1.1 rillig .elif ${${:UVAR\:\:}} != "posix-delayed-expansion"
39 1.1 rillig . error
40 1.1 rillig .endif
41 1.1 rillig
42 1.1 rillig
43 1.1 rillig VAR!= echo from shell command
44 1.1 rillig .if ${VAR} != "from shell command"
45 1.1 rillig . error
46 1.1 rillig .endif
47 1.1 rillig
48 1.1 rillig
49 1.1 rillig VAR= value
50 1.1 rillig VAR?= fallback
51 1.1 rillig .if ${VAR} != "value"
52 1.1 rillig . error
53 1.1 rillig .endif
54 1.1 rillig .undef VAR
55 1.1 rillig VAR?= fallback
56 1.1 rillig .if ${VAR} != "fallback"
57 1.1 rillig . error
58 1.1 rillig .endif
59 1.1 rillig
60 1.1 rillig
61 1.1 rillig VAR= value
62 1.1 rillig VAR+= appended
63 1.1 rillig .if ${VAR} != "value appended"
64 1.1 rillig . error
65 1.1 rillig .endif
66 1.1 rillig
67 1.1 rillig
68 1.1 rillig # In POSIX mode, the ":=" assignment operator is available as well, even
69 1.1 rillig # though it is not specified by POSIX, due to the differences in existing
70 1.1 rillig # make implementations.
71 1.1 rillig REF= before
72 1.1 rillig VAR:= immediate ${REF}
73 1.1 rillig REF= after
74 1.1 rillig .if ${VAR} != "immediate before"
75 1.1 rillig . error
76 1.1 rillig .endif
77 1.1 rillig
78 1.1 rillig
79 1.1 rillig all:
80