1*69606e3fSchristos# -*-perl-*- 2*69606e3fSchristos 3*69606e3fSchristos$description = "Test various flavors of make variable setting."; 4*69606e3fSchristos 5*69606e3fSchristos$details = ""; 6*69606e3fSchristos 7*69606e3fSchristosopen(MAKEFILE, "> $makefile"); 8*69606e3fSchristos 9*69606e3fSchristos# The Contents of the MAKEFILE ... 10*69606e3fSchristos 11*69606e3fSchristosprint MAKEFILE <<'EOF'; 12*69606e3fSchristosfoo = $(bar) 13*69606e3fSchristosbar = ${ugh} 14*69606e3fSchristosugh = Hello 15*69606e3fSchristos 16*69606e3fSchristosall: multi ; @echo $(foo) 17*69606e3fSchristos 18*69606e3fSchristosmulti: ; $(multi) 19*69606e3fSchristos 20*69606e3fSchristosx := foo 21*69606e3fSchristosy := $(x) bar 22*69606e3fSchristosx := later 23*69606e3fSchristos 24*69606e3fSchristosnullstring := 25*69606e3fSchristosspace := $(nullstring) $(nullstring) 26*69606e3fSchristos 27*69606e3fSchristosnext: ; @echo $x$(space)$y 28*69606e3fSchristos 29*69606e3fSchristosdefine multi 30*69606e3fSchristos@echo hi 31*69606e3fSchristosecho there 32*69606e3fSchristosendef 33*69606e3fSchristos 34*69606e3fSchristosifdef BOGUS 35*69606e3fSchristosdefine 36*69606e3fSchristos@echo error 37*69606e3fSchristosendef 38*69606e3fSchristosendif 39*69606e3fSchristos 40*69606e3fSchristosdefine outer 41*69606e3fSchristos define inner 42*69606e3fSchristos A = B 43*69606e3fSchristos endef 44*69606e3fSchristosendef 45*69606e3fSchristos 46*69606e3fSchristos$(eval $(outer)) 47*69606e3fSchristos 48*69606e3fSchristosouter: ; @echo $(inner) 49*69606e3fSchristos 50*69606e3fSchristosEOF 51*69606e3fSchristos 52*69606e3fSchristos# END of Contents of MAKEFILE 53*69606e3fSchristos 54*69606e3fSchristosclose(MAKEFILE); 55*69606e3fSchristos 56*69606e3fSchristos# TEST #1 57*69606e3fSchristos# ------- 58*69606e3fSchristos 59*69606e3fSchristos&run_make_with_options($makefile, "", &get_logfile); 60*69606e3fSchristos$answer = "hi\necho there\nthere\nHello\n"; 61*69606e3fSchristos&compare_output($answer, &get_logfile(1)); 62*69606e3fSchristos 63*69606e3fSchristos# TEST #2 64*69606e3fSchristos# ------- 65*69606e3fSchristos 66*69606e3fSchristos&run_make_with_options($makefile, "next", &get_logfile); 67*69606e3fSchristos$answer = "later foo bar\n"; 68*69606e3fSchristos&compare_output($answer, &get_logfile(1)); 69*69606e3fSchristos 70*69606e3fSchristos# TEST #3 71*69606e3fSchristos# ------- 72*69606e3fSchristos 73*69606e3fSchristos&run_make_with_options($makefile, "BOGUS=true", &get_logfile, 512); 74*69606e3fSchristos$answer = "$makefile:24: *** empty variable name. Stop.\n"; 75*69606e3fSchristos&compare_output($answer, &get_logfile(1)); 76*69606e3fSchristos 77*69606e3fSchristos# TEST #4 78*69606e3fSchristos# ------- 79*69606e3fSchristos 80*69606e3fSchristos&run_make_with_options($makefile, "outer", &get_logfile); 81*69606e3fSchristos$answer = "A = B\n"; 82*69606e3fSchristos&compare_output($answer, &get_logfile(1)); 83*69606e3fSchristos 84*69606e3fSchristos# Clean up from "old style" testing. If all the above tests are converted to 85*69606e3fSchristos# run_make_test() syntax than this line can be removed. 86*69606e3fSchristos$makefile = undef; 87*69606e3fSchristos 88*69606e3fSchristos# ------------------------- 89*69606e3fSchristos# Make sure that prefix characters apply properly to define/endef values. 90*69606e3fSchristos# 91*69606e3fSchristos# There's a bit of oddness here if you try to use a variable to hold the 92*69606e3fSchristos# prefix character for a define. Even though something like this: 93*69606e3fSchristos# 94*69606e3fSchristos# define foo 95*69606e3fSchristos# echo bar 96*69606e3fSchristos# endef 97*69606e3fSchristos# 98*69606e3fSchristos# all: ; $(V)$(foo) 99*69606e3fSchristos# 100*69606e3fSchristos# (where V=@) can be seen by the user to be obviously different than this: 101*69606e3fSchristos# 102*69606e3fSchristos# define foo 103*69606e3fSchristos# $(V)echo bar 104*69606e3fSchristos# endef 105*69606e3fSchristos# 106*69606e3fSchristos# all: ; $(foo) 107*69606e3fSchristos# 108*69606e3fSchristos# and the user thinks it should behave the same as when the "@" is literal 109*69606e3fSchristos# instead of in a variable, that can't happen because by the time make 110*69606e3fSchristos# expands the variables for the command line and sees it begins with a "@" it 111*69606e3fSchristos# can't know anymore whether the prefix character came before the variable 112*69606e3fSchristos# reference or was included in the first line of the variable reference. 113*69606e3fSchristos 114*69606e3fSchristos# TEST #5 115*69606e3fSchristos# ------- 116*69606e3fSchristos 117*69606e3fSchristosrun_make_test(' 118*69606e3fSchristosdefine FOO 119*69606e3fSchristos$(V1)echo hello 120*69606e3fSchristos$(V2)echo world 121*69606e3fSchristosendef 122*69606e3fSchristosall: ; @$(FOO) 123*69606e3fSchristos', '', 'hello 124*69606e3fSchristosworld'); 125*69606e3fSchristos 126*69606e3fSchristos# TEST #6 127*69606e3fSchristos# ------- 128*69606e3fSchristos 129*69606e3fSchristosrun_make_test(undef, 'V1=@ V2=@', 'hello 130*69606e3fSchristosworld'); 131*69606e3fSchristos 132*69606e3fSchristos# TEST #7 133*69606e3fSchristos# ------- 134*69606e3fSchristos 135*69606e3fSchristosrun_make_test(' 136*69606e3fSchristosdefine FOO 137*69606e3fSchristos$(V1)echo hello 138*69606e3fSchristos$(V2)echo world 139*69606e3fSchristosendef 140*69606e3fSchristosall: ; $(FOO) 141*69606e3fSchristos', 'V1=@', 'hello 142*69606e3fSchristosecho world 143*69606e3fSchristosworld'); 144*69606e3fSchristos 145*69606e3fSchristos# TEST #8 146*69606e3fSchristos# ------- 147*69606e3fSchristos 148*69606e3fSchristosrun_make_test(undef, 'V2=@', 'echo hello 149*69606e3fSchristoshello 150*69606e3fSchristosworld'); 151*69606e3fSchristos 152*69606e3fSchristos# TEST #9 153*69606e3fSchristos# ------- 154*69606e3fSchristos 155*69606e3fSchristosrun_make_test(undef, 'V1=@ V2=@', 'hello 156*69606e3fSchristosworld'); 157*69606e3fSchristos 158*69606e3fSchristos# TEST #10 159*69606e3fSchristos# ------- 160*69606e3fSchristos# Test the basics; a "@" internally to the variable applies to only one line. 161*69606e3fSchristos# A "@" before the variable applies to the entire variable. 162*69606e3fSchristos 163*69606e3fSchristosrun_make_test(' 164*69606e3fSchristosdefine FOO 165*69606e3fSchristos@echo hello 166*69606e3fSchristosecho world 167*69606e3fSchristosendef 168*69606e3fSchristosdefine BAR 169*69606e3fSchristosecho hello 170*69606e3fSchristosecho world 171*69606e3fSchristosendef 172*69606e3fSchristos 173*69606e3fSchristosall: foo bar 174*69606e3fSchristosfoo: ; $(FOO) 175*69606e3fSchristosbar: ; @$(BAR) 176*69606e3fSchristos', '', 'hello 177*69606e3fSchristosecho world 178*69606e3fSchristosworld 179*69606e3fSchristoshello 180*69606e3fSchristosworld 181*69606e3fSchristos'); 182*69606e3fSchristos 183*69606e3fSchristos1; 184