| 1 | # -*-perl-*-
|
|---|
| 2 |
|
|---|
| 3 | $description = "Test pattern rules.";
|
|---|
| 4 |
|
|---|
| 5 | $details = "";
|
|---|
| 6 |
|
|---|
| 7 | use Cwd;
|
|---|
| 8 |
|
|---|
| 9 | $dir = cwd;
|
|---|
| 10 | $dir =~ s,.*/([^/]+)$,../$1,;
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | # TEST #0: Make sure that multiple patterns where the same target
|
|---|
| 14 | # can be built are searched even if the first one fails
|
|---|
| 15 | # to match properly.
|
|---|
| 16 | #
|
|---|
| 17 |
|
|---|
| 18 | run_make_test(q!
|
|---|
| 19 | .PHONY: all
|
|---|
| 20 |
|
|---|
| 21 | all: case.1 case.2 case.3
|
|---|
| 22 |
|
|---|
| 23 | # We can't have this, due to "Implicit Rule Search Algorithm" step 5c
|
|---|
| 24 | #xxx: void
|
|---|
| 25 |
|
|---|
| 26 | # 1 - existing file
|
|---|
| 27 | %.1: void
|
|---|
| 28 | @exit 1
|
|---|
| 29 | %.1: #MAKEFILE#
|
|---|
| 30 | @exit 0
|
|---|
| 31 |
|
|---|
| 32 | # 2 - phony
|
|---|
| 33 | %.2: void
|
|---|
| 34 | @exit 1
|
|---|
| 35 | %.2: 2.phony
|
|---|
| 36 | @exit 0
|
|---|
| 37 | .PHONY: 2.phony
|
|---|
| 38 |
|
|---|
| 39 | # 3 - implicit-phony
|
|---|
| 40 | %.3: void
|
|---|
| 41 | @exit 1
|
|---|
| 42 | %.3: 3.implicit-phony
|
|---|
| 43 | @exit 0
|
|---|
| 44 |
|
|---|
| 45 | 3.implicit-phony:
|
|---|
| 46 | !, '', '');
|
|---|
| 47 |
|
|---|
| 48 | # TEST #1: make sure files that are built via implicit rules are marked
|
|---|
| 49 | # as targets (Savannah bug #12202).
|
|---|
| 50 | #
|
|---|
| 51 | run_make_test('
|
|---|
| 52 | TARGETS := foo foo.out
|
|---|
| 53 |
|
|---|
| 54 | .PHONY: all foo.in
|
|---|
| 55 |
|
|---|
| 56 | all: $(TARGETS)
|
|---|
| 57 |
|
|---|
| 58 | %: %.in
|
|---|
| 59 | @echo $@
|
|---|
| 60 |
|
|---|
| 61 | %.out: %
|
|---|
| 62 | @echo $@
|
|---|
| 63 |
|
|---|
| 64 | foo.in: ; @:
|
|---|
| 65 |
|
|---|
| 66 | ',
|
|---|
| 67 | '',
|
|---|
| 68 | 'foo
|
|---|
| 69 | foo.out');
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | # TEST #2: make sure intermediate files that also happened to be
|
|---|
| 73 | # prerequisites are not removed (Savannah bug #12267).
|
|---|
| 74 | #
|
|---|
| 75 | run_make_test('
|
|---|
| 76 | $(dir)/foo.o:
|
|---|
| 77 |
|
|---|
| 78 | $(dir)/foo.y:
|
|---|
| 79 | @echo $@
|
|---|
| 80 |
|
|---|
| 81 | %.c: %.y
|
|---|
| 82 | touch $@
|
|---|
| 83 |
|
|---|
| 84 | %.o: %.c
|
|---|
| 85 | @echo $@
|
|---|
| 86 |
|
|---|
| 87 | .PHONY: install
|
|---|
| 88 | install: $(dir)/foo.c
|
|---|
| 89 |
|
|---|
| 90 | ',
|
|---|
| 91 | "dir=$dir",
|
|---|
| 92 | "$dir/foo.y
|
|---|
| 93 | touch $dir/foo.c
|
|---|
| 94 | $dir/foo.o");
|
|---|
| 95 |
|
|---|
| 96 | unlink("$dir/foo.c");
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | # TEST #3: make sure precious flag is set properly for targets
|
|---|
| 100 | # that are built via implicit rules (Savannah bug #13218).
|
|---|
| 101 | #
|
|---|
| 102 | run_make_test('
|
|---|
| 103 | .DELETE_ON_ERROR:
|
|---|
| 104 |
|
|---|
| 105 | .PRECIOUS: %.bar
|
|---|
| 106 |
|
|---|
| 107 | %.bar:; @touch $@ && exit 1
|
|---|
| 108 |
|
|---|
| 109 | $(dir)/foo.bar:
|
|---|
| 110 |
|
|---|
| 111 | ',
|
|---|
| 112 | "dir=$dir",
|
|---|
| 113 | (!$is_kmk) ?
|
|---|
| 114 | "#MAKE#: *** [#MAKEFILE#:6: $dir/foo.bar] Error 1":
|
|---|
| 115 | "#MAKE#: *** [$dir/foo.bar] Error 1" . '
|
|---|
| 116 | The failing command:
|
|---|
| 117 | @touch $@ && exit 1',
|
|---|
| 118 | 512);
|
|---|
| 119 |
|
|---|
| 120 | unlink("$dir/foo.bar");
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | # TEST #4: make sure targets of a matched implicit pattern rule are
|
|---|
| 124 | # never considered intermediate (Savannah bug #13022).
|
|---|
| 125 | #
|
|---|
| 126 | run_make_test('
|
|---|
| 127 | .PHONY: all
|
|---|
| 128 | all: foo.c foo.o
|
|---|
| 129 |
|
|---|
| 130 | %.h %.c: %.in
|
|---|
| 131 | touch $*.h
|
|---|
| 132 | touch $*.c
|
|---|
| 133 |
|
|---|
| 134 | %.o: %.c %.h
|
|---|
| 135 | echo $+ >$@
|
|---|
| 136 |
|
|---|
| 137 | %.o: %.c
|
|---|
| 138 | @echo wrong rule
|
|---|
| 139 |
|
|---|
| 140 | foo.in:
|
|---|
| 141 | touch $@
|
|---|
| 142 |
|
|---|
| 143 | ',
|
|---|
| 144 | '-j1',
|
|---|
| 145 | 'touch foo.in
|
|---|
| 146 | touch foo.h
|
|---|
| 147 | touch foo.c
|
|---|
| 148 | echo foo.c foo.h >foo.o');
|
|---|
| 149 |
|
|---|
| 150 | unlink('foo.in', 'foo.h', 'foo.c', 'foo.o');
|
|---|
| 151 |
|
|---|
| 152 | # TEST #5: make sure both prefix and suffix patterns work with multiple
|
|---|
| 153 | # target patterns (Savannah bug #26593).
|
|---|
| 154 | #
|
|---|
| 155 | run_make_test('
|
|---|
| 156 | all: foo.s1 foo.s2 p1.foo p2.foo
|
|---|
| 157 |
|
|---|
| 158 | p1.% p2.%: %.orig
|
|---|
| 159 | @echo $@
|
|---|
| 160 | %.s1 %.s2: %.orig
|
|---|
| 161 | @echo $@
|
|---|
| 162 |
|
|---|
| 163 | .PHONY: foo.orig
|
|---|
| 164 | ',
|
|---|
| 165 | '', "foo.s1\np1.foo\n");
|
|---|
| 166 |
|
|---|
| 167 | # TEST 6: Make sure that non-target files are still eligible to be created
|
|---|
| 168 | # as part of implicit rule chaining. Savannah bug #17752.
|
|---|
| 169 |
|
|---|
| 170 | run_make_test(q!
|
|---|
| 171 | BIN = xyz
|
|---|
| 172 | COPY = $(BIN).cp
|
|---|
| 173 | SRC = $(BIN).c
|
|---|
| 174 | allbroken: $(COPY) $(BIN) ; @echo ok
|
|---|
| 175 | $(SRC): ; @echo 'main(){}' > $@
|
|---|
| 176 | %.cp: % ; @cp $< $@
|
|---|
| 177 | % : %.c ; @cp $< $@
|
|---|
| 178 | clean: ; @rm -rf $(SRC) $(COPY) $(BIN)
|
|---|
| 179 | !,
|
|---|
| 180 | '', "ok\n");
|
|---|
| 181 |
|
|---|
| 182 | unlink(qw(xyz xyz.cp xyz.c));
|
|---|
| 183 |
|
|---|
| 184 | # TEST 7: Make sure that all prereqs of all "also_make" targets get created
|
|---|
| 185 | # before any of the things that depend on any of them. Savannah bug #19108.
|
|---|
| 186 |
|
|---|
| 187 | run_make_test(q!
|
|---|
| 188 | final: x ; @echo $@
|
|---|
| 189 | x: x.t1 x.t2 ; @echo $@
|
|---|
| 190 | x.t2: dep
|
|---|
| 191 | dep: ; @echo $@
|
|---|
| 192 | %.t1 %.t2: ; @echo $*.t1 ; echo $*.t2
|
|---|
| 193 | !,
|
|---|
| 194 | '', "dep\nx.t1\nx.t2\nx\nfinal\n");
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | # TEST 8: Verify we can remove pattern rules. Savannah bug #18622.
|
|---|
| 198 |
|
|---|
| 199 | my @f = (qw(foo.w foo.ch));
|
|---|
| 200 | touch(@f);
|
|---|
| 201 |
|
|---|
| 202 | run_make_test(q!
|
|---|
| 203 | CWEAVE := :
|
|---|
| 204 |
|
|---|
| 205 | # Disable builtin rules
|
|---|
| 206 | %.tex : %.w
|
|---|
| 207 | %.tex : %.w %.ch
|
|---|
| 208 | !,
|
|---|
| 209 | 'foo.tex',
|
|---|
| 210 | "#MAKE#: *** No rule to make target 'foo.tex'. Stop.", 512);
|
|---|
| 211 |
|
|---|
| 212 | unlink(@f);
|
|---|
| 213 |
|
|---|
| 214 | # TEST #9: Test shortest stem selection in pattern rules.
|
|---|
| 215 |
|
|---|
| 216 | run_make_test('
|
|---|
| 217 | %.x: ;@echo one
|
|---|
| 218 | %-mt.x: ;@echo two
|
|---|
| 219 |
|
|---|
| 220 | all: foo.x foo-mt.x
|
|---|
| 221 | ',
|
|---|
| 222 | '',
|
|---|
| 223 | "one\ntwo");
|
|---|
| 224 |
|
|---|
| 225 | 1;
|
|---|
| 226 |
|
|---|
| 227 | # This tells the test driver that the perl test script executed properly.
|
|---|
| 228 | 1;
|
|---|
| 229 |
|
|---|
| 230 | ### Local Variables:
|
|---|
| 231 | ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
|
|---|
| 232 | ### End:
|
|---|