xref: /freebsd/tools/build/make_check/Makefile (revision 78ae60b447ebf420dd5cebfec30480866fd5cef4)
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
62.if make(C_check)
63C_check:
64.endif
65
66.if make(double)
67# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
68# switches to using the "non-right" one, it breaks things worse than a little
69# regression test.
70double:
71	@true
72
73double:
74	@false
75.endif
76
77.if make(sysvmatch)
78# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
79sysvmatch:
80	@echo EMPTY ${NIL:=foo} LHS | \
81		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
82.endif
83
84# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
85# program has not errored out because of the recursion caused by not expanding
86# the left-hand-side's embedded variables above.
87lhs_expn:
88	@true
89
90.if make(notdef)
91# make(1) claims to only evaluate a conditional as far as is necessary
92# to determine its value; that was not always the case.
93.undef notdef
94notdef:
95.if defined(notdef) && ${notdef:M/}
96.endif
97.endif
98
99.if make(modifiers)
100# check if bmake can expand plain variables
101.MAKE.EXPAND_VARIABLES= yes
102x!= ${SMAKE} -V .CURDIR:H
103modifiers:
104.if ${.CURDIR:H} != "$x"
105	@false
106.endif
107.endif
108
109.if make(arith_expr)
110arith_expr:
111# See if arithmetic expression parsing is broken.
112# The different spacing below is intentional.
113VALUE=	0
114.if (${VALUE} < 0)||(${VALUE}>0)
115.endif
116.endif
117
118.if make(PATH_exists)
119PATH_exists:
120.PATH: ${.CURDIR}
121.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
122.error exists() failed
123.endif
124.endif
125
126.if make(double_quotes)
127VALUE=	foo ""
128double_quotes:
129.if ${VALUE:S/$//} != ${VALUE}
130.error "" reduced to "
131.endif
132.endif
133
134.if make(double_quotes2)
135double_quotes2:
136	@cat /dev/null ""
137.endif
138
139#
140# Check passing of variable via MAKEFLAGS
141#
142.if make(pass_cmd_vars)
143pass_cmd_vars:
144	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
145	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
146	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
147	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
148.endif
149
150#
151# Check that the variable definition arrived from the calling make
152#
153.if make(pass_cmd_vars_1)
154# These values should get overridden by the commandline
155CMD1=oops1
156CMD2=oops2
157pass_cmd_vars_1:
158	@:
159
160.if ${CMD1} != cmd1 || ${CMD2} != cmd2
161.error variables not passed through MAKEFLAGS
162.endif
163.endif
164
165.if make(pass_cmd_vars_2)
166# Check that we cannot override the passed variables
167CMD1=foo1
168CMD2=foo2
169
170.if ${CMD1} != cmd1 || ${CMD2} != cmd2
171.error MAKEFLAGS-passed variables overridden
172.endif
173
174pass_cmd_vars_2:
175	@:
176.endif
177
178.if make(pass_cmd_vars_3)
179# Check that we can override the passed variables on the next sub-make's
180# command line
181
182pass_cmd_vars_3:
183	@${SMAKE} CMD1=foo1 pass_cmd_vars_3_1
184.endif
185
186.if make(pass_cmd_vars_3_1)
187.if ${CMD1} != foo1 || ${CMD2} != cmd2
188.error MAKEFLAGS-passed variables not overridden on command line
189.endif
190pass_cmd_vars_3_1:
191	@:
192.endif
193
194.if make(pass_cmd_vars_4)
195# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
196# by evaluating the .MAKEFLAGS target.
197
198.MAKEFLAGS: CMD1=baz1
199
200pass_cmd_vars_4:
201	@${SMAKE} pass_cmd_vars_4_1
202
203.if ${CMD1} != baz1 || ${CMD2} != cmd2
204.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
205.endif
206
207.endif
208.if make(pass_cmd_vars_4_1)
209.if ${CMD1} != baz1 || ${CMD2} != cmd2
210.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
211.endif
212pass_cmd_vars_4_1:
213	@:
214.endif
215
216#
217# Test whether make supports the '+' flag (meaning: execute even with -n)
218#
219.if make(plus_flag)
220OUT != ${SMAKE} -n plus_flag_1
221.if ${OUT:M/tmp} != "/tmp"
222.error make doesn't handle + flag
223.endif
224plus_flag:
225	@:
226.endif
227.if make(plus_flag_1)
228plus_flag_1:
229	+@cd /tmp; pwd
230.endif
231
232.if make(shell)
233# Test if make fully supports the .SHELL specification.
234.SHELL: path=/nonexistent
235A!= echo ok
236shell:
237.endif
238
239.if make(shell_1)
240# Test if setting the shell by name only works. Because we have no ksh
241# in the base system we test that we can set sh and csh. We try only exact
242# matching names and do not exercise the rather strange matching algorithm.
243shell_1:
244	@${SMAKE} shell_1_csh
245	@${SMAKE} shell_1_sh
246.endif
247.if make(shell_1_csh)
248.SHELL: name="csh"
249shell_1_csh:
250	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?csh$$'
251.endif
252.if make(shell_1_sh)
253.SHELL: name="sh"
254shell_1_sh:
255	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?sh$$'
256.endif
257
258.if make(shell_2)
259# Test if we can replace the shell specification. We do this by using
260# a shell scripts that prints us its arguments and standard input as the shell
261shell_2: shell_test
262	@${SMAKE} -B shell_2B | \
263		diff -u ${.CURDIR}/regress.shell_2B.out - || false
264	@${SMAKE} -j1 shell_2j | \
265		diff -u ${.CURDIR}/regress.shell_2j.out - || false
266.endif
267
268.if make(shell_2B)
269.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"
270
271shell_2B:
272	-@funny $$
273	funnier $$
274.endif
275
276.if make(shell_2j)
277.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"
278
279shell_2j:
280	-@funny $$
281	funnier $$
282.endif
283
284failure:
285	@echo "not ok # Test failed: regression detected.  See above."
286	@false
287
288CLEANFILES= shell_test
289
290.include <bsd.obj.mk>
291