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: 2200e13b1dSNik Clayton @echo '1..14' 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." 526d3ca9deSJuli Mallett 535661d4a7SJuli Mallett.if make(double) 5489d22e2fSJuli Mallett# Doubly-defined targets. make(1) will warn, but use the "right" one. If it 5589d22e2fSJuli Mallett# switches to using the "non-right" one, it breaks things worse than a little 5689d22e2fSJuli Mallett# regression test. 576d3ca9deSJuli Mallettdouble: 586d3ca9deSJuli Mallett @true 596d3ca9deSJuli Mallett 606d3ca9deSJuli Mallettdouble: 616d3ca9deSJuli Mallett @false 625661d4a7SJuli Mallett.endif 636541d27cSJuli Mallett 645661d4a7SJuli Mallett.if make(sysvmatch) 65a9b736adSJuli Mallett# Some versions of FreeBSD make(1) do not handle a nil LHS in sysvsubst. 66a9b736adSJuli Mallettsysvmatch: 67a9b736adSJuli Mallett @echo EMPTY ${NIL:=foo} LHS | \ 68a9b736adSJuli Mallett diff -u ${.CURDIR}/regress.sysvmatch.out - || false 695661d4a7SJuli Mallett.endif 70a9b736adSJuli Mallett 710aa9e01cSJuli Mallett# A bogus target for the lhs_expn test; If this is reached, then the make(1) 720aa9e01cSJuli Mallett# program has not errored out because of the recursion caused by not expanding 730aa9e01cSJuli Mallett# the left-hand-side's embedded variables above. 740aa9e01cSJuli Mallettlhs_expn: 756d5fda5fSJuli Mallett @true 760aa9e01cSJuli Mallett 77113cf9e6SRuslan Ermilov.if make(notdef) 78113cf9e6SRuslan Ermilov# make(1) claims to only evaluate a conditional as far as is necessary 79113cf9e6SRuslan Ermilov# to determine its value; that was not always the case. 80113cf9e6SRuslan Ermilov.undef notdef 81113cf9e6SRuslan Ermilovnotdef: 82113cf9e6SRuslan Ermilov.if defined(notdef) && ${notdef:U} 83113cf9e6SRuslan Ermilov.endif 84113cf9e6SRuslan Ermilov.endif 85113cf9e6SRuslan Ermilov 86113cf9e6SRuslan Ermilov.if make(modifiers) 87113cf9e6SRuslan Ermilov# See if make(1) supports the C modifier. 88113cf9e6SRuslan Ermilovmodifiers: 89113cf9e6SRuslan Ermilov @if ${MAKE} -V .CURDIR:C/.// 2>&1 >/dev/null | \ 90113cf9e6SRuslan Ermilov grep -q "Unknown modifier 'C'"; then \ 91113cf9e6SRuslan Ermilov false; \ 92113cf9e6SRuslan Ermilov fi 93113cf9e6SRuslan Ermilov.endif 94113cf9e6SRuslan Ermilov 95be8b43b4SRuslan Ermilov.if make(funny_targets) 96be8b43b4SRuslan Ermilovfunny_targets: colons::target exclamation!target 97be8b43b4SRuslan Ermilovcolons::target: 98be8b43b4SRuslan Ermilovexclamation!target: 99be8b43b4SRuslan Ermilov.endif 100be8b43b4SRuslan Ermilov 101c94d7043SRuslan Ermilov.if make(arith_expr) 102c94d7043SRuslan Ermilovarith_expr: 103c94d7043SRuslan Ermilov# See if arithmetic expression parsing is broken. 104c94d7043SRuslan Ermilov# The different spacing below is intentional. 105c94d7043SRuslan ErmilovVALUE= 0 106c94d7043SRuslan Ermilov.if (${VALUE} < 0)||(${VALUE}>0) 107c94d7043SRuslan Ermilov.endif 108c94d7043SRuslan Ermilov.endif 109c94d7043SRuslan Ermilov 11021159d16SRuslan Ermilov.if make(PATH_exists) 11121159d16SRuslan ErmilovPATH_exists: 11221159d16SRuslan Ermilov.PATH: ${.CURDIR} 11321159d16SRuslan Ermilov.if !exists(${.CURDIR}/) || !exists(${.CURDIR}/.) || !exists(${.CURDIR}/..) 11421159d16SRuslan Ermilov.error exists() failed 11521159d16SRuslan Ermilov.endif 11621159d16SRuslan Ermilov.endif 11721159d16SRuslan Ermilov 1189608d7e2SRuslan Ermilov.if make(double_quotes) 1199608d7e2SRuslan ErmilovVALUE= foo "" 1209608d7e2SRuslan Ermilovdouble_quotes: 1219608d7e2SRuslan Ermilov.if ${VALUE:S/$//} != ${VALUE} 1229608d7e2SRuslan Ermilov.error "" reduced to " 1239608d7e2SRuslan Ermilov.endif 1249608d7e2SRuslan Ermilov.endif 1259608d7e2SRuslan Ermilov 12699d3652eSRuslan Ermilov.if make(double_quotes2) 12799d3652eSRuslan Ermilovdouble_quotes2: 12899d3652eSRuslan Ermilov @cat /dev/null "" 12999d3652eSRuslan Ermilov.endif 13099d3652eSRuslan Ermilov 13148ec21e7SHartmut Brandt# 13248ec21e7SHartmut Brandt# Check passing of variable via MAKEFLAGS 13348ec21e7SHartmut Brandt# 13448ec21e7SHartmut Brandt.if make(pass_cmd_vars) 13548ec21e7SHartmut Brandtpass_cmd_vars: 13648ec21e7SHartmut Brandt @${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_1 13748ec21e7SHartmut Brandt @${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_2 13848ec21e7SHartmut Brandt @${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_3 13948ec21e7SHartmut Brandt @${MAKE} CMD1=cmd1 CMD2=cmd2 pass_cmd_vars_4 14048ec21e7SHartmut Brandt.endif 14148ec21e7SHartmut Brandt 14248ec21e7SHartmut Brandt.if make(pass_cmd_vars_1) 14348ec21e7SHartmut Brandt# Check that the variable definition arrived from the calling make 14448ec21e7SHartmut Brandtpass_cmd_vars_1: 14548ec21e7SHartmut Brandt @: 14648ec21e7SHartmut Brandt 14748ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2 14882eb7072SHartmut Brandt.error variables not passed through MAKEFLAGS 14948ec21e7SHartmut Brandt.endif 15048ec21e7SHartmut Brandt 15148ec21e7SHartmut Brandt# Check that the variable definition is in MAKEFLAGS 15248ec21e7SHartmut Brandt.if ${.MAKEFLAGS:MCMD1=*} != "CMD1=cmd1" || ${.MAKEFLAGS:MCMD2=*} != "CMD2=cmd2" 15382eb7072SHartmut Brandt.error variable assignment not found in $${MAKEFLAGS} 15448ec21e7SHartmut Brandt.endif 15548ec21e7SHartmut Brandt 15648ec21e7SHartmut Brandt# Check that the variable definition is not in MFLAGS 15748ec21e7SHartmut Brandt.if ${MFLAGS:MCMD1=*} != "" || ${MFLAGS:MCMD2=*} != "" 15882eb7072SHartmut Brandt.error variable assignment found in $${MFLAGS} 15948ec21e7SHartmut Brandt.endif 16048ec21e7SHartmut Brandt.endif 16148ec21e7SHartmut Brandt 16248ec21e7SHartmut Brandt.if make(pass_cmd_vars_2) 16348ec21e7SHartmut Brandt# Check that we cannot override the passed variables 16448ec21e7SHartmut BrandtCMD1=foo1 16548ec21e7SHartmut BrandtCMD2=foo2 16648ec21e7SHartmut Brandt 16748ec21e7SHartmut Brandt.if ${CMD1} != cmd1 || ${CMD2} != cmd2 16882eb7072SHartmut Brandt.error MAKEFLAGS-passed variables overridden 16948ec21e7SHartmut Brandt.endif 17048ec21e7SHartmut Brandt 17148ec21e7SHartmut Brandtpass_cmd_vars_2: 17248ec21e7SHartmut Brandt @: 17348ec21e7SHartmut Brandt.endif 17448ec21e7SHartmut Brandt 17548ec21e7SHartmut Brandt.if make(pass_cmd_vars_3) 17648ec21e7SHartmut Brandt# Check that we can override the passed variables on the next sub-make's 17748ec21e7SHartmut Brandt# command line 17848ec21e7SHartmut Brandt 17948ec21e7SHartmut Brandtpass_cmd_vars_3: 18048ec21e7SHartmut Brandt @${MAKE} CMD1=foo1 pass_cmd_vars_3_1 18148ec21e7SHartmut Brandt.endif 18248ec21e7SHartmut Brandt 18348ec21e7SHartmut Brandt.if make(pass_cmd_vars_3_1) 18448ec21e7SHartmut Brandt.if ${CMD1} != foo1 || ${CMD2} != cmd2 18582eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden on command line 18648ec21e7SHartmut Brandt.endif 18748ec21e7SHartmut Brandtpass_cmd_vars_3_1: 18848ec21e7SHartmut Brandt @: 18948ec21e7SHartmut Brandt.endif 19048ec21e7SHartmut Brandt 19148ec21e7SHartmut Brandt.if make(pass_cmd_vars_4) 19248ec21e7SHartmut Brandt# Ensure that a variable assignment passed via MAKEFLAGS may be overwritten 19348ec21e7SHartmut Brandt# by evaluating the .MAKEFLAGS target. 19448ec21e7SHartmut Brandt 19548ec21e7SHartmut Brandt.MAKEFLAGS: CMD1=baz1 19648ec21e7SHartmut Brandt 19748ec21e7SHartmut Brandtpass_cmd_vars_4: 198215431deSHartmut Brandt @${MAKE} pass_cmd_vars_4_1 19948ec21e7SHartmut Brandt 20048ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2 20182eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target 20248ec21e7SHartmut Brandt.endif 20348ec21e7SHartmut Brandt 20448ec21e7SHartmut Brandt.endif 20548ec21e7SHartmut Brandt.if make(pass_cmd_vars_4_1) 20648ec21e7SHartmut Brandt.if ${CMD1} != baz1 || ${CMD2} != cmd2 20782eb7072SHartmut Brandt.error MAKEFLAGS-passed variables not overridden via .MAKEFLAGS target (2) 20848ec21e7SHartmut Brandt.endif 20948ec21e7SHartmut Brandtpass_cmd_vars_4_1: 21048ec21e7SHartmut Brandt @: 21148ec21e7SHartmut Brandt.endif 21248ec21e7SHartmut Brandt 213c997f47bSHartmut Brandt# 214c997f47bSHartmut Brandt# Test whether make supports the '+' flag (meaning: execute even with -n) 215c997f47bSHartmut Brandt# 216c997f47bSHartmut Brandt.if make(plus_flag) 217c997f47bSHartmut BrandtOUT != ${MAKE} -n plus_flag_1 218c997f47bSHartmut Brandt.if ${OUT} != "/tmp" 21982eb7072SHartmut Brandt.error make doesn't handle + flag 220c997f47bSHartmut Brandt.endif 221c997f47bSHartmut Brandtplus_flag: 222c997f47bSHartmut Brandt @: 223c997f47bSHartmut Brandt.endif 224c997f47bSHartmut Brandt.if make(plus_flag_1) 225c997f47bSHartmut Brandtplus_flag_1: 226c997f47bSHartmut Brandt +@cd /tmp; pwd 227c997f47bSHartmut Brandt.endif 228c997f47bSHartmut Brandt 2299a5cf326SRuslan Ermilov.if make(shell) 2309a5cf326SRuslan Ermilov# Test if make fully supports the .SHELL specification. 2319a5cf326SRuslan Ermilov.SHELL: path=/nonexistent 2329a5cf326SRuslan ErmilovA!= echo ok 2339a5cf326SRuslan Ermilovshell: 2349a5cf326SRuslan Ermilov.endif 2359a5cf326SRuslan Ermilov 2366541d27cSJuli Mallettfailure: 23700e13b1dSNik Clayton @echo "not ok # Test failed: regression detected. See above." 2386541d27cSJuli Mallett @false 239