1#                                                                    -*-perl-*-
2$description = "Check GNU make export/unexport commands.";
3
4$details = "";
5
6# The test driver cleans out our environment for us so we don't have to worry
7# about that here.
8
9open(MAKEFILE,"> $makefile");
10
11# The Contents of the MAKEFILE ...
12
13print MAKEFILE <<'EOMAKE';
14
15FOO = foo
16BAR = bar
17BOZ = boz
18
19export BAZ = baz
20export BOZ
21
22BITZ = bitz
23BOTZ = botz
24
25export BITZ BOTZ
26unexport BOTZ
27
28ifdef EXPORT_ALL
29export
30endif
31
32ifdef UNEXPORT_ALL
33unexport
34endif
35
36ifdef EXPORT_ALL_PSEUDO
37.EXPORT_ALL_VARIABLES:
38endif
39
40all:
41	@echo "FOO=$(FOO) BAR=$(BAR) BAZ=$(BAZ) BOZ=$(BOZ) BITZ=$(BITZ) BOTZ=$(BOTZ)"
42	@echo "FOO=$$FOO BAR=$$BAR BAZ=$$BAZ BOZ=$$BOZ BITZ=$$BITZ BOTZ=$$BOTZ"
43
44EOMAKE
45
46close(MAKEFILE);
47
48# TEST 0: basics
49
50&run_make_with_options($makefile,"",&get_logfile,0);
51
52$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
53FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
54
55&compare_output($answer,&get_logfile(1));
56
57# TEST 1: make sure vars inherited from the parent are exported
58
59$extraENV{FOO} = 1;
60
61&run_make_with_options($makefile,"",&get_logfile,0);
62
63$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
64FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
65
66&compare_output($answer,&get_logfile(1));
67
68# TEST 2: global export.  Explicit unexport takes precedence.
69
70&run_make_with_options($makefile,"EXPORT_ALL=1",&get_logfile,0);
71
72$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
73FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
74
75&compare_output($answer,&get_logfile(1));
76
77# TEST 3: global unexport.  Explicit export takes precedence.
78
79&run_make_with_options($makefile,"UNEXPORT_ALL=1",&get_logfile,0);
80
81$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
82FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
83
84&compare_output($answer,&get_logfile(1));
85
86# TEST 4: both: in the above makefile the unexport comes last so that rules.
87
88&run_make_with_options($makefile,"EXPORT_ALL=1 UNEXPORT_ALL=1",&get_logfile,0);
89
90$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
91FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
92
93&compare_output($answer,&get_logfile(1));
94
95# TEST 5: test the pseudo target.
96
97&run_make_with_options($makefile,"EXPORT_ALL_PSEUDO=1",&get_logfile,0);
98
99$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz
100FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n";
101
102&compare_output($answer,&get_logfile(1));
103
104
105# TEST 6: Test the expansion of variables inside export
106
107$makefile2 = &get_tmpfile;
108
109open(MAKEFILE, "> $makefile2");
110
111print MAKEFILE <<'EOF';
112
113foo = f-ok
114bar = b-ok
115
116FOO = foo
117F = f
118
119BAR = bar
120B = b
121
122export $(FOO)
123export $(B)ar
124
125all:
126	@echo foo=$(foo) bar=$(bar)
127	@echo foo=$$foo bar=$$bar
128
129EOF
130
131close(MAKEFILE);
132
133&run_make_with_options($makefile2,"",&get_logfile,0);
134$answer = "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n";
135&compare_output($answer,&get_logfile(1));
136
137
138# TEST 7: Test the expansion of variables inside unexport
139
140$makefile3 = &get_tmpfile;
141
142open(MAKEFILE, "> $makefile3");
143
144print MAKEFILE <<'EOF';
145
146foo = f-ok
147bar = b-ok
148
149FOO = foo
150F = f
151
152BAR = bar
153B = b
154
155export foo bar
156
157unexport $(FOO)
158unexport $(B)ar
159
160all:
161	@echo foo=$(foo) bar=$(bar)
162	@echo foo=$$foo bar=$$bar
163
164EOF
165
166close(MAKEFILE);
167
168&run_make_with_options($makefile3,"",&get_logfile,0);
169$answer = "foo=f-ok bar=b-ok\nfoo= bar=\n";
170&compare_output($answer,&get_logfile(1));
171
172
173# TEST 7: Test exporting multiple variables on the same line
174
175$makefile4 = &get_tmpfile;
176
177open(MAKEFILE, "> $makefile4");
178
179print MAKEFILE <<'EOF';
180
181A = a
182B = b
183C = c
184D = d
185E = e
186F = f
187G = g
188H = h
189I = i
190J = j
191
192SOME = A B C
193
194export F G H I J
195
196export D E $(SOME)
197
198all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
199EOF
200
201close(MAKEFILE);
202
203&run_make_with_options($makefile4,"",&get_logfile,0);
204$answer = "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n";
205&compare_output($answer,&get_logfile(1));
206
207
208# TEST 8: Test unexporting multiple variables on the same line
209
210$makefile5 = &get_tmpfile;
211
212open(MAKEFILE, "> $makefile5");
213
214print MAKEFILE <<'EOF';
215
216A = a
217B = b
218C = c
219D = d
220E = e
221F = f
222G = g
223H = h
224I = i
225J = j
226
227SOME = A B C
228
229unexport F G H I J
230
231unexport D E $(SOME)
232
233all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
234EOF
235
236close(MAKEFILE);
237
238@extraENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10);
239
240&run_make_with_options($makefile5,"",&get_logfile,0);
241$answer = "A= B= C= D= E= F= G= H= I= J=\n";
242&compare_output($answer,&get_logfile(1));
243
244
245# This tells the test driver that the perl test script executed properly.
2461;
247