195158Sjmallett# $FreeBSD$
295158Sjmallett
3222295Sobrien.MAKE.MODE=	normal
4222295Sobrien
598442Sjmallett# Test for broken LHS expansion.
6107374Sru# This *must* cause make(1) to detect a recursive variable, and fail as such.
798442Sjmallett.if make(lhs_expn)
898442SjmallettFOO=		${BAR}
998442SjmallettBAR${NIL}=	${FOO}
1098442SjmallettFOO${BAR}=	${FOO}
1198442Sjmallett.endif
1298442Sjmallett
1395158SjmallettDATA1=	helllo
1495158SjmallettDATA2:=	${DATA1}
1595158SjmallettDATA3=	${DATA2:S/ll/rr/g}
1695158SjmallettDATA4:=	${DATA2:S/ll/rr/g}
1795158SjmallettDATA2?=	allo
1895158SjmallettDATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
1995158SjmallettDATA2=	yello
2095158SjmallettDATA1:=	${DATA5:S/l/r/g}
2196070SjmallettNIL=
2295158Sjmallett
23138432SruSMAKE=	MAKEFLAGS= ${MAKE} -C ${.CURDIR}
24138317Sharti
2595158Sjmallettall:
26138317Sharti	@echo '1..17'
27138317Sharti	@${SMAKE} C_check || { cd ${.CURDIR} ; ${MAKE} failure ; }
28138317Sharti	@echo "ok 1 - C_check # Test of -C flag existence detected no regression."
2995158Sjmallett	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
30138317Sharti		diff -u ${.CURDIR}/regress.variables.out - || \
31138317Sharti		${SMAKE} failure
32138317Sharti	@echo "ok 2 - test_variables # Test variables detected no regression, output matches."
33138317Sharti	@${SMAKE} double 2>/dev/null || ${SMAKE} failure
34138317Sharti	@echo "ok 3 - test_targets # Test targets detected no regression."
35138317Sharti	@${SMAKE} sysvmatch || ${SMAKE} failure
36138317Sharti	@echo "ok 4 - sysvmatch # Test sysvmatch detected no regression."
37138317Sharti	@! ${SMAKE} lhs_expn && true || ${SMAKE} failure
38138317Sharti	@echo "ok 5 lhs_expn # Test lhs_expn detected no regression."
39138317Sharti	@${SMAKE} notdef || ${SMAKE} failure
40138317Sharti	@echo "ok 6 - notdef # Test notdef detected no regression."
41138317Sharti	@${SMAKE} modifiers || ${SMAKE} failure
42138317Sharti	@echo "ok 7 - modifiers # Test modifiers detected no regression."
43138317Sharti	@${SMAKE} funny_targets || ${SMAKE} failure
44138317Sharti	@echo "ok 8 funny_targets # Test funny_targets detected no regression."
45138317Sharti	@${SMAKE} arith_expr || ${SMAKE} failure
46138317Sharti	@echo "ok 9 arith_expr # Test arith_expr detected no regression."
47138317Sharti	@${SMAKE} PATH_exists || ${SMAKE} failure
48138317Sharti	@echo "ok 10 PATH_exists # Test PATH_exists detected no regression."
49138317Sharti	@${SMAKE} double_quotes || ${SMAKE} failure
50138317Sharti	@echo "ok 11 double_quotes # Test double_quotes detected no regression."
51138317Sharti	@! ${SMAKE} double_quotes2 >/dev/null 2>&1 && true || ${SMAKE} failure
52138317Sharti	@echo "ok 12 double_quotes2 # Test double_quotes2 detected no regression."
53138317Sharti	@${SMAKE} pass_cmd_vars || ${SMAKE} failure
54138317Sharti	@echo "ok 13 pass_cmd_vars # Test pass_cmd_vars detected no regression."
55138317Sharti	@${SMAKE} plus_flag || ${SMAKE} failure
56138317Sharti	@echo "ok 14 plus_flag # Test plus_flag detected no regression."
57138317Sharti	@! ${SMAKE} shell >/dev/null 2>&1 && true || ${SMAKE} failure
58138317Sharti	@echo "ok 15 shell # Test shell detected no regression."
59138317Sharti	@${SMAKE} shell_1 || ${SMAKE} failure
60138317Sharti	@echo "ok 16 shell_1 # Test shell_1 detected no regression."
61138317Sharti	@${SMAKE} shell_2 || ${SMAKE} failure
62138317Sharti	@echo "ok 17 shell_2 # Test shell_2 detected no regression."
6395158Sjmallett
64138317Sharti.if make(C_check)
65138317ShartiC_check:
66138317Sharti.endif
67138317Sharti
68105907Sjmallett.if make(double)
69100794Sjmallett# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
70100794Sjmallett# switches to using the "non-right" one, it breaks things worse than a little
71100794Sjmallett# regression test.
7295167Sjmallettdouble:
7395167Sjmallett	@true
7495167Sjmallett
7595167Sjmallettdouble:
7695167Sjmallett	@false
77105907Sjmallett.endif
7895167Sjmallett
79105907Sjmallett.if make(sysvmatch)
8096070Sjmallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
8196070Sjmallettsysvmatch:
8296070Sjmallett	@echo EMPTY ${NIL:=foo} LHS | \
8396070Sjmallett		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
84105907Sjmallett.endif
8596070Sjmallett
8698442Sjmallett# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
8798442Sjmallett# program has not errored out because of the recursion caused by not expanding
8898442Sjmallett# the left-hand-side's embedded variables above.
8998442Sjmallettlhs_expn:
9098461Sjmallett	@true
9198442Sjmallett
92107374Sru.if make(notdef)
93107374Sru# make(1) claims to only evaluate a conditional as far as is necessary
94107374Sru# to determine its value; that was not always the case.
95107374Sru.undef notdef
96107374Srunotdef:
97107374Sru.if defined(notdef) && ${notdef:U}
98107374Sru.endif
99107374Sru.endif
100107374Sru
101107374Sru.if make(modifiers)
102107374Sru# See if make(1) supports the C modifier.
103107374Srumodifiers:
104138317Sharti	@if ${SMAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
105107374Sru	    grep -q "Unknown modifier 'C'"; then \
106107374Sru		false; \
107107374Sru	fi
108107374Sru.endif
109107374Sru
110107375Sru.if make(funny_targets)
111107375Srufunny_targets: colons::target exclamation!target
112107375Srucolons::target:
113107375Sruexclamation!target: 
114107375Sru.endif
115107375Sru
116117226Sru.if make(arith_expr)
117117226Sruarith_expr:
118117226Sru# See if arithmetic expression parsing is broken.
119117226Sru# The different spacing below is intentional.
120117226SruVALUE=	0
121117226Sru.if (${VALUE} < 0)||(${VALUE}>0)
122117226Sru.endif
123117226Sru.endif
124117226Sru
125120676Sru.if make(PATH_exists)
126120676SruPATH_exists:
127120676Sru.PATH: ${.CURDIR}
128120676Sru.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
129120676Sru.error exists() failed
130120676Sru.endif
131120676Sru.endif
132120676Sru
133125219Sru.if make(double_quotes)
134125219SruVALUE=	foo ""
135125219Srudouble_quotes:
136125219Sru.if ${VALUE:S/$//} != ${VALUE}
137125219Sru.error "" reduced to "
138125219Sru.endif
139125219Sru.endif
140125219Sru
141125227Sru.if make(double_quotes2)
142125227Srudouble_quotes2:
143125227Sru	@cat /dev/null ""
144125227Sru.endif
145125227Sru
146133109Sharti#
147133109Sharti# Check passing of variable via MAKEFLAGS
148133109Sharti#
149133109Sharti.if make(pass_cmd_vars)
150133109Shartipass_cmd_vars:
151138317Sharti	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
152138317Sharti	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
153138317Sharti	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
154138317Sharti	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
155133109Sharti.endif
156133109Sharti
157222295Sobrien#
158222295Sobrien# Check that the variable definition arrived from the calling make
159222295Sobrien#
160133109Sharti.if make(pass_cmd_vars_1)
161222295Sobrien# These values should get overridden by the commandline
162222295SobrienCMD1=oops1
163222295SobrienCMD2=oops2
164133109Shartipass_cmd_vars_1:
165133109Sharti	@:
166133109Sharti
167133109Sharti.if ${CMD1} != cmd1 || ${CMD2} != cmd2
168133164Sharti.error variables not passed through MAKEFLAGS
169133109Sharti.endif
170133109Sharti.endif
171133109Sharti
172133109Sharti.if make(pass_cmd_vars_2)
173133109Sharti# Check that we cannot override the passed variables
174133109ShartiCMD1=foo1
175133109ShartiCMD2=foo2
176133109Sharti
177133109Sharti.if ${CMD1} != cmd1 || ${CMD2} != cmd2
178133164Sharti.error MAKEFLAGS-passed variables overridden
179133109Sharti.endif
180133109Sharti
181133109Shartipass_cmd_vars_2:
182133109Sharti	@:
183133109Sharti.endif
184133109Sharti
185133109Sharti.if make(pass_cmd_vars_3)
186133109Sharti# Check that we can override the passed variables on the next sub-make's
187133109Sharti# command line
188133109Sharti
189133109Shartipass_cmd_vars_3:
190138317Sharti	@${SMAKE} CMD1=foo1 pass_cmd_vars_3_1
191133109Sharti.endif
192133109Sharti
193133109Sharti.if make(pass_cmd_vars_3_1)
194133109Sharti.if ${CMD1} != foo1 || ${CMD2} != cmd2
195133164Sharti.error MAKEFLAGS-passed variables not overridden on command line
196133109Sharti.endif
197133109Shartipass_cmd_vars_3_1:
198133109Sharti	@:
199133109Sharti.endif
200133109Sharti
201133109Sharti.if make(pass_cmd_vars_4)
202133109Sharti# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
203133109Sharti# by evaluating the .MAKEFLAGS target.
204133109Sharti
205133109Sharti.MAKEFLAGS: CMD1=baz1
206133109Sharti
207133109Shartipass_cmd_vars_4:
208138317Sharti	@${SMAKE} pass_cmd_vars_4_1
209133109Sharti
210133109Sharti.if ${CMD1} != baz1 || ${CMD2} != cmd2
211133164Sharti.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
212133109Sharti.endif
213133109Sharti
214133109Sharti.endif
215133109Sharti.if make(pass_cmd_vars_4_1)
216133109Sharti.if ${CMD1} != baz1 || ${CMD2} != cmd2
217133164Sharti.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
218133109Sharti.endif
219133109Shartipass_cmd_vars_4_1:
220133109Sharti	@:
221133109Sharti.endif
222133109Sharti
223133161Sharti#
224133161Sharti# Test whether make supports the '+' flag (meaning: execute even with -n)
225133161Sharti#
226133161Sharti.if make(plus_flag)
227138317ShartiOUT != ${SMAKE} -n plus_flag_1
228222295Sobrien.if ${OUT:M/tmp} != "/tmp"
229133164Sharti.error make doesn't handle + flag
230133161Sharti.endif
231133161Shartiplus_flag:
232133161Sharti	@:
233133161Sharti.endif
234133161Sharti.if make(plus_flag_1)
235133161Shartiplus_flag_1:
236133161Sharti	+@cd /tmp; pwd
237133161Sharti.endif
238133161Sharti
239136842Sru.if make(shell)
240136842Sru# Test if make fully supports the .SHELL specification.
241136842Sru.SHELL: path=/nonexistent
242136842SruA!= echo ok
243136842Srushell:
244136842Sru.endif
245136842Sru
246138080Sharti.if make(shell_1)
247138080Sharti# Test if setting the shell by name only works. Because we have no ksh
248138080Sharti# in the base system we test that we can set sh and csh. We try only exact
249138080Sharti# matching names and do not exercise the rather strange matching algorithm.
250138080Shartishell_1:
251138317Sharti	@${SMAKE} shell_1_csh
252138317Sharti	@${SMAKE} shell_1_sh
253138080Sharti.endif
254138080Sharti.if make(shell_1_csh)
255138080Sharti.SHELL: name="csh"
256138080Shartishell_1_csh:
257138317Sharti	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?csh$$'
258138080Sharti.endif
259138080Sharti.if make(shell_1_sh)
260138080Sharti.SHELL: name="sh"
261138080Shartishell_1_sh:
262172399Sru	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?sh$$'
263138080Sharti.endif
264138080Sharti
265138080Sharti.if make(shell_2)
266138080Sharti# Test if we can replace the shell specification. We do this by using
267138080Sharti# a shell scripts that prints us its arguments and standard input as the shell
268138515Shartishell_2: shell_test
269138317Sharti	@${SMAKE} -B shell_2B | \
270138080Sharti		diff -u ${.CURDIR}/regress.shell_2B.out - || false
271138317Sharti	@${SMAKE} -j1 shell_2j | \
272138080Sharti		diff -u ${.CURDIR}/regress.shell_2j.out - || false
273138080Sharti.endif
274138080Sharti
275138080Sharti.if make(shell_2B)
276138317Sharti.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"
277138080Sharti
278138080Shartishell_2B:
279138080Sharti	-@funny $$
280138080Sharti	funnier $$
281138080Sharti.endif
282138080Sharti
283138080Sharti.if make(shell_2j)
284138317Sharti.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"
285138080Sharti
286138080Shartishell_2j:
287138080Sharti	-@funny $$
288138080Sharti	funnier $$
289138080Sharti.endif
290138080Sharti
29195158Sjmallettfailure:
292137587Snik	@echo "not ok # Test failed: regression detected.  See above."
29395158Sjmallett	@false
294138317Sharti
295138515ShartiCLEANFILES= shell_test
296138515Sharti
297138515Sharti.include <bsd.obj.mk>
298