xref: /freebsd/tools/build/make_check/Makefile (revision 9c1f3ca3cf68bb399259bab53f75589dd3b6ea17)
16541d27cSJuli Mallett# $FreeBSD$
26541d27cSJuli Mallett
30aa9e01cSJuli Mallett# Test for broken LHS expansion.
4113cf9e6SRuslan Ermilov# This *must* cause make(1) to detect a recursive variable, and fail as such.
50aa9e01cSJuli Mallett.if make(lhs_expn)
60aa9e01cSJuli MallettFOO=		${BAR}
70aa9e01cSJuli MallettBAR${NIL}=	${FOO}
80aa9e01cSJuli MallettFOO${BAR}=	${FOO}
90aa9e01cSJuli Mallett.endif
100aa9e01cSJuli Mallett
116541d27cSJuli MallettDATA1=	helllo
126541d27cSJuli MallettDATA2:=	${DATA1}
136541d27cSJuli MallettDATA3=	${DATA2:S/ll/rr/g}
146541d27cSJuli MallettDATA4:=	${DATA2:S/ll/rr/g}
156541d27cSJuli MallettDATA2?=	allo
166541d27cSJuli MallettDATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
176541d27cSJuli MallettDATA2=	yello
186541d27cSJuli MallettDATA1:=	${DATA5:S/l/r/g}
19a9b736adSJuli MallettNIL=
206541d27cSJuli Mallett
219c1f3ca3SHartmut BrandtSMAKE=	${MAKE} -C ${.CURDIR}
229c1f3ca3SHartmut Brandt
236541d27cSJuli Mallettall:
249c1f3ca3SHartmut Brandt	@if [ ! -x ./shell_test ] ; then \
259c1f3ca3SHartmut Brandt		${INSTALL} -m 555 ${.CURDIR}/shell_test.sh shell_test ; \
269c1f3ca3SHartmut Brandt	fi
279c1f3ca3SHartmut Brandt	@echo '1..17'
289c1f3ca3SHartmut Brandt	@${SMAKE} C_check || { cd ${.CURDIR} ; ${MAKE} failure ; }
299c1f3ca3SHartmut Brandt	@echo "ok 1 - C_check # Test of -C flag existence detected no regression."
306541d27cSJuli Mallett	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
319c1f3ca3SHartmut Brandt		diff -u ${.CURDIR}/regress.variables.out - || \
329c1f3ca3SHartmut Brandt		${SMAKE} failure
339c1f3ca3SHartmut Brandt	@echo "ok 2 - test_variables # Test variables detected no regression, output matches."
349c1f3ca3SHartmut Brandt	@${SMAKE} double 2>/dev/null || ${SMAKE} failure
359c1f3ca3SHartmut Brandt	@echo "ok 3 - test_targets # Test targets detected no regression."
369c1f3ca3SHartmut Brandt	@${SMAKE} sysvmatch || ${SMAKE} failure
379c1f3ca3SHartmut Brandt	@echo "ok 4 - sysvmatch # Test sysvmatch detected no regression."
389c1f3ca3SHartmut Brandt	@! ${SMAKE} lhs_expn && true || ${SMAKE} failure
399c1f3ca3SHartmut Brandt	@echo "ok 5 lhs_expn # Test lhs_expn detected no regression."
409c1f3ca3SHartmut Brandt	@${SMAKE} notdef || ${SMAKE} failure
419c1f3ca3SHartmut Brandt	@echo "ok 6 - notdef # Test notdef detected no regression."
429c1f3ca3SHartmut Brandt	@${SMAKE} modifiers || ${SMAKE} failure
439c1f3ca3SHartmut Brandt	@echo "ok 7 - modifiers # Test modifiers detected no regression."
449c1f3ca3SHartmut Brandt	@${SMAKE} funny_targets || ${SMAKE} failure
459c1f3ca3SHartmut Brandt	@echo "ok 8 funny_targets # Test funny_targets detected no regression."
469c1f3ca3SHartmut Brandt	@${SMAKE} arith_expr || ${SMAKE} failure
479c1f3ca3SHartmut Brandt	@echo "ok 9 arith_expr # Test arith_expr detected no regression."
489c1f3ca3SHartmut Brandt	@${SMAKE} PATH_exists || ${SMAKE} failure
499c1f3ca3SHartmut Brandt	@echo "ok 10 PATH_exists # Test PATH_exists detected no regression."
509c1f3ca3SHartmut Brandt	@${SMAKE} double_quotes || ${SMAKE} failure
519c1f3ca3SHartmut Brandt	@echo "ok 11 double_quotes # Test double_quotes detected no regression."
529c1f3ca3SHartmut Brandt	@! ${SMAKE} double_quotes2 >/dev/null 2>&1 && true || ${SMAKE} failure
539c1f3ca3SHartmut Brandt	@echo "ok 12 double_quotes2 # Test double_quotes2 detected no regression."
549c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars || ${SMAKE} failure
559c1f3ca3SHartmut Brandt	@echo "ok 13 pass_cmd_vars # Test pass_cmd_vars detected no regression."
569c1f3ca3SHartmut Brandt	@${SMAKE} plus_flag || ${SMAKE} failure
579c1f3ca3SHartmut Brandt	@echo "ok 14 plus_flag # Test plus_flag detected no regression."
589c1f3ca3SHartmut Brandt	@! ${SMAKE} shell >/dev/null 2>&1 && true || ${SMAKE} failure
599c1f3ca3SHartmut Brandt	@echo "ok 15 shell # Test shell detected no regression."
609c1f3ca3SHartmut Brandt	@${SMAKE} shell_1 || ${SMAKE} failure
619c1f3ca3SHartmut Brandt	@echo "ok 16 shell_1 # Test shell_1 detected no regression."
629c1f3ca3SHartmut Brandt	@${SMAKE} shell_2 || ${SMAKE} failure
639c1f3ca3SHartmut Brandt	@echo "ok 17 shell_2 # Test shell_2 detected no regression."
649c1f3ca3SHartmut Brandt
659c1f3ca3SHartmut Brandt.if make(C_check)
669c1f3ca3SHartmut BrandtC_check:
679c1f3ca3SHartmut Brandt.endif
686d3ca9deSJuli Mallett
695661d4a7SJuli Mallett.if make(double)
7089d22e2fSJuli Mallett# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
7189d22e2fSJuli Mallett# switches to using the "non-right" one, it breaks things worse than a little
7289d22e2fSJuli Mallett# regression test.
736d3ca9deSJuli Mallettdouble:
746d3ca9deSJuli Mallett	@true
756d3ca9deSJuli Mallett
766d3ca9deSJuli Mallettdouble:
776d3ca9deSJuli Mallett	@false
785661d4a7SJuli Mallett.endif
796541d27cSJuli Mallett
805661d4a7SJuli Mallett.if make(sysvmatch)
81a9b736adSJuli Mallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
82a9b736adSJuli Mallettsysvmatch:
83a9b736adSJuli Mallett	@echo EMPTY ${NIL:=foo} LHS | \
84a9b736adSJuli Mallett		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
855661d4a7SJuli Mallett.endif
86a9b736adSJuli Mallett
870aa9e01cSJuli Mallett# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
880aa9e01cSJuli Mallett# program has not errored out because of the recursion caused by not expanding
890aa9e01cSJuli Mallett# the left-hand-side's embedded variables above.
900aa9e01cSJuli Mallettlhs_expn:
916d5fda5fSJuli Mallett	@true
920aa9e01cSJuli Mallett
93113cf9e6SRuslan Ermilov.if make(notdef)
94113cf9e6SRuslan Ermilov# make(1) claims to only evaluate a conditional as far as is necessary
95113cf9e6SRuslan Ermilov# to determine its value; that was not always the case.
96113cf9e6SRuslan Ermilov.undef notdef
97113cf9e6SRuslan Ermilovnotdef:
98113cf9e6SRuslan Ermilov.if defined(notdef) && ${notdef:U}
99113cf9e6SRuslan Ermilov.endif
100113cf9e6SRuslan Ermilov.endif
101113cf9e6SRuslan Ermilov
102113cf9e6SRuslan Ermilov.if make(modifiers)
103113cf9e6SRuslan Ermilov# See if make(1) supports the C modifier.
104113cf9e6SRuslan Ermilovmodifiers:
1059c1f3ca3SHartmut Brandt	@if ${SMAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
106113cf9e6SRuslan Ermilov	    grep -q "Unknown modifier 'C'"; then \
107113cf9e6SRuslan Ermilov		false; \
108113cf9e6SRuslan Ermilov	fi
109113cf9e6SRuslan Ermilov.endif
110113cf9e6SRuslan Ermilov
111be8b43b4SRuslan Ermilov.if make(funny_targets)
112be8b43b4SRuslan Ermilovfunny_targets: colons::target exclamation!target
113be8b43b4SRuslan Ermilovcolons::target:
114be8b43b4SRuslan Ermilovexclamation!target:
115be8b43b4SRuslan Ermilov.endif
116be8b43b4SRuslan Ermilov
117c94d7043SRuslan Ermilov.if make(arith_expr)
118c94d7043SRuslan Ermilovarith_expr:
119c94d7043SRuslan Ermilov# See if arithmetic expression parsing is broken.
120c94d7043SRuslan Ermilov# The different spacing below is intentional.
121c94d7043SRuslan ErmilovVALUE=	0
122c94d7043SRuslan Ermilov.if (${VALUE} < 0)||(${VALUE}>0)
123c94d7043SRuslan Ermilov.endif
124c94d7043SRuslan Ermilov.endif
125c94d7043SRuslan Ermilov
12621159d16SRuslan Ermilov.if make(PATH_exists)
12721159d16SRuslan ErmilovPATH_exists:
12821159d16SRuslan Ermilov.PATH: ${.CURDIR}
12921159d16SRuslan Ermilov.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
13021159d16SRuslan Ermilov.error exists() failed
13121159d16SRuslan Ermilov.endif
13221159d16SRuslan Ermilov.endif
13321159d16SRuslan Ermilov
1349608d7e2SRuslan Ermilov.if make(double_quotes)
1359608d7e2SRuslan ErmilovVALUE=	foo ""
1369608d7e2SRuslan Ermilovdouble_quotes:
1379608d7e2SRuslan Ermilov.if ${VALUE:S/$//} != ${VALUE}
1389608d7e2SRuslan Ermilov.error "" reduced to "
1399608d7e2SRuslan Ermilov.endif
1409608d7e2SRuslan Ermilov.endif
1419608d7e2SRuslan Ermilov
14299d3652eSRuslan Ermilov.if make(double_quotes2)
14399d3652eSRuslan Ermilovdouble_quotes2:
14499d3652eSRuslan Ermilov	@cat /dev/null ""
14599d3652eSRuslan Ermilov.endif
14699d3652eSRuslan Ermilov
14748ec21e7SHartmut Brandt#
14848ec21e7SHartmut Brandt# Check passing of variable via MAKEFLAGS
14948ec21e7SHartmut Brandt#
15048ec21e7SHartmut Brandt.if make(pass_cmd_vars)
15148ec21e7SHartmut Brandtpass_cmd_vars:
1529c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
1539c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
1549c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
1559c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
15648ec21e7SHartmut Brandt.endif
15748ec21e7SHartmut Brandt
15848ec21e7SHartmut Brandt.if make(pass_cmd_vars_1)
15948ec21e7SHartmut Brandt# Check that the variable definition arrived from the calling make
16048ec21e7SHartmut Brandtpass_cmd_vars_1:
16148ec21e7SHartmut Brandt	@:
16248ec21e7SHartmut Brandt
16348ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
16482eb7072SHartmut Brandt.error variables not passed through MAKEFLAGS
16548ec21e7SHartmut Brandt.endif
16648ec21e7SHartmut Brandt
16748ec21e7SHartmut Brandt# Check that the variable definition is in MAKEFLAGS
16848ec21e7SHartmut Brandt.if ${.MAKEFLAGS:MCMD1=*} != "CMD1=cmd1" || ${.MAKEFLAGS:MCMD2=*} != "CMD2=cmd2"
16982eb7072SHartmut Brandt.error variable assignment not found in $${MAKEFLAGS}
17048ec21e7SHartmut Brandt.endif
17148ec21e7SHartmut Brandt
17248ec21e7SHartmut Brandt# Check that the variable definition is not in MFLAGS
17348ec21e7SHartmut Brandt.if ${MFLAGS:MCMD1=*} != "" || ${MFLAGS:MCMD2=*} != ""
17482eb7072SHartmut Brandt.error variable assignment found in $${MFLAGS}
17548ec21e7SHartmut Brandt.endif
17648ec21e7SHartmut Brandt.endif
17748ec21e7SHartmut Brandt
17848ec21e7SHartmut Brandt.if make(pass_cmd_vars_2)
17948ec21e7SHartmut Brandt# Check that we cannot override the passed variables
18048ec21e7SHartmut BrandtCMD1=foo1
18148ec21e7SHartmut BrandtCMD2=foo2
18248ec21e7SHartmut Brandt
18348ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
18482eb7072SHartmut Brandt.error MAKEFLAGS-passed variables overridden
18548ec21e7SHartmut Brandt.endif
18648ec21e7SHartmut Brandt
18748ec21e7SHartmut Brandtpass_cmd_vars_2:
18848ec21e7SHartmut Brandt	@:
18948ec21e7SHartmut Brandt.endif
19048ec21e7SHartmut Brandt
19148ec21e7SHartmut Brandt.if make(pass_cmd_vars_3)
19248ec21e7SHartmut Brandt# Check that we can override the passed variables on the next sub-make's
19348ec21e7SHartmut Brandt# command line
19448ec21e7SHartmut Brandt
19548ec21e7SHartmut Brandtpass_cmd_vars_3:
1969c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=foo1 pass_cmd_vars_3_1
19748ec21e7SHartmut Brandt.endif
19848ec21e7SHartmut Brandt
19948ec21e7SHartmut Brandt.if make(pass_cmd_vars_3_1)
20048ec21e7SHartmut Brandt.if ${CMD1} != foo1 || ${CMD2} != cmd2
20182eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden on command line
20248ec21e7SHartmut Brandt.endif
20348ec21e7SHartmut Brandtpass_cmd_vars_3_1:
20448ec21e7SHartmut Brandt	@:
20548ec21e7SHartmut Brandt.endif
20648ec21e7SHartmut Brandt
20748ec21e7SHartmut Brandt.if make(pass_cmd_vars_4)
20848ec21e7SHartmut Brandt# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
20948ec21e7SHartmut Brandt# by evaluating the .MAKEFLAGS target.
21048ec21e7SHartmut Brandt
21148ec21e7SHartmut Brandt.MAKEFLAGS: CMD1=baz1
21248ec21e7SHartmut Brandt
21348ec21e7SHartmut Brandtpass_cmd_vars_4:
2149c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars_4_1
21548ec21e7SHartmut Brandt
21648ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
21782eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
21848ec21e7SHartmut Brandt.endif
21948ec21e7SHartmut Brandt
22048ec21e7SHartmut Brandt.endif
22148ec21e7SHartmut Brandt.if make(pass_cmd_vars_4_1)
22248ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
22382eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
22448ec21e7SHartmut Brandt.endif
22548ec21e7SHartmut Brandtpass_cmd_vars_4_1:
22648ec21e7SHartmut Brandt	@:
22748ec21e7SHartmut Brandt.endif
22848ec21e7SHartmut Brandt
229c997f47bSHartmut Brandt#
230c997f47bSHartmut Brandt# Test whether make supports the '+' flag (meaning: execute even with -n)
231c997f47bSHartmut Brandt#
232c997f47bSHartmut Brandt.if make(plus_flag)
2339c1f3ca3SHartmut BrandtOUT != ${SMAKE} -n plus_flag_1
234c997f47bSHartmut Brandt.if ${OUT} != "/tmp"
23582eb7072SHartmut Brandt.error make doesn't handle + flag
236c997f47bSHartmut Brandt.endif
237c997f47bSHartmut Brandtplus_flag:
238c997f47bSHartmut Brandt	@:
239c997f47bSHartmut Brandt.endif
240c997f47bSHartmut Brandt.if make(plus_flag_1)
241c997f47bSHartmut Brandtplus_flag_1:
242c997f47bSHartmut Brandt	+@cd /tmp; pwd
243c997f47bSHartmut Brandt.endif
244c997f47bSHartmut Brandt
2459a5cf326SRuslan Ermilov.if make(shell)
2469a5cf326SRuslan Ermilov# Test if make fully supports the .SHELL specification.
2479a5cf326SRuslan Ermilov.SHELL: path=/nonexistent
2489a5cf326SRuslan ErmilovA!= echo ok
2499a5cf326SRuslan Ermilovshell:
2509a5cf326SRuslan Ermilov.endif
2519a5cf326SRuslan Ermilov
2527b54cddaSHartmut Brandt.if make(shell_1)
2537b54cddaSHartmut Brandt# Test if setting the shell by name only works. Because we have no ksh
2547b54cddaSHartmut Brandt# in the base system we test that we can set sh and csh. We try only exact
2557b54cddaSHartmut Brandt# matching names and do not exercise the rather strange matching algorithm.
2567b54cddaSHartmut Brandtshell_1:
2579c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_csh
2589c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_sh
2597b54cddaSHartmut Brandt.endif
2607b54cddaSHartmut Brandt.if make(shell_1_csh)
2617b54cddaSHartmut Brandt.SHELL: name="csh"
2627b54cddaSHartmut Brandtshell_1_csh:
2639c1f3ca3SHartmut Brandt	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?csh$$'
2647b54cddaSHartmut Brandt.endif
2657b54cddaSHartmut Brandt.if make(shell_1_sh)
2667b54cddaSHartmut Brandt.SHELL: name="sh"
2677b54cddaSHartmut Brandtshell_1_sh:
2687b54cddaSHartmut Brandt	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -q '^/bin/sh$$'
2697b54cddaSHartmut Brandt.endif
2707b54cddaSHartmut Brandt
2717b54cddaSHartmut Brandt.if make(shell_2)
2727b54cddaSHartmut Brandt# Test if we can replace the shell specification. We do this by using
2737b54cddaSHartmut Brandt# a shell scripts that prints us its arguments and standard input as the shell
2747b54cddaSHartmut Brandtshell_2:
2759c1f3ca3SHartmut Brandt	@${SMAKE} -B shell_2B | \
2767b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2B.out - || false
2779c1f3ca3SHartmut Brandt	@${SMAKE} -j1 shell_2j | \
2787b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2j.out - || false
2797b54cddaSHartmut Brandt.endif
2807b54cddaSHartmut Brandt
2817b54cddaSHartmut Brandt.if make(shell_2B)
2829c1f3ca3SHartmut Brandt.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"
2837b54cddaSHartmut Brandt
2847b54cddaSHartmut Brandtshell_2B:
2857b54cddaSHartmut Brandt	-@funny $$
2867b54cddaSHartmut Brandt	funnier $$
2877b54cddaSHartmut Brandt.endif
2887b54cddaSHartmut Brandt
2897b54cddaSHartmut Brandt.if make(shell_2j)
2909c1f3ca3SHartmut Brandt.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"
2917b54cddaSHartmut Brandt
2927b54cddaSHartmut Brandtshell_2j:
2937b54cddaSHartmut Brandt	-@funny $$
2947b54cddaSHartmut Brandt	funnier $$
2957b54cddaSHartmut Brandt.endif
2967b54cddaSHartmut Brandt
2976541d27cSJuli Mallettfailure:
29800e13b1dSNik Clayton	@echo "not ok # Test failed: regression detected.  See above."
2996541d27cSJuli Mallett	@false
3009c1f3ca3SHartmut Brandt
3019c1f3ca3SHartmut Brandtclean:
3029c1f3ca3SHartmut Brandt	rm -f shell_test
303