Makefile revision 133593
1169691Skan# $FreeBSD: head/tools/build/make_check/Makefile 133593 2004-08-12 19:14:10Z harti $
2169691Skan
3169691Skan# Test for broken LHS expansion.
4169691Skan# This *must* cause make(1) to detect a recursive variable, and fail as such.
5169691Skan.if make(lhs_expn)
6169691SkanFOO=		${BAR}
7169691SkanBAR${NIL}=	${FOO}
8169691SkanFOO${BAR}=	${FOO}
9169691Skan.endif
10169691Skan
11169691SkanDATA1=	helllo
12169691SkanDATA2:=	${DATA1}
13169691SkanDATA3=	${DATA2:S/ll/rr/g}
14169691SkanDATA4:=	${DATA2:S/ll/rr/g}
15169691SkanDATA2?=	allo
16169691SkanDATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
17169691SkanDATA2=	yello
18169691SkanDATA1:=	${DATA5:S/l/r/g}
19169691SkanNIL=
20169691Skan
21169691Skanall:
22169691Skan	@echo "Running test variables"
23169691Skan	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
24169691Skan		diff -u ${.CURDIR}/regress.variables.out - || ${MAKE} failure
25169691Skan	@echo "PASS: Test variables detected no regression, output matches."
26169691Skan	@echo "Running test targets"
27169691Skan	@${MAKE} double 2>/dev/null || ${MAKE} failure
28169691Skan	@echo "PASS: Test targets detected no regression."
29169691Skan	@echo "Running test sysvmatch"
30169691Skan	@${MAKE} sysvmatch || ${MAKE} failure
31169691Skan	@echo "PASS: Test sysvmatch detected no regression."
32169691Skan	@echo "Running test lhs_expn"
33169691Skan	@! ${MAKE} lhs_expn && true || ${MAKE} failure
34169691Skan	@echo "PASS: Test lhs_expn detected no regression."
35169691Skan	@echo "Running test notdef"
36169691Skan	@${MAKE} notdef || ${MAKE} failure
37169691Skan	@echo "PASS: Test notdef detected no regression."
38169691Skan	@echo "Running test modifiers"
39169691Skan	@${MAKE} modifiers || ${MAKE} failure
40169691Skan	@echo "PASS: Test modifiers detected no regression."
41169691Skan	@echo "Running test funny_targets"
42169691Skan	@${MAKE} funny_targets || ${MAKE} failure
43169691Skan	@echo "PASS: Test funny_targets detected no regression."
44169691Skan	@echo "Running test arith_expr"
45169691Skan	@${MAKE} arith_expr || ${MAKE} failure
46169691Skan	@echo "PASS: Test arith_expr detected no regression."
47169691Skan	@echo "Running test PATH_exists"
48169691Skan	@${MAKE} PATH_exists || ${MAKE} failure
49169691Skan	@echo "PASS: Test PATH_exists detected no regression."
50169691Skan	@echo "Running test double_quotes"
51169691Skan	@${MAKE} double_quotes || ${MAKE} failure
52169691Skan	@echo "PASS: Test double_quotes detected no regression."
53169691Skan	@echo "Running test double_quotes2"
54169691Skan	@! ${MAKE} double_quotes2 >/dev/null 2>&1 && true || ${MAKE} failure
55169691Skan	@echo "PASS: Test double_quotes2 detected no regression."
56169691Skan	@echo "Running test pass_cmd_vars"
57169691Skan	@${MAKE} pass_cmd_vars || ${MAKE} failure
58169691Skan	@echo "PASS: Test pass_cmd_vars detected no regression."
59169691Skan	@echo "Running test plus_flag"
60169691Skan	@${MAKE} plus_flag || ${MAKE} failure
61169691Skan	@echo "PASS: Test plus_flag detected no regression."
62169691Skan
63169691Skan.if make(double)
64169691Skan# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
65169691Skan# switches to using the "non-right" one, it breaks things worse than a little
66169691Skan# regression test.
67169691Skandouble:
68169691Skan	@true
69169691Skan
70169691Skandouble:
71169691Skan	@false
72169691Skan.endif
73169691Skan
74169691Skan.if make(sysvmatch)
75169691Skan# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
76169691Skansysvmatch:
77169691Skan	@echo EMPTY ${NIL:=foo} LHS | \
78169691Skan		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
79169691Skan.endif
80169691Skan
81169691Skan# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
82169691Skan# program has not errored out because of the recursion caused by not expanding
83169691Skan# the left-hand-side's embedded variables above.
84169691Skanlhs_expn:
85169691Skan	@true
86169691Skan
87169691Skan.if make(notdef)
88169691Skan# make(1) claims to only evaluate a conditional as far as is necessary
89169691Skan# to determine its value; that was not always the case.
90169691Skan.undef notdef
91169691Skannotdef:
92169691Skan.if defined(notdef) && ${notdef:U}
93169691Skan.endif
94169691Skan.endif
95169691Skan
96169691Skan.if make(modifiers)
97169691Skan# See if make(1) supports the C modifier.
98169691Skanmodifiers:
99169691Skan	@if ${MAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
100169691Skan	    grep -q "Unknown modifier 'C'"; then \
101169691Skan		false; \
102169691Skan	fi
103169691Skan.endif
104169691Skan
105169691Skan.if make(funny_targets)
106169691Skanfunny_targets: colons::target exclamation!target
107169691Skancolons::target:
108169691Skanexclamation!target: 
109169691Skan.endif
110169691Skan
111169691Skan.if make(arith_expr)
112169691Skanarith_expr:
113169691Skan# See if arithmetic expression parsing is broken.
114169691Skan# The different spacing below is intentional.
115169691SkanVALUE=	0
116169691Skan.if (${VALUE} < 0)||(${VALUE}>0)
117169691Skan.endif
118169691Skan.endif
119169691Skan
120169691Skan.if make(PATH_exists)
121169691SkanPATH_exists:
122169691Skan.PATH: ${.CURDIR}
123169691Skan.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
124169691Skan.error exists() failed
125169691Skan.endif
126169691Skan.endif
127
128.if make(double_quotes)
129VALUE=	foo ""
130double_quotes:
131.if ${VALUE:S/$//} != ${VALUE}
132.error "" reduced to "
133.endif
134.endif
135
136.if make(double_quotes2)
137double_quotes2:
138	@cat /dev/null ""
139.endif
140
141#
142# Check passing of variable via MAKEFLAGS
143#
144.if make(pass_cmd_vars)
145pass_cmd_vars:
146	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
147	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
148	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
149	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
150.endif
151
152.if make(pass_cmd_vars_1)
153# Check that the variable definition arrived from the calling make
154pass_cmd_vars_1:
155	@:
156
157.if ${CMD1} != cmd1 || ${CMD2} != cmd2
158.error variables not passed through MAKEFLAGS
159.endif
160
161# Check that the variable definition is in MAKEFLAGS
162.if ${.MAKEFLAGS:MCMD1=*} != "CMD1=cmd1" || ${.MAKEFLAGS:MCMD2=*} != "CMD2=cmd2"
163.error variable assignment not found in $${MAKEFLAGS}
164.endif
165
166# Check that the variable definition is not in MFLAGS
167.if ${MFLAGS:MCMD1=*} != "" || ${MFLAGS:MCMD2=*} != ""
168.error variable assignment found in $${MFLAGS}
169.endif
170.endif
171
172.if make(pass_cmd_vars_2)
173# Check that we cannot override the passed variables
174CMD1=foo1
175CMD2=foo2
176
177.if ${CMD1} != cmd1 || ${CMD2} != cmd2
178.error MAKEFLAGS-passed variables overridden
179.endif
180
181pass_cmd_vars_2:
182	@:
183.endif
184
185.if make(pass_cmd_vars_3)
186# Check that we can override the passed variables on the next sub-make's
187# command line
188
189pass_cmd_vars_3:
190	@${MAKE} CMD1=foo1 pass_cmd_vars_3_1
191.endif
192
193.if make(pass_cmd_vars_3_1)
194.if ${CMD1} != foo1 || ${CMD2} != cmd2
195.error MAKEFLAGS-passed variables not overridden on command line
196.endif
197pass_cmd_vars_3_1:
198	@:
199.endif
200
201.if make(pass_cmd_vars_4)
202# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
203# by evaluating the .MAKEFLAGS target.
204
205.MAKEFLAGS: CMD1=baz1
206
207pass_cmd_vars_4:
208	@${MAKE} pass_cmd_vars_4_1
209
210.if ${CMD1} != baz1 || ${CMD2} != cmd2
211.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
212.endif
213
214.endif
215.if make(pass_cmd_vars_4_1)
216.if ${CMD1} != baz1 || ${CMD2} != cmd2
217.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
218.endif
219pass_cmd_vars_4_1:
220	@:
221.endif
222
223#
224# Test whether make supports the '+' flag (meaning: execute even with -n)
225#
226.if make(plus_flag)
227OUT != ${MAKE} -n plus_flag_1
228.if ${OUT} != "/tmp"
229.error make doesn't handle + flag
230.endif
231plus_flag:
232	@:
233.endif
234.if make(plus_flag_1)
235plus_flag_1:
236	+@cd /tmp; pwd
237.endif
238
239failure:
240	@echo "FAIL: Test failed: regression detected.  See above."
241	@false
242