1 # -*-perl-*- 2 $description = "Test target-specific variable settings."; 3 4 $details = "\ 5 Create a makefile containing various flavors of target-specific variable 6 values, override and non-override, and using various variable expansion 7 rules, semicolon interference, etc."; 8 9 open(MAKEFILE,"> $makefile"); 10 11 print MAKEFILE <<'EOF'; 12 SHELL = /bin/sh 13 export FOO = foo 14 export BAR = bar 15 one: override FOO = one 16 one two: ; @echo $(FOO) $(BAR) 17 two: BAR = two 18 three: ; BAR=1000 19 @echo $(FOO) $(BAR) 20 # Some things that shouldn't be target vars 21 funk : override 22 funk : override adelic 23 adelic override : ; echo $@ 24 # Test per-target recursive variables 25 four:FOO=x 26 four:VAR$(FOO)=ok 27 four: ; @echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)' 28 five:FOO=x 29 five six : VAR$(FOO)=good 30 five six: ;@echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)' 31 # Test per-target variable inheritance 32 seven: eight 33 seven eight: ; @echo $@: $(FOO) $(BAR) 34 seven: BAR = seven 35 seven: FOO = seven 36 eight: BAR = eight 37 # Test the export keyword with per-target variables 38 nine: ; @echo $(FOO) $(BAR) $$FOO $$BAR 39 nine: FOO = wallace 40 nine-a: export BAZ = baz 41 nine-a: ; @echo $$BAZ 42 # Test = escaping 43 EQ = = 44 ten: one\=two 45 ten: one \= two 46 ten one$(EQ)two $(EQ):;@echo $@ 47 .PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two 48 # Test target-specific vars with pattern/suffix rules 49 QVAR = qvar 50 RVAR = = 51 %.q : ; @echo $(QVAR) $(RVAR) 52 foo.q : RVAR += rvar 53 # Target-specific vars with multiple LHS pattern rules 54 %.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR) 55 foo.r : RVAR += rvar 56 foo.t : TVAR := $(QVAR) 57 EOF 58 59 close(MAKEFILE); 60 61 # TEST #1 62 63 &run_make_with_options($makefile, "one two three", &get_logfile); 64 $answer = "one bar\nfoo two\nBAR=1000\nfoo bar\n"; 65 &compare_output($answer,&get_logfile(1)); 66 67 # TEST #2 68 69 &run_make_with_options($makefile, "one two FOO=1 BAR=2", &get_logfile); 70 $answer = "one 2\n1 2\n"; 71 &compare_output($answer,&get_logfile(1)); 72 73 # TEST #3 74 75 &run_make_with_options($makefile, "four", &get_logfile); 76 $answer = "x ok ok\n"; 77 &compare_output($answer,&get_logfile(1)); 78 79 # TEST #4 80 81 &run_make_with_options($makefile, "seven", &get_logfile); 82 $answer = "eight: seven eight\nseven: seven seven\n"; 83 &compare_output($answer,&get_logfile(1)); 84 85 # TEST #5 86 87 &run_make_with_options($makefile, "nine", &get_logfile); 88 $answer = "wallace bar wallace bar\n"; 89 &compare_output($answer,&get_logfile(1)); 90 91 # TEST #5-a 92 93 &run_make_with_options($makefile, "nine-a", &get_logfile); 94 $answer = "baz\n"; 95 &compare_output($answer,&get_logfile(1)); 96 97 # TEST #6 98 99 &run_make_with_options($makefile, "ten", &get_logfile); 100 $answer = "one=two\none bar\n=\nfoo two\nten\n"; 101 &compare_output($answer,&get_logfile(1)); 102 103 # TEST #6 104 105 &run_make_with_options($makefile, "foo.q bar.q", &get_logfile); 106 $answer = "qvar = rvar\nqvar =\n"; 107 &compare_output($answer,&get_logfile(1)); 108 109 # TEST #7 110 111 &run_make_with_options($makefile, "foo.t bar.s", &get_logfile); 112 $answer = "qvar = qvar\nqvar =\n"; 113 &compare_output($answer,&get_logfile(1)); 114 115 116 # TEST #8 117 # For PR/1378: Target-specific vars don't inherit correctly 118 119 $makefile2 = &get_tmpfile; 120 121 open(MAKEFILE,"> $makefile2"); 122 print MAKEFILE <<'EOF'; 123 foo: FOO = foo 124 bar: BAR = bar 125 foo: bar 126 bar: baz 127 baz: ; @echo $(FOO) $(BAR) 128 EOF 129 close(MAKEFILE); 130 131 &run_make_with_options("$makefile2", "", &get_logfile); 132 $answer = "foo bar\n"; 133 &compare_output($answer, &get_logfile(1)); 134 135 # TEST #9 136 # For PR/1380: Using += assignment in target-specific variables sometimes fails 137 # Also PR/1831 138 139 $makefile3 = &get_tmpfile; 140 141 open(MAKEFILE,"> $makefile3"); 142 print MAKEFILE <<'EOF'; 143 .PHONY: all one 144 all: FOO += baz 145 all: one; @echo $(FOO) 146 147 FOO = bar 148 149 one: FOO += biz 150 one: FOO += boz 151 one: ; @echo $(FOO) 152 EOF 153 close(MAKEFILE); 154 155 &run_make_with_options("$makefile3", "", &get_logfile); 156 $answer = "bar baz biz boz\nbar baz\n"; 157 &compare_output($answer, &get_logfile(1)); 158 159 # Test #10 160 161 &run_make_with_options("$makefile3", "one", &get_logfile); 162 $answer = "bar biz boz\n"; 163 &compare_output($answer, &get_logfile(1)); 164 165 # Test #11 166 # PR/1709: Test semicolons in target-specific variable values 167 168 $makefile4 = &get_tmpfile; 169 170 open(MAKEFILE, "> $makefile4"); 171 print MAKEFILE <<'EOF'; 172 foo : FOO = ; ok 173 foo : ; @echo '$(FOO)' 174 EOF 175 close(MAKEFILE); 176 177 &run_make_with_options("$makefile4", "", &get_logfile); 178 $answer = "; ok\n"; 179 &compare_output($answer, &get_logfile(1)); 180 181 # Test #12 182 # PR/2020: More hassles with += target-specific vars. I _really_ think 183 # I nailed it this time :-/. 184 185 $makefile5 = &get_tmpfile; 186 187 open(MAKEFILE, "> $makefile5"); 188 print MAKEFILE <<'EOF'; 189 .PHONY: a 190 191 BLAH := foo 192 COMMAND = echo $(BLAH) 193 194 a: ; @$(COMMAND) 195 196 a: BLAH := bar 197 a: COMMAND += snafu $(BLAH) 198 EOF 199 close(MAKEFILE); 200 201 &run_make_with_options("$makefile5", "", &get_logfile); 202 $answer = "bar snafu bar\n"; 203 &compare_output($answer, &get_logfile(1)); 204 205 # Test #13 206 # Test double-colon rules with target-specific variable values 207 208 $makefile6 = &get_tmpfile; 209 210 open(MAKEFILE, "> $makefile6"); 211 print MAKEFILE <<'EOF'; 212 W = bad 213 X = bad 214 foo: W = ok 215 foo:: ; @echo $(W) $(X) $(Y) $(Z) 216 foo:: ; @echo $(W) $(X) $(Y) $(Z) 217 foo: X = ok 218 219 Y = foo 220 bar: foo 221 bar: Y = bar 222 223 Z = nopat 224 ifdef PATTERN 225 fo% : Z = pat 226 endif 227 228 EOF 229 close(MAKEFILE); 230 231 &run_make_with_options("$makefile6", "foo", &get_logfile); 232 $answer = "ok ok foo nopat\nok ok foo nopat\n"; 233 &compare_output($answer, &get_logfile(1)); 234 235 # Test #14 236 # Test double-colon rules with target-specific variable values and 237 # inheritance 238 239 &run_make_with_options("$makefile6", "bar", &get_logfile); 240 $answer = "ok ok bar nopat\nok ok bar nopat\n"; 241 &compare_output($answer, &get_logfile(1)); 242 243 # Test #15 244 # Test double-colon rules with pattern-specific variable values 245 246 &run_make_with_options("$makefile6", "foo PATTERN=yes", &get_logfile); 247 $answer = "ok ok foo pat\nok ok foo pat\n"; 248 &compare_output($answer, &get_logfile(1)); 249 250 251 # Test #16 252 # Test target-specific variables with very long command line 253 # (> make default buffer length) 254 255 $makefile7 = &get_tmpfile; 256 257 open(MAKEFILE, "> $makefile7"); 258 print MAKEFILE <<'EOF'; 259 base_metals_fmd_reports.sun5 base_metals_fmd_reports CreateRealPositions CreateMarginFunds deals_changed_since : BUILD_OBJ=$(shell if [ -f "build_information.generate" ]; then echo "$(OBJ_DIR)/build_information.o"; else echo "no build information"; fi ) 260 261 deals_changed_since: ; @echo $(BUILD_OBJ) 262 263 EOF 264 close(MAKEFILE); 265 266 &run_make_with_options("$makefile7", '', &get_logfile); 267 $answer = "no build information\n"; 268 &compare_output($answer, &get_logfile(1)); 269 270 # TEST #17 271 272 # Test a merge of set_lists for files, where one list is much longer 273 # than the other. See Savannah bug #15757. 274 275 mkdir('t1', 0777); 276 touch('t1/rules.mk'); 277 278 run_make_test(' 279 VPATH = t1 280 include rules.mk 281 .PHONY: all 282 all: foo.x 283 foo.x : rules.mk ; @echo MYVAR=$(MYVAR) FOOVAR=$(FOOVAR) ALLVAR=$(ALLVAR) 284 all: ALLVAR = xxx 285 foo.x: FOOVAR = bar 286 rules.mk : MYVAR = foo 287 .INTERMEDIATE: foo.x rules.mk 288 ', 289 '-I t1', 290 'MYVAR= FOOVAR=bar ALLVAR=xxx'); 291 292 rmfiles('t1/rules.mk'); 293 rmdir('t1'); 294 295 # TEST #18 296 297 # Test appending to a simple variable containing a "$": avoid a 298 # double-expansion. See Savannah bug #15913. 299 300 run_make_test(" 301 VAR := \$\$FOO 302 foo: VAR += BAR 303 foo: ; \@echo '\$(VAR)'", 304 '', 305 '$FOO BAR'); 306 307 1; 308