1# -*-perl-*- 2$description = "Test pattern-specific variable settings."; 3 4$details = "\ 5Create a makefile containing various flavors of pattern-specific variable 6settings, override and non-override, and using various variable expansion 7rules, semicolon interference, etc."; 8 9open(MAKEFILE,"> $makefile"); 10 11print MAKEFILE <<'EOF'; 12all: one.x two.x three.x 13FOO = foo 14BAR = bar 15BAZ = baz 16one.x: override FOO = one 17%.x: BAR = two 18t%.x: BAR = four 19thr% : override BAZ = three 20one.x two.x three.x: ; @echo $@: $(FOO) $(BAR) $(BAZ) 21four.x: baz ; @echo $@: $(FOO) $(BAR) $(BAZ) 22baz: ; @echo $@: $(FOO) $(BAR) $(BAZ) 23 24# test matching multiple patterns 25a%: AAA = aaa 26%b: BBB = ccc 27a%: BBB += ddd 28%b: AAA ?= xxx 29%b: AAA += bbb 30.PHONY: ab 31ab: ; @echo $(AAA); echo $(BBB) 32EOF 33 34close(MAKEFILE); 35 36 37# TEST #1 -- basics 38 39&run_make_with_options($makefile, "", &get_logfile); 40$answer = "one.x: one two baz\ntwo.x: foo four baz\nthree.x: foo four three\n"; 41&compare_output($answer,&get_logfile(1)); 42 43 44# TEST #2 -- try the override feature 45 46&run_make_with_options($makefile, "BAZ=five", &get_logfile); 47$answer = "one.x: one two five\ntwo.x: foo four five\nthree.x: foo four three\n"; 48&compare_output($answer,&get_logfile(1)); 49 50 51# TEST #3 -- make sure patterns are inherited properly 52 53&run_make_with_options($makefile, "four.x", &get_logfile); 54$answer = "baz: foo two baz\nfour.x: foo two baz\n"; 55&compare_output($answer,&get_logfile(1)); 56 57 58# TEST #4 -- test multiple patterns matching the same target 59 60&run_make_with_options($makefile, "ab", &get_logfile); 61$answer = "aaa bbb\nccc ddd\n"; 62&compare_output($answer,&get_logfile(1)); 63 64# TEST #5 -- test pattern-specific exported variables 65# 66run_make_test(' 67/%: export foo := foo 68 69/bar: 70 @echo $(foo) $$foo 71', '', 'foo foo'); 72 73 74# TEST #6 -- test expansion of pattern-specific simple variables 75# 76run_make_test(' 77.PHONY: all 78 79all: inherit := good $$t 80all: bar baz 81 82b%: pattern := good $$t 83 84global := orginal $$t 85 86 87# normal target 88# 89ifdef rec 90bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit) 91else 92bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit) 93endif 94 95bar: ; @echo \'normal: $a;\' 96 97 98# pattern target 99# 100ifdef rec 101%z: a = global: $(global) pattern: $(pattern) inherit: $(inherit) 102else 103%z: a := global: $(global) pattern: $(pattern) inherit: $(inherit) 104endif 105 106%z: ; @echo \'pattrn: $a;\' 107 108 109global := new $$t 110', 111'', 112'normal: global: orginal $t pattern: inherit: ; 113pattrn: global: orginal $t pattern: inherit: ;'); 114 115 116# TEST #7 -- test expansion of pattern-specific recursive variables 117# 118run_make_test(undef, # reuse previous makefile 119'rec=1', 120'normal: global: new $t pattern: good $t inherit: good $t; 121pattrn: global: new $t pattern: good $t inherit: good $t;'); 122 123 1241; 125