1# $NetBSD: directive-export-gmake.mk,v 1.3 2020/11/17 20:16:44 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.
8VAR=	before
9export 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.
21export 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.
29export 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.
41export 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.
49TWICE=	expanded twice
50ONCE=	expanded once, leaving $${TWICE} as-is
51export 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.
58export VAR=an ${UNDEF} variable
59.if ${:!echo "\$VAR"!} != "an  variable"
60.  error
61.endif
62
63all:
64	@:;
65