1 # $NetBSD: directive-export-gmake.mk,v 1.3 2020/11/17 20:16:44 rillig Exp $
3 # Tests for the export directive (without leading dot), as in GNU make.
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
10 .if ${VAR} != "before"
14 # Ensure that the name-value pair is actually exported.
15 .if ${:!echo "\$VAR"!} != "exported"
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"!}
26 # Contrary to the usual variable assignments, spaces are significant
27 # after the '=' sign and are prepended to the value of the environment
29 export VAR= leading spaces
30 .if ${:!echo "\$VAR"!} != " leading spaces"
34 # Contrary to the usual variable assignments, spaces are significant
35 # before the '=' sign and are appended to the name of the environment
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
48 # The right-hand side of the exported variable is expanded exactly once.
50 ONCE= expanded once, leaving $${TWICE} as-is
52 .if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is"
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"