directive-export-gmake.mk revision 1.4 1 # $NetBSD: directive-export-gmake.mk,v 1.4 2023/08/19 10:33:32 rillig Exp $
2 #
3 # Tests for the export directive (without leading dot), as in GNU make.
4
5 # The "export" directive only affects the environment of the make process
6 # and its child processes. It does not affect the global variables or any
7 # other variables.
8 VAR= before
9 export VAR=exported
10 .if ${VAR} != "before"
11 . error
12 .endif
13
14 # Ensure that the name-value pair is actually exported.
15 .if ${:!echo "\$VAR"!} != "exported"
16 . error
17 .endif
18
19 # This line looks like it would export 2 variables, but it doesn't.
20 # It only exports VAR and appends everything else as the variable value.
21 export VAR=exported VAR2=exported-as-well
22 .if ${:!echo "\$VAR"!} != "exported VAR2=exported-as-well"
23 . error ${:!echo "\$VAR"!}
24 .endif
25
26 # Contrary to the usual variable assignments, spaces are significant
27 # after the '=' sign and are prepended to the value of the environment
28 # variable.
29 export VAR= leading spaces
30 .if ${:!echo "\$VAR"!} != " leading spaces"
31 . error
32 .endif
33
34 # Contrary to the usual variable assignments, spaces are significant
35 # before the '=' sign and are appended to the name of the environment
36 # variable.
37 #
38 # Depending on the shell, environment variables with such exotic names
39 # may be silently discarded. One such shell is dash, which is the default
40 # shell on Ubuntu and Debian.
41 export VAR =trailing space in varname
42 .if ${:!env | grep trailing || true!} != "VAR =trailing space in varname"
43 . if ${:!env | grep trailing || true!} != "" # for dash
44 . error
45 . endif
46 .endif
47
48 # The right-hand side of the exported variable is expanded exactly once.
49 TWICE= expanded twice
50 ONCE= expanded once, leaving $${TWICE} as-is
51 export VAR=${ONCE}
52 .if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is"
53 . error
54 .endif
55
56 # Undefined variables are allowed on the right-hand side, they expand
57 # to an empty string, as usual.
58 export VAR=an ${UNDEF} variable
59 .if ${:!echo "\$VAR"!} != "an variable"
60 . error
61 .endif
62
63
64 # The body of the .for loop expands to 'export VAR=${:U1}', and the 'export'
65 # directive is only recognized if the line does not contain a ':', to allow
66 # 'export' to be a regular target.
67 .for value in 1
68 # FIXME: The below error message is missing all details. But even if it
69 # contained the text of the line, it would be confusing because at the point
70 # where that error message is printed, all expressions from the line have
71 # already been expanded as part of the dependency line parsing, which in this
72 # case hides the ':' from the error message.
73 # expect+1: Invalid line type
74 export VAR=${value}
75 .endfor
76