VirtualBox

source: kBuild/trunk/src/kmk/tests/scripts/variables/define@ 2634

Last change on this file since 2634 was 2591, checked in by bird, 13 years ago

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

File size: 3.7 KB
Line 
1# -*-perl-*-
2
3$description = "Test define/endef variable assignments.";
4
5$details = "";
6
7# TEST 0: old-style basic define/endef
8
9run_make_test('
10define multi
11@echo hi
12echo there
13endef
14
15all: ; $(multi)
16',
17 '', "hi\necho there\nthere\n");
18
19# TEST 1: Various new-style define/endef
20
21run_make_test('
22FOO = foo
23
24define multi =
25echo hi
26@echo $(FOO)
27endef # this is the end
28
29define simple :=
30@echo $(FOO)
31endef
32
33append = @echo a
34
35define append +=
36
37@echo b
38endef
39
40define cond ?= # this is a conditional
41@echo first
42endef
43
44define cond ?=
45@echo second
46endef
47
48FOO = there
49
50all: ; $(multi)
51 $(simple)
52 $(append)
53 $(cond)
54',
55 '', "echo hi\nhi\nthere\nfoo\na\nb\nfirst\n");
56
57# TEST 2: define in true section of conditional (containing conditional)
58
59run_make_test('
60FOO = foo
61NAME = def
62def =
63ifdef BOGUS
64 define $(subst e,e,$(NAME)) =
65 ifeq (1,1)
66 FOO = bar
67 endif
68 endef
69endif
70
71$(eval $(def))
72all: ; @echo $(FOO)
73',
74 'BOGUS=1', "bar\n");
75
76# TEST 3: define in false section of conditional (containing conditional)
77
78run_make_test(undef, '', "foo\n");
79
80# TEST 4: nested define (supported?)
81
82run_make_test('
83define outer
84 define inner
85 A = B
86 endef
87endef
88
89$(eval $(outer))
90
91outer: ; @echo $(inner)
92',
93 '', "A = B\n");
94
95# TEST 5: NEGATIVE: Missing variable name
96
97run_make_test('
98NAME =
99define $(NAME) =
100ouch
101endef
102all: ; @echo ouch
103',
104 '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512);
105
106# TEST 6: NEGATIVE: extra text after define
107
108run_make_test('
109NAME =
110define NAME = $(NAME)
111ouch
112endef
113all: ; @echo ok
114',
115 '', "#MAKEFILE#:3: extraneous text after `define' directive\nok\n");
116
117# TEST 7: NEGATIVE: extra text after endef
118
119run_make_test('
120NAME =
121define NAME =
122ouch
123endef $(NAME)
124all: ; @echo ok
125',
126 '', "#MAKEFILE#:5: extraneous text after `endef' directive\nok\n");
127
128# TEST 8: NEGATIVE: missing endef
129
130run_make_test('
131NAME =
132all: ; @echo ok
133define NAME =
134ouch
135endef$(NAME)
136',
137 '', "#MAKEFILE#:4: *** missing `endef', unterminated `define'. Stop.\n", 512);
138
139# -------------------------
140# Make sure that prefix characters apply properly to define/endef values.
141#
142# There's a bit of oddness here if you try to use a variable to hold the
143# prefix character for a define. Even though something like this:
144#
145# define foo
146# echo bar
147# endef
148#
149# all: ; $(V)$(foo)
150#
151# (where V=@) can be seen by the user to be obviously different than this:
152#
153# define foo
154# $(V)echo bar
155# endef
156#
157# all: ; $(foo)
158#
159# and the user thinks it should behave the same as when the "@" is literal
160# instead of in a variable, that can't happen because by the time make
161# expands the variables for the command line and sees it begins with a "@" it
162# can't know anymore whether the prefix character came before the variable
163# reference or was included in the first line of the variable reference.
164
165# TEST #5
166# -------
167
168run_make_test('
169define FOO
170$(V1)echo hello
171$(V2)echo world
172endef
173all: ; @$(FOO)
174', '', 'hello
175world');
176
177# TEST #6
178# -------
179
180run_make_test(undef, 'V1=@ V2=@', 'hello
181world');
182
183# TEST #7
184# -------
185
186run_make_test('
187define FOO
188$(V1)echo hello
189$(V2)echo world
190endef
191all: ; $(FOO)
192', 'V1=@', 'hello
193echo world
194world');
195
196# TEST #8
197# -------
198
199run_make_test(undef, 'V2=@', 'echo hello
200hello
201world');
202
203# TEST #9
204# -------
205
206run_make_test(undef, 'V1=@ V2=@', 'hello
207world');
208
209# TEST #10
210# -------
211# Test the basics; a "@" internally to the variable applies to only one line.
212# A "@" before the variable applies to the entire variable.
213
214run_make_test('
215define FOO
216@echo hello
217echo world
218endef
219define BAR
220echo hello
221echo world
222endef
223
224all: foo bar
225foo: ; $(FOO)
226bar: ; @$(BAR)
227', '', 'hello
228echo world
229world
230hello
231world
232');
233
2341;
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette