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