VirtualBox

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

Last change on this file was 3140, checked in by bird, 7 years ago

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

File size: 4.3 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
33define posix ::=
34@echo $(FOO)
35endef
36
37append = @echo a
38
39define append +=
40
41@echo b
42endef
43
44define cond ?= # this is a conditional
45@echo first
46endef
47
48define cond ?=
49@echo second
50endef
51
52FOO = there
53
54all: ; $(multi)
55 $(simple)
56 $(posix)
57 $(append)
58 $(cond)
59',
60 '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n");
61
62# TEST 1a: Various new-style define/endef, with no spaces
63
64run_make_test('
65FOO = foo
66
67define multi=
68echo hi
69@echo $(FOO)
70endef # this is the end
71
72define simple:=
73@echo $(FOO)
74endef
75
76define posix::=
77@echo $(FOO)
78endef
79
80append = @echo a
81
82define append+=
83
84@echo b
85endef
86
87define cond?= # this is a conditional
88@echo first
89endef
90
91define cond?=
92@echo second
93endef
94
95FOO = there
96
97all: ; $(multi)
98 $(simple)
99 $(posix)
100 $(append)
101 $(cond)
102',
103 '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n");
104
105# TEST 2: define in true section of conditional (containing conditional)
106
107run_make_test('
108FOO = foo
109NAME = def
110def =
111ifdef BOGUS
112 define $(subst e,e,$(NAME)) =
113 ifeq (1,1)
114 FOO = bar
115 endif
116 endef
117endif
118
119$(eval $(def))
120all: ; @echo $(FOO)
121',
122 'BOGUS=1', "bar\n");
123
124# TEST 3: define in false section of conditional (containing conditional)
125
126run_make_test(undef, '', "foo\n");
127
128# TEST 4: nested define (supported?)
129
130run_make_test('
131define outer
132 define inner
133 A = B
134 endef
135endef
136
137$(eval $(outer))
138
139outer: ; @echo $(inner)
140',
141 '', "A = B\n");
142
143# TEST 5: NEGATIVE: Missing variable name
144
145run_make_test('
146NAME =
147define $(NAME) =
148ouch
149endef
150all: ; @echo ouch
151',
152 '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512);
153
154# TEST 6: NEGATIVE: extra text after define
155
156run_make_test('
157NAME =
158define NAME = $(NAME)
159ouch
160endef
161all: ; @echo ok
162',
163 '', "#MAKEFILE#:3: extraneous text after 'define' directive\nok\n");
164
165# TEST 7: NEGATIVE: extra text after endef
166
167run_make_test('
168NAME =
169define NAME =
170ouch
171endef $(NAME)
172all: ; @echo ok
173',
174 '', "#MAKEFILE#:5: extraneous text after 'endef' directive\nok\n");
175
176# TEST 8: NEGATIVE: missing endef
177
178run_make_test('
179NAME =
180all: ; @echo ok
181define NAME =
182ouch
183endef$(NAME)
184',
185 '', "#MAKEFILE#:4: *** missing 'endef', unterminated 'define'. Stop.\n", 512);
186
187# -------------------------
188# Make sure that prefix characters apply properly to define/endef values.
189#
190# There's a bit of oddness here if you try to use a variable to hold the
191# prefix character for a define. Even though something like this:
192#
193# define foo
194# echo bar
195# endef
196#
197# all: ; $(V)$(foo)
198#
199# (where V=@) can be seen by the user to be obviously different than this:
200#
201# define foo
202# $(V)echo bar
203# endef
204#
205# all: ; $(foo)
206#
207# and the user thinks it should behave the same as when the "@" is literal
208# instead of in a variable, that can't happen because by the time make
209# expands the variables for the command line and sees it begins with a "@" it
210# can't know anymore whether the prefix character came before the variable
211# reference or was included in the first line of the variable reference.
212
213# TEST #5
214# -------
215
216run_make_test('
217define FOO
218$(V1)echo hello
219$(V2)echo world
220endef
221all: ; @$(FOO)
222', '', 'hello
223world');
224
225# TEST #6
226# -------
227
228run_make_test(undef, 'V1=@ V2=@', 'hello
229world');
230
231# TEST #7
232# -------
233
234run_make_test('
235define FOO
236$(V1)echo hello
237$(V2)echo world
238endef
239all: ; $(FOO)
240', 'V1=@', 'hello
241echo world
242world');
243
244# TEST #8
245# -------
246
247run_make_test(undef, 'V2=@', 'echo hello
248hello
249world');
250
251# TEST #9
252# -------
253
254run_make_test(undef, 'V1=@ V2=@', 'hello
255world');
256
257# TEST #10
258# -------
259# Test the basics; a "@" internally to the variable applies to only one line.
260# A "@" before the variable applies to the entire variable.
261
262run_make_test('
263define FOO
264@echo hello
265echo world
266endef
267define BAR
268echo hello
269echo world
270endef
271
272all: foo bar
273foo: ; $(FOO)
274bar: ; @$(BAR)
275', '', 'hello
276echo world
277world
278hello
279world
280');
281
2821;
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