xref: /freebsd/tools/build/make_check/Makefile (revision 9b6b6816241be8199d8368c3bbb4b2d85ff9bcb7)
16541d27cSJuli Mallett# $FreeBSD$
26541d27cSJuli Mallett
33c24f8e8SDavid E. O'Brien.MAKE.MODE=	normal
43c24f8e8SDavid E. O'Brien
50aa9e01cSJuli Mallett# Test for broken LHS expansion.
6113cf9e6SRuslan Ermilov# This *must* cause make(1) to detect a recursive variable, and fail as such.
70aa9e01cSJuli Mallett.if make(lhs_expn)
80aa9e01cSJuli MallettFOO=		${BAR}
90aa9e01cSJuli MallettBAR${NIL}=	${FOO}
100aa9e01cSJuli MallettFOO${BAR}=	${FOO}
110aa9e01cSJuli Mallett.endif
120aa9e01cSJuli Mallett
136541d27cSJuli MallettDATA1=	helllo
146541d27cSJuli MallettDATA2:=	${DATA1}
156541d27cSJuli MallettDATA3=	${DATA2:S/ll/rr/g}
166541d27cSJuli MallettDATA4:=	${DATA2:S/ll/rr/g}
176541d27cSJuli MallettDATA2?=	allo
186541d27cSJuli MallettDATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
196541d27cSJuli MallettDATA2=	yello
206541d27cSJuli MallettDATA1:=	${DATA5:S/l/r/g}
21a9b736adSJuli MallettNIL=
226541d27cSJuli Mallett
23d29cf9e2SRuslan ErmilovSMAKE=	MAKEFLAGS= ${MAKE} -C ${.CURDIR}
249c1f3ca3SHartmut Brandt
256541d27cSJuli Mallettall:
266e501706SDavid E. O'Brien	@echo '1..16'
27*9b6b6816SDavid E. O'Brien	@${SMAKE} C_check || { ${MAKE} -C ${.CURDIR} failure ; }
289c1f3ca3SHartmut Brandt	@echo "ok 1 - C_check # Test of -C flag existence detected no regression."
296541d27cSJuli Mallett	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
309c1f3ca3SHartmut Brandt		diff -u ${.CURDIR}/regress.variables.out - || \
319c1f3ca3SHartmut Brandt		${SMAKE} failure
329c1f3ca3SHartmut Brandt	@echo "ok 2 - test_variables # Test variables detected no regression, output matches."
339c1f3ca3SHartmut Brandt	@${SMAKE} double 2>/dev/null || ${SMAKE} failure
349c1f3ca3SHartmut Brandt	@echo "ok 3 - test_targets # Test targets detected no regression."
359c1f3ca3SHartmut Brandt	@${SMAKE} sysvmatch || ${SMAKE} failure
369c1f3ca3SHartmut Brandt	@echo "ok 4 - sysvmatch # Test sysvmatch detected no regression."
379c1f3ca3SHartmut Brandt	@! ${SMAKE} lhs_expn && true || ${SMAKE} failure
389c1f3ca3SHartmut Brandt	@echo "ok 5 lhs_expn # Test lhs_expn detected no regression."
399c1f3ca3SHartmut Brandt	@${SMAKE} notdef || ${SMAKE} failure
409c1f3ca3SHartmut Brandt	@echo "ok 6 - notdef # Test notdef detected no regression."
419c1f3ca3SHartmut Brandt	@${SMAKE} modifiers || ${SMAKE} failure
429c1f3ca3SHartmut Brandt	@echo "ok 7 - modifiers # Test modifiers detected no regression."
439c1f3ca3SHartmut Brandt	@${SMAKE} arith_expr || ${SMAKE} failure
446e501706SDavid E. O'Brien	@echo "ok 8 arith_expr # Test arith_expr detected no regression."
459c1f3ca3SHartmut Brandt	@${SMAKE} PATH_exists || ${SMAKE} failure
466e501706SDavid E. O'Brien	@echo "ok 9 PATH_exists # Test PATH_exists detected no regression."
479c1f3ca3SHartmut Brandt	@${SMAKE} double_quotes || ${SMAKE} failure
486e501706SDavid E. O'Brien	@echo "ok 10 double_quotes # Test double_quotes detected no regression."
499c1f3ca3SHartmut Brandt	@! ${SMAKE} double_quotes2 >/dev/null 2>&1 && true || ${SMAKE} failure
506e501706SDavid E. O'Brien	@echo "ok 11 double_quotes2 # Test double_quotes2 detected no regression."
519c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars || ${SMAKE} failure
526e501706SDavid E. O'Brien	@echo "ok 12 pass_cmd_vars # Test pass_cmd_vars detected no regression."
539c1f3ca3SHartmut Brandt	@${SMAKE} plus_flag || ${SMAKE} failure
546e501706SDavid E. O'Brien	@echo "ok 13 plus_flag # Test plus_flag detected no regression."
559c1f3ca3SHartmut Brandt	@! ${SMAKE} shell >/dev/null 2>&1 && true || ${SMAKE} failure
566e501706SDavid E. O'Brien	@echo "ok 14 shell # Test shell detected no regression."
579c1f3ca3SHartmut Brandt	@${SMAKE} shell_1 || ${SMAKE} failure
586e501706SDavid E. O'Brien	@echo "ok 15 shell_1 # Test shell_1 detected no regression."
590815243cSMarcel Moolenaar.if !defined(.PARSEDIR)
609c1f3ca3SHartmut Brandt	@${SMAKE} shell_2 || ${SMAKE} failure
616e501706SDavid E. O'Brien	@echo "ok 16 shell_2 # Test shell_2 detected no regression."
620815243cSMarcel Moolenaar.endif
639c1f3ca3SHartmut Brandt
649c1f3ca3SHartmut Brandt.if make(C_check)
659c1f3ca3SHartmut BrandtC_check:
669c1f3ca3SHartmut Brandt.endif
676d3ca9deSJuli Mallett
685661d4a7SJuli Mallett.if make(double)
6989d22e2fSJuli Mallett# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
7089d22e2fSJuli Mallett# switches to using the "non-right" one, it breaks things worse than a little
7189d22e2fSJuli Mallett# regression test.
726d3ca9deSJuli Mallettdouble:
736d3ca9deSJuli Mallett	@true
746d3ca9deSJuli Mallett
756d3ca9deSJuli Mallettdouble:
766d3ca9deSJuli Mallett	@false
775661d4a7SJuli Mallett.endif
786541d27cSJuli Mallett
795661d4a7SJuli Mallett.if make(sysvmatch)
80a9b736adSJuli Mallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
81a9b736adSJuli Mallettsysvmatch:
82a9b736adSJuli Mallett	@echo EMPTY ${NIL:=foo} LHS | \
83a9b736adSJuli Mallett		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
845661d4a7SJuli Mallett.endif
85a9b736adSJuli Mallett
860aa9e01cSJuli Mallett# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
870aa9e01cSJuli Mallett# program has not errored out because of the recursion caused by not expanding
880aa9e01cSJuli Mallett# the left-hand-side's embedded variables above.
890aa9e01cSJuli Mallettlhs_expn:
906d5fda5fSJuli Mallett	@true
910aa9e01cSJuli Mallett
92113cf9e6SRuslan Ermilov.if make(notdef)
93113cf9e6SRuslan Ermilov# make(1) claims to only evaluate a conditional as far as is necessary
94113cf9e6SRuslan Ermilov# to determine its value; that was not always the case.
95113cf9e6SRuslan Ermilov.undef notdef
96113cf9e6SRuslan Ermilovnotdef:
970815243cSMarcel Moolenaar.if defined(notdef) && ${notdef:M/}
98113cf9e6SRuslan Ermilov.endif
99113cf9e6SRuslan Ermilov.endif
100113cf9e6SRuslan Ermilov
101113cf9e6SRuslan Ermilov.if make(modifiers)
1020815243cSMarcel Moolenaar.if defined(.PARSEDIR)
1030815243cSMarcel Moolenaar# check if bmake can expand plain variables
1040815243cSMarcel Moolenaar.MAKE.EXPAND_VARIABLES= yes
1050815243cSMarcel Moolenaarx!= ${SMAKE} -V .CURDIR:H
106113cf9e6SRuslan Ermilovmodifiers:
1070815243cSMarcel Moolenaar.if ${.CURDIR:H} != "$x"
1080815243cSMarcel Moolenaar	@false
1090815243cSMarcel Moolenaar.endif
1100815243cSMarcel Moolenaar.else
1110815243cSMarcel Moolenaar# See if make(1) supports the C modifier.
1120815243cSMarcel Moolenaarmodifiers: dollarV
1139c1f3ca3SHartmut Brandt	@if ${SMAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
114113cf9e6SRuslan Ermilov	    grep -q "Unknown modifier 'C'"; then \
115113cf9e6SRuslan Ermilov		false; \
116113cf9e6SRuslan Ermilov	fi
1170815243cSMarcel Moolenaar
1180815243cSMarcel Moolenaar# check that make -V '${VAR}' works
1190815243cSMarcel MoolenaarV_expn != V_OK=ok ${SMAKE} -r -f /dev/null -V '$${V_OK}'
1200815243cSMarcel MoolenaardollarV:
1210815243cSMarcel Moolenaar.if ${V_expn} == ""
1220815243cSMarcel Moolenaar	@false
1230815243cSMarcel Moolenaar.endif
1240815243cSMarcel Moolenaar.endif
125113cf9e6SRuslan Ermilov.endif
126113cf9e6SRuslan Ermilov
127c94d7043SRuslan Ermilov.if make(arith_expr)
128c94d7043SRuslan Ermilovarith_expr:
129c94d7043SRuslan Ermilov# See if arithmetic expression parsing is broken.
130c94d7043SRuslan Ermilov# The different spacing below is intentional.
131c94d7043SRuslan ErmilovVALUE=	0
132c94d7043SRuslan Ermilov.if (${VALUE} < 0)||(${VALUE}>0)
133c94d7043SRuslan Ermilov.endif
134c94d7043SRuslan Ermilov.endif
135c94d7043SRuslan Ermilov
13621159d16SRuslan Ermilov.if make(PATH_exists)
13721159d16SRuslan ErmilovPATH_exists:
13821159d16SRuslan Ermilov.PATH: ${.CURDIR}
13921159d16SRuslan Ermilov.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
14021159d16SRuslan Ermilov.error exists() failed
14121159d16SRuslan Ermilov.endif
14221159d16SRuslan Ermilov.endif
14321159d16SRuslan Ermilov
1449608d7e2SRuslan Ermilov.if make(double_quotes)
1459608d7e2SRuslan ErmilovVALUE=	foo ""
1469608d7e2SRuslan Ermilovdouble_quotes:
1479608d7e2SRuslan Ermilov.if ${VALUE:S/$//} != ${VALUE}
1489608d7e2SRuslan Ermilov.error "" reduced to "
1499608d7e2SRuslan Ermilov.endif
1509608d7e2SRuslan Ermilov.endif
1519608d7e2SRuslan Ermilov
15299d3652eSRuslan Ermilov.if make(double_quotes2)
15399d3652eSRuslan Ermilovdouble_quotes2:
15499d3652eSRuslan Ermilov	@cat /dev/null ""
15599d3652eSRuslan Ermilov.endif
15699d3652eSRuslan Ermilov
15748ec21e7SHartmut Brandt#
15848ec21e7SHartmut Brandt# Check passing of variable via MAKEFLAGS
15948ec21e7SHartmut Brandt#
16048ec21e7SHartmut Brandt.if make(pass_cmd_vars)
16148ec21e7SHartmut Brandtpass_cmd_vars:
1629c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
1639c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
1649c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
1659c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
16648ec21e7SHartmut Brandt.endif
16748ec21e7SHartmut Brandt
1683c24f8e8SDavid E. O'Brien#
16948ec21e7SHartmut Brandt# Check that the variable definition arrived from the calling make
1703c24f8e8SDavid E. O'Brien#
1713c24f8e8SDavid E. O'Brien.if make(pass_cmd_vars_1)
1723c24f8e8SDavid E. O'Brien# These values should get overridden by the commandline
1733c24f8e8SDavid E. O'BrienCMD1=oops1
1743c24f8e8SDavid E. O'BrienCMD2=oops2
17548ec21e7SHartmut Brandtpass_cmd_vars_1:
17648ec21e7SHartmut Brandt	@:
17748ec21e7SHartmut Brandt
17848ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
17982eb7072SHartmut Brandt.error variables not passed through MAKEFLAGS
18048ec21e7SHartmut Brandt.endif
18148ec21e7SHartmut Brandt.endif
18248ec21e7SHartmut Brandt
18348ec21e7SHartmut Brandt.if make(pass_cmd_vars_2)
18448ec21e7SHartmut Brandt# Check that we cannot override the passed variables
18548ec21e7SHartmut BrandtCMD1=foo1
18648ec21e7SHartmut BrandtCMD2=foo2
18748ec21e7SHartmut Brandt
18848ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
18982eb7072SHartmut Brandt.error MAKEFLAGS-passed variables overridden
19048ec21e7SHartmut Brandt.endif
19148ec21e7SHartmut Brandt
19248ec21e7SHartmut Brandtpass_cmd_vars_2:
19348ec21e7SHartmut Brandt	@:
19448ec21e7SHartmut Brandt.endif
19548ec21e7SHartmut Brandt
19648ec21e7SHartmut Brandt.if make(pass_cmd_vars_3)
19748ec21e7SHartmut Brandt# Check that we can override the passed variables on the next sub-make's
19848ec21e7SHartmut Brandt# command line
19948ec21e7SHartmut Brandt
20048ec21e7SHartmut Brandtpass_cmd_vars_3:
2019c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=foo1 pass_cmd_vars_3_1
20248ec21e7SHartmut Brandt.endif
20348ec21e7SHartmut Brandt
20448ec21e7SHartmut Brandt.if make(pass_cmd_vars_3_1)
20548ec21e7SHartmut Brandt.if ${CMD1} != foo1 || ${CMD2} != cmd2
20682eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden on command line
20748ec21e7SHartmut Brandt.endif
20848ec21e7SHartmut Brandtpass_cmd_vars_3_1:
20948ec21e7SHartmut Brandt	@:
21048ec21e7SHartmut Brandt.endif
21148ec21e7SHartmut Brandt
21248ec21e7SHartmut Brandt.if make(pass_cmd_vars_4)
21348ec21e7SHartmut Brandt# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
21448ec21e7SHartmut Brandt# by evaluating the .MAKEFLAGS target.
21548ec21e7SHartmut Brandt
21648ec21e7SHartmut Brandt.MAKEFLAGS: CMD1=baz1
21748ec21e7SHartmut Brandt
21848ec21e7SHartmut Brandtpass_cmd_vars_4:
2199c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars_4_1
22048ec21e7SHartmut Brandt
22148ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
22282eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
22348ec21e7SHartmut Brandt.endif
22448ec21e7SHartmut Brandt
22548ec21e7SHartmut Brandt.endif
22648ec21e7SHartmut Brandt.if make(pass_cmd_vars_4_1)
22748ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
22882eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
22948ec21e7SHartmut Brandt.endif
23048ec21e7SHartmut Brandtpass_cmd_vars_4_1:
23148ec21e7SHartmut Brandt	@:
23248ec21e7SHartmut Brandt.endif
23348ec21e7SHartmut Brandt
234c997f47bSHartmut Brandt#
235c997f47bSHartmut Brandt# Test whether make supports the '+' flag (meaning: execute even with -n)
236c997f47bSHartmut Brandt#
237c997f47bSHartmut Brandt.if make(plus_flag)
2389c1f3ca3SHartmut BrandtOUT != ${SMAKE} -n plus_flag_1
2393c24f8e8SDavid E. O'Brien.if ${OUT:M/tmp} != "/tmp"
24082eb7072SHartmut Brandt.error make doesn't handle + flag
241c997f47bSHartmut Brandt.endif
242c997f47bSHartmut Brandtplus_flag:
243c997f47bSHartmut Brandt	@:
244c997f47bSHartmut Brandt.endif
245c997f47bSHartmut Brandt.if make(plus_flag_1)
246c997f47bSHartmut Brandtplus_flag_1:
247c997f47bSHartmut Brandt	+@cd /tmp; pwd
248c997f47bSHartmut Brandt.endif
249c997f47bSHartmut Brandt
2509a5cf326SRuslan Ermilov.if make(shell)
2519a5cf326SRuslan Ermilov# Test if make fully supports the .SHELL specification.
2529a5cf326SRuslan Ermilov.SHELL: path=/nonexistent
2539a5cf326SRuslan ErmilovA!= echo ok
2549a5cf326SRuslan Ermilovshell:
2559a5cf326SRuslan Ermilov.endif
2569a5cf326SRuslan Ermilov
2577b54cddaSHartmut Brandt.if make(shell_1)
2587b54cddaSHartmut Brandt# Test if setting the shell by name only works. Because we have no ksh
2597b54cddaSHartmut Brandt# in the base system we test that we can set sh and csh. We try only exact
2607b54cddaSHartmut Brandt# matching names and do not exercise the rather strange matching algorithm.
2617b54cddaSHartmut Brandtshell_1:
2629c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_csh
2639c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_sh
2647b54cddaSHartmut Brandt.endif
2657b54cddaSHartmut Brandt.if make(shell_1_csh)
2667b54cddaSHartmut Brandt.SHELL: name="csh"
2677b54cddaSHartmut Brandtshell_1_csh:
2689c1f3ca3SHartmut Brandt	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?csh$$'
2697b54cddaSHartmut Brandt.endif
2707b54cddaSHartmut Brandt.if make(shell_1_sh)
2717b54cddaSHartmut Brandt.SHELL: name="sh"
2727b54cddaSHartmut Brandtshell_1_sh:
2731b647f44SRuslan Ermilov	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?sh$$'
2747b54cddaSHartmut Brandt.endif
2757b54cddaSHartmut Brandt
2767b54cddaSHartmut Brandt.if make(shell_2)
2777b54cddaSHartmut Brandt# Test if we can replace the shell specification. We do this by using
2787b54cddaSHartmut Brandt# a shell scripts that prints us its arguments and standard input as the shell
27989f087e8SHartmut Brandtshell_2: shell_test
2809c1f3ca3SHartmut Brandt	@${SMAKE} -B shell_2B | \
2817b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2B.out - || false
2829c1f3ca3SHartmut Brandt	@${SMAKE} -j1 shell_2j | \
2837b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2j.out - || false
2847b54cddaSHartmut Brandt.endif
2857b54cddaSHartmut Brandt
2867b54cddaSHartmut Brandt.if make(shell_2B)
2879c1f3ca3SHartmut 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"
2887b54cddaSHartmut Brandt
2897b54cddaSHartmut Brandtshell_2B:
2907b54cddaSHartmut Brandt	-@funny $$
2917b54cddaSHartmut Brandt	funnier $$
2927b54cddaSHartmut Brandt.endif
2937b54cddaSHartmut Brandt
2947b54cddaSHartmut Brandt.if make(shell_2j)
2959c1f3ca3SHartmut 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"
2967b54cddaSHartmut Brandt
2977b54cddaSHartmut Brandtshell_2j:
2987b54cddaSHartmut Brandt	-@funny $$
2997b54cddaSHartmut Brandt	funnier $$
3007b54cddaSHartmut Brandt.endif
3017b54cddaSHartmut Brandt
3026541d27cSJuli Mallettfailure:
30300e13b1dSNik Clayton	@echo "not ok # Test failed: regression detected.  See above."
3046541d27cSJuli Mallett	@false
3059c1f3ca3SHartmut Brandt
30689f087e8SHartmut BrandtCLEANFILES= shell_test
30789f087e8SHartmut Brandt
30889f087e8SHartmut Brandt.include <bsd.obj.mk>
309