xref: /freebsd/tools/build/make_check/Makefile (revision 7b54cdda4e5d7bf71170366d59f76889ead62c9e)
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
216541d27cSJuli Mallettall:
227b54cddaSHartmut Brandt	@echo '1..16'
236541d27cSJuli Mallett	@echo 1:${DATA1} 2:${DATA2} 3:${DATA3} 4:${DATA4} 5:${DATA5} | \
246541d27cSJuli Mallett		diff -u ${.CURDIR}/regress.variables.out - || ${MAKE} failure
2500e13b1dSNik Clayton	@echo "ok 1 - test_variables # Test variables detected no regression, output matches."
26413a16d8SGarance A Drosehn	@${MAKE} double 2>/dev/null || ${MAKE} failure
2700e13b1dSNik Clayton	@echo "ok 2 - test_targets # Test targets detected no regression."
28a9b736adSJuli Mallett	@${MAKE} sysvmatch || ${MAKE} failure
2900e13b1dSNik Clayton	@echo "ok 3 - sysvmatch # Test sysvmatch detected no regression."
306d5fda5fSJuli Mallett	@! ${MAKE} lhs_expn && true || ${MAKE} failure
3100e13b1dSNik Clayton	@echo "ok 4 lhs_expn # Test lhs_expn detected no regression."
32113cf9e6SRuslan Ermilov	@${MAKE} notdef || ${MAKE} failure
3300e13b1dSNik Clayton	@echo "ok 5 - notdef # Test notdef detected no regression."
34113cf9e6SRuslan Ermilov	@${MAKE} modifiers || ${MAKE} failure
3500e13b1dSNik Clayton	@echo "ok 6 - modifiers # Test modifiers detected no regression."
36be8b43b4SRuslan Ermilov	@${MAKE} funny_targets || ${MAKE} failure
3700e13b1dSNik Clayton	@echo "ok 7 funny_targets # Test funny_targets detected no regression."
38c94d7043SRuslan Ermilov	@${MAKE} arith_expr || ${MAKE} failure
3900e13b1dSNik Clayton	@echo "ok 8 arith_expr # Test arith_expr detected no regression."
4021159d16SRuslan Ermilov	@${MAKE} PATH_exists || ${MAKE} failure
4100e13b1dSNik Clayton	@echo "ok 9 PATH_exists # Test PATH_exists detected no regression."
429608d7e2SRuslan Ermilov	@${MAKE} double_quotes || ${MAKE} failure
4300e13b1dSNik Clayton	@echo "ok 10 double_quotes # Test double_quotes detected no regression."
4499d3652eSRuslan Ermilov	@! ${MAKE} double_quotes2 >/dev/null 2>&1 && true || ${MAKE} failure
4500e13b1dSNik Clayton	@echo "ok 11 double_quotes2 # Test double_quotes2 detected no regression."
4648ec21e7SHartmut Brandt	@${MAKE} pass_cmd_vars || ${MAKE} failure
4700e13b1dSNik Clayton	@echo "ok 12 pass_cmd_vars # Test pass_cmd_vars detected no regression."
48c997f47bSHartmut Brandt	@${MAKE} plus_flag || ${MAKE} failure
4900e13b1dSNik Clayton	@echo "ok 13 plus_flag # Test plus_flag detected no regression."
509a5cf326SRuslan Ermilov	@! ${MAKE} shell >/dev/null 2>&1 && true || ${MAKE} failure
5100e13b1dSNik Clayton	@echo "ok 14 shell # Test shell detected no regression."
527b54cddaSHartmut Brandt	@${MAKE} shell_1 || ${MAKE} failure
537b54cddaSHartmut Brandt	@echo "ok 15 shell_1 # Test shell_1 detected no regression."
547b54cddaSHartmut Brandt	@${MAKE} shell_2 || ${MAKE} failure
557b54cddaSHartmut Brandt	@echo "ok 16 shell_2 # Test shell_2 detected no regression."
566d3ca9deSJuli Mallett
575661d4a7SJuli Mallett.if make(double)
5889d22e2fSJuli Mallett# Doubly-defined targets.  make(1) will warn, but use the "right" one.  If it
5989d22e2fSJuli Mallett# switches to using the "non-right" one, it breaks things worse than a little
6089d22e2fSJuli Mallett# regression test.
616d3ca9deSJuli Mallettdouble:
626d3ca9deSJuli Mallett	@true
636d3ca9deSJuli Mallett
646d3ca9deSJuli Mallettdouble:
656d3ca9deSJuli Mallett	@false
665661d4a7SJuli Mallett.endif
676541d27cSJuli Mallett
685661d4a7SJuli Mallett.if make(sysvmatch)
69a9b736adSJuli Mallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst.
70a9b736adSJuli Mallettsysvmatch:
71a9b736adSJuli Mallett	@echo EMPTY ${NIL:=foo} LHS | \
72a9b736adSJuli Mallett		diff -u ${.CURDIR}/regress.sysvmatch.out - || false
735661d4a7SJuli Mallett.endif
74a9b736adSJuli Mallett
750aa9e01cSJuli Mallett# A bogus target for the lhs_expn test;  If this is reached, then the make(1)
760aa9e01cSJuli Mallett# program has not errored out because of the recursion caused by not expanding
770aa9e01cSJuli Mallett# the left-hand-side's embedded variables above.
780aa9e01cSJuli Mallettlhs_expn:
796d5fda5fSJuli Mallett	@true
800aa9e01cSJuli Mallett
81113cf9e6SRuslan Ermilov.if make(notdef)
82113cf9e6SRuslan Ermilov# make(1) claims to only evaluate a conditional as far as is necessary
83113cf9e6SRuslan Ermilov# to determine its value; that was not always the case.
84113cf9e6SRuslan Ermilov.undef notdef
85113cf9e6SRuslan Ermilovnotdef:
86113cf9e6SRuslan Ermilov.if defined(notdef) && ${notdef:U}
87113cf9e6SRuslan Ermilov.endif
88113cf9e6SRuslan Ermilov.endif
89113cf9e6SRuslan Ermilov
90113cf9e6SRuslan Ermilov.if make(modifiers)
91113cf9e6SRuslan Ermilov# See if make(1) supports the C modifier.
92113cf9e6SRuslan Ermilovmodifiers:
93113cf9e6SRuslan Ermilov	@if ${MAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \
94113cf9e6SRuslan Ermilov	    grep -q "Unknown modifier 'C'"; then \
95113cf9e6SRuslan Ermilov		false; \
96113cf9e6SRuslan Ermilov	fi
97113cf9e6SRuslan Ermilov.endif
98113cf9e6SRuslan Ermilov
99be8b43b4SRuslan Ermilov.if make(funny_targets)
100be8b43b4SRuslan Ermilovfunny_targets: colons::target exclamation!target
101be8b43b4SRuslan Ermilovcolons::target:
102be8b43b4SRuslan Ermilovexclamation!target:
103be8b43b4SRuslan Ermilov.endif
104be8b43b4SRuslan Ermilov
105c94d7043SRuslan Ermilov.if make(arith_expr)
106c94d7043SRuslan Ermilovarith_expr:
107c94d7043SRuslan Ermilov# See if arithmetic expression parsing is broken.
108c94d7043SRuslan Ermilov# The different spacing below is intentional.
109c94d7043SRuslan ErmilovVALUE=	0
110c94d7043SRuslan Ermilov.if (${VALUE} < 0)||(${VALUE}>0)
111c94d7043SRuslan Ermilov.endif
112c94d7043SRuslan Ermilov.endif
113c94d7043SRuslan Ermilov
11421159d16SRuslan Ermilov.if make(PATH_exists)
11521159d16SRuslan ErmilovPATH_exists:
11621159d16SRuslan Ermilov.PATH: ${.CURDIR}
11721159d16SRuslan Ermilov.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..)
11821159d16SRuslan Ermilov.error exists() failed
11921159d16SRuslan Ermilov.endif
12021159d16SRuslan Ermilov.endif
12121159d16SRuslan Ermilov
1229608d7e2SRuslan Ermilov.if make(double_quotes)
1239608d7e2SRuslan ErmilovVALUE=	foo ""
1249608d7e2SRuslan Ermilovdouble_quotes:
1259608d7e2SRuslan Ermilov.if ${VALUE:S/$//} != ${VALUE}
1269608d7e2SRuslan Ermilov.error "" reduced to "
1279608d7e2SRuslan Ermilov.endif
1289608d7e2SRuslan Ermilov.endif
1299608d7e2SRuslan Ermilov
13099d3652eSRuslan Ermilov.if make(double_quotes2)
13199d3652eSRuslan Ermilovdouble_quotes2:
13299d3652eSRuslan Ermilov	@cat /dev/null ""
13399d3652eSRuslan Ermilov.endif
13499d3652eSRuslan Ermilov
13548ec21e7SHartmut Brandt#
13648ec21e7SHartmut Brandt# Check passing of variable via MAKEFLAGS
13748ec21e7SHartmut Brandt#
13848ec21e7SHartmut Brandt.if make(pass_cmd_vars)
13948ec21e7SHartmut Brandtpass_cmd_vars:
14048ec21e7SHartmut Brandt	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1
14148ec21e7SHartmut Brandt	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2
14248ec21e7SHartmut Brandt	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3
14348ec21e7SHartmut Brandt	@${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4
14448ec21e7SHartmut Brandt.endif
14548ec21e7SHartmut Brandt
14648ec21e7SHartmut Brandt.if make(pass_cmd_vars_1)
14748ec21e7SHartmut Brandt# Check that the variable definition arrived from the calling make
14848ec21e7SHartmut Brandtpass_cmd_vars_1:
14948ec21e7SHartmut Brandt	@:
15048ec21e7SHartmut Brandt
15148ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
15282eb7072SHartmut Brandt.error variables not passed through MAKEFLAGS
15348ec21e7SHartmut Brandt.endif
15448ec21e7SHartmut Brandt
15548ec21e7SHartmut Brandt# Check that the variable definition is in MAKEFLAGS
15648ec21e7SHartmut Brandt.if ${.MAKEFLAGS:MCMD1=*} != "CMD1=cmd1" || ${.MAKEFLAGS:MCMD2=*} != "CMD2=cmd2"
15782eb7072SHartmut Brandt.error variable assignment not found in $${MAKEFLAGS}
15848ec21e7SHartmut Brandt.endif
15948ec21e7SHartmut Brandt
16048ec21e7SHartmut Brandt# Check that the variable definition is not in MFLAGS
16148ec21e7SHartmut Brandt.if ${MFLAGS:MCMD1=*} != "" || ${MFLAGS:MCMD2=*} != ""
16282eb7072SHartmut Brandt.error variable assignment found in $${MFLAGS}
16348ec21e7SHartmut Brandt.endif
16448ec21e7SHartmut Brandt.endif
16548ec21e7SHartmut Brandt
16648ec21e7SHartmut Brandt.if make(pass_cmd_vars_2)
16748ec21e7SHartmut Brandt# Check that we cannot override the passed variables
16848ec21e7SHartmut BrandtCMD1=foo1
16948ec21e7SHartmut BrandtCMD2=foo2
17048ec21e7SHartmut Brandt
17148ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2
17282eb7072SHartmut Brandt.error MAKEFLAGS-passed variables overridden
17348ec21e7SHartmut Brandt.endif
17448ec21e7SHartmut Brandt
17548ec21e7SHartmut Brandtpass_cmd_vars_2:
17648ec21e7SHartmut Brandt	@:
17748ec21e7SHartmut Brandt.endif
17848ec21e7SHartmut Brandt
17948ec21e7SHartmut Brandt.if make(pass_cmd_vars_3)
18048ec21e7SHartmut Brandt# Check that we can override the passed variables on the next sub-make's
18148ec21e7SHartmut Brandt# command line
18248ec21e7SHartmut Brandt
18348ec21e7SHartmut Brandtpass_cmd_vars_3:
18448ec21e7SHartmut Brandt	@${MAKE} CMD1=foo1 pass_cmd_vars_3_1
18548ec21e7SHartmut Brandt.endif
18648ec21e7SHartmut Brandt
18748ec21e7SHartmut Brandt.if make(pass_cmd_vars_3_1)
18848ec21e7SHartmut Brandt.if ${CMD1} != foo1 || ${CMD2} != cmd2
18982eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden on command line
19048ec21e7SHartmut Brandt.endif
19148ec21e7SHartmut Brandtpass_cmd_vars_3_1:
19248ec21e7SHartmut Brandt	@:
19348ec21e7SHartmut Brandt.endif
19448ec21e7SHartmut Brandt
19548ec21e7SHartmut Brandt.if make(pass_cmd_vars_4)
19648ec21e7SHartmut Brandt# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten
19748ec21e7SHartmut Brandt# by evaluating the .MAKEFLAGS target.
19848ec21e7SHartmut Brandt
19948ec21e7SHartmut Brandt.MAKEFLAGS: CMD1=baz1
20048ec21e7SHartmut Brandt
20148ec21e7SHartmut Brandtpass_cmd_vars_4:
202215431deSHartmut Brandt	@${MAKE} pass_cmd_vars_4_1
20348ec21e7SHartmut Brandt
20448ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
20582eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target
20648ec21e7SHartmut Brandt.endif
20748ec21e7SHartmut Brandt
20848ec21e7SHartmut Brandt.endif
20948ec21e7SHartmut Brandt.if make(pass_cmd_vars_4_1)
21048ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2
21182eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2)
21248ec21e7SHartmut Brandt.endif
21348ec21e7SHartmut Brandtpass_cmd_vars_4_1:
21448ec21e7SHartmut Brandt	@:
21548ec21e7SHartmut Brandt.endif
21648ec21e7SHartmut Brandt
217c997f47bSHartmut Brandt#
218c997f47bSHartmut Brandt# Test whether make supports the '+' flag (meaning: execute even with -n)
219c997f47bSHartmut Brandt#
220c997f47bSHartmut Brandt.if make(plus_flag)
221c997f47bSHartmut BrandtOUT != ${MAKE} -n plus_flag_1
222c997f47bSHartmut Brandt.if ${OUT} != "/tmp"
22382eb7072SHartmut Brandt.error make doesn't handle + flag
224c997f47bSHartmut Brandt.endif
225c997f47bSHartmut Brandtplus_flag:
226c997f47bSHartmut Brandt	@:
227c997f47bSHartmut Brandt.endif
228c997f47bSHartmut Brandt.if make(plus_flag_1)
229c997f47bSHartmut Brandtplus_flag_1:
230c997f47bSHartmut Brandt	+@cd /tmp; pwd
231c997f47bSHartmut Brandt.endif
232c997f47bSHartmut Brandt
2339a5cf326SRuslan Ermilov.if make(shell)
2349a5cf326SRuslan Ermilov# Test if make fully supports the .SHELL specification.
2359a5cf326SRuslan Ermilov.SHELL: path=/nonexistent
2369a5cf326SRuslan ErmilovA!= echo ok
2379a5cf326SRuslan Ermilovshell:
2389a5cf326SRuslan Ermilov.endif
2399a5cf326SRuslan Ermilov
2407b54cddaSHartmut Brandt.if make(shell_1)
2417b54cddaSHartmut Brandt# Test if setting the shell by name only works. Because we have no ksh
2427b54cddaSHartmut Brandt# in the base system we test that we can set sh and csh. We try only exact
2437b54cddaSHartmut Brandt# matching names and do not exercise the rather strange matching algorithm.
2447b54cddaSHartmut Brandtshell_1:
2457b54cddaSHartmut Brandt	@${MAKE} shell_1_csh
2467b54cddaSHartmut Brandt	@${MAKE} shell_1_sh
2477b54cddaSHartmut Brandt.endif
2487b54cddaSHartmut Brandt.if make(shell_1_csh)
2497b54cddaSHartmut Brandt.SHELL: name="csh"
2507b54cddaSHartmut Brandtshell_1_csh:
2517b54cddaSHartmut Brandt	@echo $${shell} | grep -q '^/bin/csh$$'
2527b54cddaSHartmut Brandt.endif
2537b54cddaSHartmut Brandt.if make(shell_1_sh)
2547b54cddaSHartmut Brandt.SHELL: name="sh"
2557b54cddaSHartmut Brandtshell_1_sh:
2567b54cddaSHartmut Brandt	@ps -ax -opid,command | awk '$$1=="'$$$$'" { print $$2 }' | grep -q '^/bin/sh$$'
2577b54cddaSHartmut Brandt.endif
2587b54cddaSHartmut Brandt
2597b54cddaSHartmut Brandt.if make(shell_2)
2607b54cddaSHartmut Brandt# Test if we can replace the shell specification. We do this by using
2617b54cddaSHartmut Brandt# a shell scripts that prints us its arguments and standard input as the shell
2627b54cddaSHartmut Brandtshell_2:
2637b54cddaSHartmut Brandt	@${MAKE} -B shell_2B | \
2647b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2B.out - || false
2657b54cddaSHartmut Brandt	@${MAKE} -j1 shell_2j | \
2667b54cddaSHartmut Brandt		diff -u ${.CURDIR}/regress.shell_2j.out - || false
2677b54cddaSHartmut Brandt.endif
2687b54cddaSHartmut Brandt
2697b54cddaSHartmut Brandt.if make(shell_2B)
2707b54cddaSHartmut Brandt.SHELL: name="echo" path="${.CURDIR}/shell_test" quiet="be quiet" echo="be verbose" filter="be verbose" echoFlag="x" errFlag="y" hasErrCtl=y check="check errors" ignore="ignore errors"
2717b54cddaSHartmut Brandt
2727b54cddaSHartmut Brandtshell_2B:
2737b54cddaSHartmut Brandt	-@funny $$
2747b54cddaSHartmut Brandt	funnier $$
2757b54cddaSHartmut Brandt.endif
2767b54cddaSHartmut Brandt
2777b54cddaSHartmut Brandt.if make(shell_2j)
2787b54cddaSHartmut Brandt.SHELL: name="echo" path="${.CURDIR}/shell_test" quiet="be quiet" echo="be verbose" filter="be verbose" echoFlag="x" errFlag="y" hasErrCtl=y check="check errors" ignore="ignore errors"
2797b54cddaSHartmut Brandt
2807b54cddaSHartmut Brandtshell_2j:
2817b54cddaSHartmut Brandt	-@funny $$
2827b54cddaSHartmut Brandt	funnier $$
2837b54cddaSHartmut Brandt.endif
2847b54cddaSHartmut Brandt
2856541d27cSJuli Mallettfailure:
28600e13b1dSNik Clayton	@echo "not ok # Test failed: regression detected.  See above."
2876541d27cSJuli Mallett	@false
288