1 1.1 rillig # $NetBSD: directive-export-gmake.mk,v 1.1 2020/10/02 20:34:59 rillig Exp $ 2 1.1 rillig # 3 1.1 rillig # Tests for the export directive (without leading dot), as in GNU make. 4 1.1 rillig 5 1.1 rillig # The "export" directive only affects the environment of the make process 6 1.1 rillig # and its child processes. It does not affect the global variables or any 7 1.1 rillig # other variables. 8 1.1 rillig VAR= before 9 1.1 rillig export VAR=exported 10 1.1 rillig .if ${VAR} != "before" 11 1.1 rillig . error 12 1.1 rillig .endif 13 1.1 rillig 14 1.1 rillig # Ensure that the name-value pair is actually exported. 15 1.1 rillig .if ${:!echo "\$VAR"!} != "exported" 16 1.1 rillig . error 17 1.1 rillig .endif 18 1.1 rillig 19 1.1 rillig # This line looks like it would export 2 variables, but it doesn't. 20 1.1 rillig # It only exports VAR and appends everything else as the variable value. 21 1.1 rillig export VAR=exported VAR2=exported-as-well 22 1.1 rillig .if ${:!echo "\$VAR"!} != "exported VAR2=exported-as-well" 23 1.1 rillig . error ${:!echo "\$VAR"!} 24 1.1 rillig .endif 25 1.1 rillig 26 1.1 rillig # Contrary to the usual variable assignments, spaces are significant 27 1.1 rillig # after the '=' sign and are prepended to the value of the environment 28 1.1 rillig # variable. 29 1.1 rillig export VAR= leading spaces 30 1.1 rillig .if ${:!echo "\$VAR"!} != " leading spaces" 31 1.1 rillig . error 32 1.1 rillig .endif 33 1.1 rillig 34 1.1 rillig # Contrary to the usual variable assignments, spaces are significant 35 1.1 rillig # before the '=' sign and are appended to the name of the environment 36 1.1 rillig # variable. 37 1.1 rillig export VAR =trailing space in varname 38 1.1 rillig .if ${:!env | grep trailing!} != "VAR =trailing space in varname" 39 1.1 rillig . error 40 1.1 rillig .endif 41 1.1 rillig 42 1.1 rillig # The right-hand side of the exported variable is expanded exactly once. 43 1.1 rillig TWICE= expanded twice 44 1.1 rillig ONCE= expanded once, leaving $${TWICE} as-is 45 1.1 rillig export VAR=${ONCE} 46 1.1 rillig .if ${:!echo "\$VAR"!} != "expanded once, leaving \${TWICE} as-is" 47 1.1 rillig . error 48 1.1 rillig .endif 49 1.1 rillig 50 1.1 rillig # Undefined variables are allowed on the right-hand side, they expand 51 1.1 rillig # to an empty string, as usual. 52 1.1 rillig export VAR=an ${UNDEF} variable 53 1.1 rillig .if ${:!echo "\$VAR"!} != "an variable" 54 1.1 rillig . error 55 1.1 rillig .endif 56 1.1 rillig 57 1.1 rillig all: 58 1.1 rillig @:; 59