Makefile revision 138080
1# $FreeBSD: head/tools/build/make_check/Makefile 138080 2004-11-25 10:03:29Z harti $
2
3# Test for broken LHS expansion.
4# This *must* cause make(1) to detect a recursive variable, and fail as such.
5.if make(lhs_expn)
6FOO=		${BAR}
7BAR${NIL}=	${FOO}
8FOO${BAR}=	${FOO}
9.endif
10
11DATA1=	helllo
12DATA2:=	${DATA1}
13DATA3=	${DATA2:S/ll/rr/g}
14DATA4:=	${DATA2:S/ll/rr/g}
15DATA2?=	allo
16DATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
17DATA2=	yello
18DATA1:=	${DATA5:S/l/r/g}
19NIL=
20
21all:
22	@echo '1..16'
23	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
24		diff -u ${.CURDIR}/regress.variables.out - || ${MAKE} failure
25	@echo "ok 1 - test_variables # Test variables detected no regression, output matches."
26	@${MAKE} double 2>/dev/null || ${MAKE} failure
27	@echo "ok 2 - test_targets # Test targets detected no regression."
28	@${MAKE} sysvmatch || ${MAKE} failure
29	@echo "ok 3 - sysvmatch # Test sysvmatch detected no regression."
30	@! ${MAKE} lhs_expn && true || ${MAKE} failure
31	@echo "ok 4 lhs_expn # Test lhs_expn detected no regression."
32	@${MAKE} notdef || ${MAKE} failure
33	@echo "ok 5 - notdef # Test notdef detected no regression."
34	@${MAKE} modifiers || ${MAKE} failure
35	@echo "ok 6 - modifiers # Test modifiers detected no regression."
36	@${MAKE} funny_targets || ${MAKE} failure
37	@echo "ok 7 funny_targets # Test funny_targets detected no regression."
38	@${MAKE} arith_expr || ${MAKE} failure
39	@echo "ok 8 arith_expr # Test arith_expr detected no regression."
40	@${MAKE} PATH_exists || ${MAKE} failure
41	@echo "ok 9 PATH_exists # Test PATH_exists detected no regression."
42	@${MAKE} double_quotes || ${MAKE} failure
43	@echo "ok 10 double_quotes # Test double_quotes detected no regression."
44	@! ${MAKE} double_quotes2 >/dev/null 2>&1 && true || ${MAKE} failure
45	@echo "ok 11 double_quotes2 # Test double_quotes2 detected no regression."
46	@${MAKE} pass_cmd_vars || ${MAKE} failure
47	@echo "ok 12 pass_cmd_vars # Test pass_cmd_vars detected no regression."
48	@${MAKE} plus_flag || ${MAKE} failure
49	@echo "ok 13 plus_flag # Test plus_flag detected no regression."
50	@! ${MAKE} shell >/dev/null 2>&1 && true || ${MAKE} failure
51	@echo "ok 14 shell # Test shell detected no regression."
52	@${MAKE} shell_1 || ${MAKE} failure
53	@echo "ok 15 shell_1 # Test shell_1 detected no regression."
54	@${MAKE} shell_2 || ${MAKE} failure
55	@echo "ok 16 shell_2 # Test shell_2 detected no regression."
56
57.if make(double)
58# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
59# switches to using the "non-right" one, it breaks things worse than a little
60# regression test.
61double:
62	@true
63
64double:
65	@false
66.endif
67
68.if make(sysvmatch)
69# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
70sysvmatch:
71	@echo EMPTY ${NIL:=foo} LHS | \
72		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
73.endif
74
75# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
76# program has not errored out because of the recursion caused by not expanding
77# the left-hand-side's embedded variables above.
78lhs_expn:
79	@true
80
81.if make(notdef)
82# make(1) claims to only evaluate a conditional as far as is necessary
83# to determine its value; that was not always the case.
84.undef notdef
85notdef:
86.if defined(notdef) && ${notdef:U}
87.endif
88.endif
89
90.if make(modifiers)
91# See if make(1) supports the C modifier.
92modifiers:
93	@if ${MAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
94	    grep -q "Unknown modifier 'C'"; then \
95		false; \
96	fi
97.endif
98
99.if make(funny_targets)
100funny_targets: colons::target exclamation!target
101colons::target:
102exclamation!target: 
103.endif
104
105.if make(arith_expr)
106arith_expr:
107# See if arithmetic expression parsing is broken.
108# The different spacing below is intentional.
109VALUE=	0
110.if (${VALUE} < 0)||(${VALUE}>0)
111.endif
112.endif
113
114.if make(PATH_exists)
115PATH_exists:
116.PATH: ${.CURDIR}
117.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
118.error exists() failed
119.endif
120.endif
121
122.if make(double_quotes)
123VALUE=	foo ""
124double_quotes:
125.if ${VALUE:S/$//} != ${VALUE}
126.error "" reduced to "
127.endif
128.endif
129
130.if make(double_quotes2)
131double_quotes2:
132	@cat /dev/null ""
133.endif
134
135#
136# Check passing of variable via MAKEFLAGS
137#
138.if make(pass_cmd_vars)
139pass_cmd_vars:
140	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
141	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
142	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
143	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
144.endif
145
146.if make(pass_cmd_vars_1)
147# Check that the variable definition arrived from the calling make
148pass_cmd_vars_1:
149	@:
150
151.if ${CMD1} != cmd1 || ${CMD2} != cmd2
152.error variables not passed through MAKEFLAGS
153.endif
154
155# Check that the variable definition is in MAKEFLAGS
156.if ${.MAKEFLAGS:MCMD1=*} != "CMD1=cmd1" || ${.MAKEFLAGS:MCMD2=*} != "CMD2=cmd2"
157.error variable assignment not found in $${MAKEFLAGS}
158.endif
159
160# Check that the variable definition is not in MFLAGS
161.if ${MFLAGS:MCMD1=*} != "" || ${MFLAGS:MCMD2=*} != ""
162.error variable assignment found in $${MFLAGS}
163.endif
164.endif
165
166.if make(pass_cmd_vars_2)
167# Check that we cannot override the passed variables
168CMD1=foo1
169CMD2=foo2
170
171.if ${CMD1} != cmd1 || ${CMD2} != cmd2
172.error MAKEFLAGS-passed variables overridden
173.endif
174
175pass_cmd_vars_2:
176	@:
177.endif
178
179.if make(pass_cmd_vars_3)
180# Check that we can override the passed variables on the next sub-make's
181# command line
182
183pass_cmd_vars_3:
184	@${MAKE} CMD1=foo1 pass_cmd_vars_3_1
185.endif
186
187.if make(pass_cmd_vars_3_1)
188.if ${CMD1} != foo1 || ${CMD2} != cmd2
189.error MAKEFLAGS-passed variables not overridden on command line
190.endif
191pass_cmd_vars_3_1:
192	@:
193.endif
194
195.if make(pass_cmd_vars_4)
196# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
197# by evaluating the .MAKEFLAGS target.
198
199.MAKEFLAGS: CMD1=baz1
200
201pass_cmd_vars_4:
202	@${MAKE} pass_cmd_vars_4_1
203
204.if ${CMD1} != baz1 || ${CMD2} != cmd2
205.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
206.endif
207
208.endif
209.if make(pass_cmd_vars_4_1)
210.if ${CMD1} != baz1 || ${CMD2} != cmd2
211.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
212.endif
213pass_cmd_vars_4_1:
214	@:
215.endif
216
217#
218# Test whether make supports the '+' flag (meaning: execute even with -n)
219#
220.if make(plus_flag)
221OUT != ${MAKE} -n plus_flag_1
222.if ${OUT} != "/tmp"
223.error make doesn't handle + flag
224.endif
225plus_flag:
226	@:
227.endif
228.if make(plus_flag_1)
229plus_flag_1:
230	+@cd /tmp; pwd
231.endif
232
233.if make(shell)
234# Test if make fully supports the .SHELL specification.
235.SHELL: path=/nonexistent
236A!= echo ok
237shell:
238.endif
239
240.if make(shell_1)
241# Test if setting the shell by name only works. Because we have no ksh
242# in the base system we test that we can set sh and csh. We try only exact
243# matching names and do not exercise the rather strange matching algorithm.
244shell_1:
245	@${MAKE} shell_1_csh
246	@${MAKE} shell_1_sh
247.endif
248.if make(shell_1_csh)
249.SHELL: name="csh"
250shell_1_csh:
251	@echo $${shell} | grep -q '^/bin/csh$$'
252.endif
253.if make(shell_1_sh)
254.SHELL: name="sh"
255shell_1_sh:
256	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -q '^/bin/sh$$'
257.endif
258
259.if make(shell_2)
260# Test if we can replace the shell specification. We do this by using
261# a shell scripts that prints us its arguments and standard input as the shell
262shell_2:
263	@${MAKE} -B shell_2B | \
264		diff -u ${.CURDIR}/regress.shell_2B.out - || false
265	@${MAKE} -j1 shell_2j | \
266		diff -u ${.CURDIR}/regress.shell_2j.out - || false
267.endif
268
269.if make(shell_2B)
270.SHELL: name="echo" path="${.CURDIR}/shell_test" quiet="be quiet" echo="be verbose" filter="be verbose" echoFlag="x" errFlag="y" hasErrCtl=y check="check errors" ignore="ignore errors"
271
272shell_2B:
273	-@funny $$
274	funnier $$
275.endif
276
277.if make(shell_2j)
278.SHELL: name="echo" path="${.CURDIR}/shell_test" quiet="be quiet" echo="be verbose" filter="be verbose" echoFlag="x" errFlag="y" hasErrCtl=y check="check errors" ignore="ignore errors"
279
280shell_2j:
281	-@funny $$
282	funnier $$
283.endif
284
285failure:
286	@echo "not ok # Test failed: regression detected.  See above."
287	@false
288