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