xref: /freebsd/tools/build/make_check/Makefile (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
13c24f8e8SDavid E. O'Brien.MAKE.MODE=	normal
23c24f8e8SDavid E. O'Brien
3*fad3f0e4SIan Lepore# Failure is handled by the invoker, don't kill other legs of a parallel build.
4*fad3f0e4SIan LeporeMAKE_JOB_ERROR_TOKEN=no
5*fad3f0e4SIan Lepore
60aa9e01cSJuli Mallett# Test for broken LHS expansion.
7113cf9e6SRuslan Ermilov# This *must* cause make(1) to detect a recursive variable, and fail as such.
80aa9e01cSJuli Mallett.if make(lhs_expn)
90aa9e01cSJuli MallettFOO=		${BAR}
100aa9e01cSJuli MallettBAR${NIL}=	${FOO}
110aa9e01cSJuli MallettFOO${BAR}=	${FOO}
120aa9e01cSJuli Mallett.endif
130aa9e01cSJuli Mallett
146541d27cSJuli MallettDATA1=	helllo
156541d27cSJuli MallettDATA2:=	${DATA1}
166541d27cSJuli MallettDATA3=	${DATA2:S/ll/rr/g}
176541d27cSJuli MallettDATA4:=	${DATA2:S/ll/rr/g}
186541d27cSJuli MallettDATA2?=	allo
196541d27cSJuli MallettDATA5:= ${DATA2:S/ll/ii/g} ${DATA1:S/ll/rr/g}
206541d27cSJuli MallettDATA2=	yello
216541d27cSJuli MallettDATA1:=	${DATA5:S/l/r/g}
22a9b736adSJuli MallettNIL=
236541d27cSJuli Mallett
24d29cf9e2SRuslan ErmilovSMAKE=	MAKEFLAGS= ${MAKE} -C ${.CURDIR}
259c1f3ca3SHartmut Brandt
266541d27cSJuli Mallettall:
276e501706SDavid E. O'Brien	@echo '1..16'
289b6b6816SDavid E. O'Brien	@${SMAKE} C_check || { ${MAKE} -C ${.CURDIR} 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} arith_expr || ${SMAKE} failure
456e501706SDavid E. O'Brien	@echo "ok 8 arith_expr # Test arith_expr detected no regression."
469c1f3ca3SHartmut Brandt	@${SMAKE} PATH_exists || ${SMAKE} failure
476e501706SDavid E. O'Brien	@echo "ok 9 PATH_exists # Test PATH_exists detected no regression."
489c1f3ca3SHartmut Brandt	@${SMAKE} double_quotes || ${SMAKE} failure
496e501706SDavid E. O'Brien	@echo "ok 10 double_quotes # Test double_quotes detected no regression."
509c1f3ca3SHartmut Brandt	@! ${SMAKE} double_quotes2 >/dev/null 2>&1 && true || ${SMAKE} failure
516e501706SDavid E. O'Brien	@echo "ok 11 double_quotes2 # Test double_quotes2 detected no regression."
529c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars || ${SMAKE} failure
536e501706SDavid E. O'Brien	@echo "ok 12 pass_cmd_vars # Test pass_cmd_vars detected no regression."
549c1f3ca3SHartmut Brandt	@${SMAKE} plus_flag || ${SMAKE} failure
556e501706SDavid E. O'Brien	@echo "ok 13 plus_flag # Test plus_flag detected no regression."
569c1f3ca3SHartmut Brandt	@! ${SMAKE} shell >/dev/null 2>&1 && true || ${SMAKE} failure
576e501706SDavid E. O'Brien	@echo "ok 14 shell # Test shell detected no regression."
589c1f3ca3SHartmut Brandt	@${SMAKE} shell_1 || ${SMAKE} failure
596e501706SDavid E. O'Brien	@echo "ok 15 shell_1 # Test shell_1 detected no regression."
609c1f3ca3SHartmut Brandt
619c1f3ca3SHartmut Brandt.if make(C_check)
629c1f3ca3SHartmut BrandtC_check:
639c1f3ca3SHartmut Brandt.endif
646d3ca9deSJuli Mallett
655661d4a7SJuli Mallett.if make(double)
6689d22e2fSJuli Mallett# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
6789d22e2fSJuli Mallett# switches to using the "non-right" one, it breaks things worse than a little
6889d22e2fSJuli Mallett# regression test.
696d3ca9deSJuli Mallettdouble:
706d3ca9deSJuli Mallett	@true
716d3ca9deSJuli Mallett
726d3ca9deSJuli Mallettdouble:
736d3ca9deSJuli Mallett	@false
745661d4a7SJuli Mallett.endif
756541d27cSJuli Mallett
765661d4a7SJuli Mallett.if make(sysvmatch)
77a9b736adSJuli Mallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
78a9b736adSJuli Mallettsysvmatch:
79a9b736adSJuli Mallett	@echo EMPTY ${NIL:=foo} LHS | \
80a9b736adSJuli Mallett		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
815661d4a7SJuli Mallett.endif
82a9b736adSJuli Mallett
830aa9e01cSJuli Mallett# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
840aa9e01cSJuli Mallett# program has not errored out because of the recursion caused by not expanding
850aa9e01cSJuli Mallett# the left-hand-side's embedded variables above.
860aa9e01cSJuli Mallettlhs_expn:
876d5fda5fSJuli Mallett	@true
880aa9e01cSJuli Mallett
89113cf9e6SRuslan Ermilov.if make(notdef)
90113cf9e6SRuslan Ermilov# make(1) claims to only evaluate a conditional as far as is necessary
91113cf9e6SRuslan Ermilov# to determine its value; that was not always the case.
92113cf9e6SRuslan Ermilov.undef notdef
93113cf9e6SRuslan Ermilovnotdef:
940815243cSMarcel Moolenaar.if defined(notdef) && ${notdef:M/}
95113cf9e6SRuslan Ermilov.endif
96113cf9e6SRuslan Ermilov.endif
97113cf9e6SRuslan Ermilov
98113cf9e6SRuslan Ermilov.if make(modifiers)
990815243cSMarcel Moolenaar# check if bmake can expand plain variables
1000815243cSMarcel Moolenaar.MAKE.EXPAND_VARIABLES= yes
1010815243cSMarcel Moolenaarx!= ${SMAKE} -V .CURDIR:H
102113cf9e6SRuslan Ermilovmodifiers:
1030815243cSMarcel Moolenaar.if ${.CURDIR:H} != "$x"
1040815243cSMarcel Moolenaar	@false
1050815243cSMarcel Moolenaar.endif
106113cf9e6SRuslan Ermilov.endif
107113cf9e6SRuslan Ermilov
108c94d7043SRuslan Ermilov.if make(arith_expr)
109c94d7043SRuslan Ermilovarith_expr:
110c94d7043SRuslan Ermilov# See if arithmetic expression parsing is broken.
111c94d7043SRuslan Ermilov# The different spacing below is intentional.
112c94d7043SRuslan ErmilovVALUE=	0
113c94d7043SRuslan Ermilov.if (${VALUE} < 0)||(${VALUE}>0)
114c94d7043SRuslan Ermilov.endif
115c94d7043SRuslan Ermilov.endif
116c94d7043SRuslan Ermilov
11721159d16SRuslan Ermilov.if make(PATH_exists)
11821159d16SRuslan ErmilovPATH_exists:
11921159d16SRuslan Ermilov.PATH: ${.CURDIR}
12021159d16SRuslan Ermilov.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
12121159d16SRuslan Ermilov.error exists() failed
12221159d16SRuslan Ermilov.endif
12321159d16SRuslan Ermilov.endif
12421159d16SRuslan Ermilov
1259608d7e2SRuslan Ermilov.if make(double_quotes)
1269608d7e2SRuslan ErmilovVALUE=	foo ""
1279608d7e2SRuslan Ermilovdouble_quotes:
1289608d7e2SRuslan Ermilov.if ${VALUE:S/$//} != ${VALUE}
1299608d7e2SRuslan Ermilov.error "" reduced to "
1309608d7e2SRuslan Ermilov.endif
1319608d7e2SRuslan Ermilov.endif
1329608d7e2SRuslan Ermilov
13399d3652eSRuslan Ermilov.if make(double_quotes2)
13499d3652eSRuslan Ermilovdouble_quotes2:
13599d3652eSRuslan Ermilov	@cat /dev/null ""
13699d3652eSRuslan Ermilov.endif
13799d3652eSRuslan Ermilov
13848ec21e7SHartmut Brandt#
13948ec21e7SHartmut Brandt# Check passing of variable via MAKEFLAGS
14048ec21e7SHartmut Brandt#
14148ec21e7SHartmut Brandt.if make(pass_cmd_vars)
14248ec21e7SHartmut Brandtpass_cmd_vars:
1439c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
1449c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
1459c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
1469c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
14748ec21e7SHartmut Brandt.endif
14848ec21e7SHartmut Brandt
1493c24f8e8SDavid E. O'Brien#
15048ec21e7SHartmut Brandt# Check that the variable definition arrived from the calling make
1513c24f8e8SDavid E. O'Brien#
1523c24f8e8SDavid E. O'Brien.if make(pass_cmd_vars_1)
1533c24f8e8SDavid E. O'Brien# These values should get overridden by the commandline
1543c24f8e8SDavid E. O'BrienCMD1=oops1
1553c24f8e8SDavid E. O'BrienCMD2=oops2
15648ec21e7SHartmut Brandtpass_cmd_vars_1:
15748ec21e7SHartmut Brandt	@:
15848ec21e7SHartmut Brandt
15948ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
16082eb7072SHartmut Brandt.error variables not passed through MAKEFLAGS
16148ec21e7SHartmut Brandt.endif
16248ec21e7SHartmut Brandt.endif
16348ec21e7SHartmut Brandt
16448ec21e7SHartmut Brandt.if make(pass_cmd_vars_2)
16548ec21e7SHartmut Brandt# Check that we cannot override the passed variables
16648ec21e7SHartmut BrandtCMD1=foo1
16748ec21e7SHartmut BrandtCMD2=foo2
16848ec21e7SHartmut Brandt
16948ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
17082eb7072SHartmut Brandt.error MAKEFLAGS-passed variables overridden
17148ec21e7SHartmut Brandt.endif
17248ec21e7SHartmut Brandt
17348ec21e7SHartmut Brandtpass_cmd_vars_2:
17448ec21e7SHartmut Brandt	@:
17548ec21e7SHartmut Brandt.endif
17648ec21e7SHartmut Brandt
17748ec21e7SHartmut Brandt.if make(pass_cmd_vars_3)
17848ec21e7SHartmut Brandt# Check that we can override the passed variables on the next sub-make's
17948ec21e7SHartmut Brandt# command line
18048ec21e7SHartmut Brandt
18148ec21e7SHartmut Brandtpass_cmd_vars_3:
1829c1f3ca3SHartmut Brandt	@${SMAKE} CMD1=foo1 pass_cmd_vars_3_1
18348ec21e7SHartmut Brandt.endif
18448ec21e7SHartmut Brandt
18548ec21e7SHartmut Brandt.if make(pass_cmd_vars_3_1)
18648ec21e7SHartmut Brandt.if ${CMD1} != foo1 || ${CMD2} != cmd2
18782eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden on command line
18848ec21e7SHartmut Brandt.endif
18948ec21e7SHartmut Brandtpass_cmd_vars_3_1:
19048ec21e7SHartmut Brandt	@:
19148ec21e7SHartmut Brandt.endif
19248ec21e7SHartmut Brandt
19348ec21e7SHartmut Brandt.if make(pass_cmd_vars_4)
19448ec21e7SHartmut Brandt# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
19548ec21e7SHartmut Brandt# by evaluating the .MAKEFLAGS target.
19648ec21e7SHartmut Brandt
19748ec21e7SHartmut Brandt.MAKEFLAGS: CMD1=baz1
19848ec21e7SHartmut Brandt
19948ec21e7SHartmut Brandtpass_cmd_vars_4:
2009c1f3ca3SHartmut Brandt	@${SMAKE} pass_cmd_vars_4_1
20148ec21e7SHartmut Brandt
20248ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
20382eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
20448ec21e7SHartmut Brandt.endif
20548ec21e7SHartmut Brandt
20648ec21e7SHartmut Brandt.endif
20748ec21e7SHartmut Brandt.if make(pass_cmd_vars_4_1)
20848ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
20982eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
21048ec21e7SHartmut Brandt.endif
21148ec21e7SHartmut Brandtpass_cmd_vars_4_1:
21248ec21e7SHartmut Brandt	@:
21348ec21e7SHartmut Brandt.endif
21448ec21e7SHartmut Brandt
215c997f47bSHartmut Brandt#
216c997f47bSHartmut Brandt# Test whether make supports the '+' flag (meaning: execute even with -n)
217c997f47bSHartmut Brandt#
218c997f47bSHartmut Brandt.if make(plus_flag)
2199c1f3ca3SHartmut BrandtOUT != ${SMAKE} -n plus_flag_1
2203c24f8e8SDavid E. O'Brien.if ${OUT:M/tmp} != "/tmp"
22182eb7072SHartmut Brandt.error make doesn't handle + flag
222c997f47bSHartmut Brandt.endif
223c997f47bSHartmut Brandtplus_flag:
224c997f47bSHartmut Brandt	@:
225c997f47bSHartmut Brandt.endif
226c997f47bSHartmut Brandt.if make(plus_flag_1)
227c997f47bSHartmut Brandtplus_flag_1:
228c997f47bSHartmut Brandt	+@cd /tmp; pwd
229c997f47bSHartmut Brandt.endif
230c997f47bSHartmut Brandt
2319a5cf326SRuslan Ermilov.if make(shell)
2329a5cf326SRuslan Ermilov# Test if make fully supports the .SHELL specification.
2339a5cf326SRuslan Ermilov.SHELL: path=/nonexistent
2349a5cf326SRuslan ErmilovA!= echo ok
2359a5cf326SRuslan Ermilovshell:
2369a5cf326SRuslan Ermilov.endif
2379a5cf326SRuslan Ermilov
2387b54cddaSHartmut Brandt.if make(shell_1)
2397b54cddaSHartmut Brandt# Test if setting the shell by name only works. Because we have no ksh
2407b54cddaSHartmut Brandt# in the base system we test that we can set sh and csh. We try only exact
2417b54cddaSHartmut Brandt# matching names and do not exercise the rather strange matching algorithm.
2427b54cddaSHartmut Brandtshell_1:
2439c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_csh
2449c1f3ca3SHartmut Brandt	@${SMAKE} shell_1_sh
2457b54cddaSHartmut Brandt.endif
2467b54cddaSHartmut Brandt.if make(shell_1_csh)
2477b54cddaSHartmut Brandt.SHELL: name="csh"
2487b54cddaSHartmut Brandtshell_1_csh:
2499c1f3ca3SHartmut Brandt	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?csh$$'
2507b54cddaSHartmut Brandt.endif
2517b54cddaSHartmut Brandt.if make(shell_1_sh)
2527b54cddaSHartmut Brandt.SHELL: name="sh"
2537b54cddaSHartmut Brandtshell_1_sh:
2541b647f44SRuslan Ermilov	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -E -q '^(/bin/)?sh$$'
2557b54cddaSHartmut Brandt.endif
2567b54cddaSHartmut Brandt
2577b54cddaSHartmut Brandt.if make(shell_2)
2587b54cddaSHartmut Brandt# Test if we can replace the shell specification. We do this by using
2597b54cddaSHartmut Brandt# a shell scripts that prints us its arguments and standard input as the shell
26089f087e8SHartmut Brandtshell_2: shell_test
2619c1f3ca3SHartmut Brandt	@${SMAKE} -B shell_2B | \
2627b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2B.out - || false
2639c1f3ca3SHartmut Brandt	@${SMAKE} -j1 shell_2j | \
2647b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2j.out - || false
2657b54cddaSHartmut Brandt.endif
2667b54cddaSHartmut Brandt
2677b54cddaSHartmut Brandt.if make(shell_2B)
2689c1f3ca3SHartmut 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"
2697b54cddaSHartmut Brandt
2707b54cddaSHartmut Brandtshell_2B:
2717b54cddaSHartmut Brandt	-@funny $$
2727b54cddaSHartmut Brandt	funnier $$
2737b54cddaSHartmut Brandt.endif
2747b54cddaSHartmut Brandt
2757b54cddaSHartmut Brandt.if make(shell_2j)
2769c1f3ca3SHartmut 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"
2777b54cddaSHartmut Brandt
2787b54cddaSHartmut Brandtshell_2j:
2797b54cddaSHartmut Brandt	-@funny $$
2807b54cddaSHartmut Brandt	funnier $$
2817b54cddaSHartmut Brandt.endif
2827b54cddaSHartmut Brandt
2836541d27cSJuli Mallettfailure:
28400e13b1dSNik Clayton	@echo "not ok # Test failed: regression detected.  See above."
2856541d27cSJuli Mallett	@false
2869c1f3ca3SHartmut Brandt
28789f087e8SHartmut BrandtCLEANFILES= shell_test
28889f087e8SHartmut Brandt
28989f087e8SHartmut Brandt.include <bsd.obj.mk>
290