Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / variables / flavors
1 #                                                                    -*-perl-*-
2
3 $description = "Test various flavors of make variable setting.";
4
5 $details = "";
6
7 # TEST 0: Recursive
8
9 run_make_test('
10 ugh = Goodbye
11 foo = $(bar)
12 bar = ${ugh}
13 ugh = Hello
14 all: ; @echo $(foo)
15 ',
16               '', "Hello\n");
17
18 # TEST 1: Simple
19
20 run_make_test('
21 bar = Goodbye
22 foo := $(bar)
23 bar = ${ugh}
24 ugh = Hello
25 all: ; @echo $(foo)
26 ',
27               '', "Goodbye\n");
28
29 # TEST 2: Append to recursive
30
31 run_make_test('
32 foo = Hello
33 ugh = Goodbye
34 foo += $(bar)
35 bar = ${ugh}
36 ugh = Hello
37 all: ; @echo $(foo)
38 ',
39               '', "Hello Hello\n");
40
41 # TEST 3: Append to simple
42
43 run_make_test('
44 foo := Hello
45 ugh = Goodbye
46 bar = ${ugh}
47 foo += $(bar)
48 ugh = Hello
49 all: ; @echo $(foo)
50 ',
51               '', "Hello Goodbye\n");
52
53 # TEST 4: Conditional pre-set
54
55 run_make_test('
56 foo = Hello
57 ugh = Goodbye
58 bar = ${ugh}
59 foo ?= $(bar)
60 ugh = Hello
61 all: ; @echo $(foo)
62 ',
63               '', "Hello\n");
64
65 # TEST 5: Conditional unset
66
67 run_make_test('
68 ugh = Goodbye
69 bar = ${ugh}
70 foo ?= $(bar)
71 ugh = Hello
72 all: ; @echo $(foo)
73 ',
74               '', "Hello\n");
75
76 # TEST 6: Simple using POSIX syntax
77 run_make_test('
78 bar = Goodbye
79 foo ::= $(bar)
80 bar = ${ugh}
81 ugh = Hello
82 all: ; @echo $(foo)
83 ',
84               '', "Goodbye\n");
85
86 # TEST 7: POSIX syntax no spaces
87 run_make_test('
88 bar = Goodbye
89 foo::=$(bar)
90 bar = ${ugh}
91 ugh = Hello
92 all: ; @echo $(foo)
93 ',
94               '', "Goodbye\n");
95
96 # TEST 8: Append to empty
97 run_make_test(q!
98 recur =
99 recur += foo
100 simple :=
101 simple += bar
102 recur_empty = foo
103 recur_empty +=
104 simple_empty := bar
105 simple_empty +=
106 empty_recur =
107 empty_recur +=
108 empty_simple :=
109 empty_simple +=
110
111 all: ; @: $(info recur=/$(recur)/ simple=/$(simple)/ recure=/$(recur_empty)/ simplee=/$(simple_empty)/ erecur=/$(empty_recur)/ esimple=/$(empty_simple)/)
112 !,
113               '', "recur=/foo/ simple=/bar/ recure=/foo/ simplee=/bar/ erecur=// esimple=//\n");
114
115 # TEST 9: Line continuation
116 run_make_test(q!
117 recur = $\
118   one$\
119   two$\
120   three
121 simple := $\
122   four$\
123   five$\
124   six
125
126 all: d$\
127      e$\
128      p; @:
129
130 .PHONY: dep
131 dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/)
132 !,
133              '', "recur=/onetwothree/ simple=/fourfivesix/\n");
134
135 # TEST 9: Line continuation
136 run_make_test(q!
137 .POSIX:
138 recur = $\
139   one$\
140   two$\
141   three
142 simple := $\
143   four$\
144   five$\
145   six
146
147 all: d$\
148      e$\
149      p; @:
150
151 .PHONY: dep
152 dep: ; @: $(info recur=/$(recur)/ simple=/$(simple)/)
153 !,
154              '', "recur=/onetwothree/ simple=/fourfivesix/\n");
155
156 # Test POSIX :::=
157 # This creates a recursive variable, but it expands the RHS first.  Any
158 # variable escapes ('$$') are preserved so that this recursive variable can be
159 # expanded again without changing its contents.
160 run_make_test('
161 bar = Goodbye
162 foo :::= $(bar)
163 bar = ${ugh}
164 ugh = Hello
165 all: ; @echo $(foo)
166 ',
167               '', "Goodbye");
168
169 # POSIX :::= no spaces
170 run_make_test(q!
171 bar = Goodbye
172 foo:::=$(bar)
173 bar = ${ugh}
174 ugh = Hello
175 all: ; @echo $(foo)
176 !,
177               '', "Goodbye");
178
179 # Variable escapes ('$$') are preserved.
180 run_make_test(q!
181 bar = Good$$bye
182 foo :::= $(bar) $$what
183 bar = ${ugh}
184 ugh = Hello
185 all: ; @echo '$(foo)'
186 !,
187               '', 'Good$bye $what');
188
189 # Append works as expected
190 run_make_test(q!
191 bar = Good$$bye
192 foo :::= $(bar)
193 foo += $$what $(bar)
194 bar = ${ugh}
195 ugh = Hello
196 all: ; @echo '$(foo)'
197 !,
198               '', 'Good$bye $what Hello');
199
200 1;