summaryrefslogtreecommitdiff
path: root/tests/scripts/features/patternrules
blob: dcaf0dd027514890720dfb0ce249c1eb5340987c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#                                                                    -*-perl-*-

$description = "Test pattern rules.";

$details = "";

use Cwd;

$dir = cwd;
$dir =~ s,.*/([^/]+)$,../$1,;


# TEST #0: Make sure that multiple patterns where the same target
#          can be built are searched even if the first one fails
#          to match properly.
#

run_make_test(q!
.PHONY: all

all: case.1 case.2 case.3

# We can't have this, due to "Implicit Rule Search Algorithm" step 5c
#xxx: void

# 1 - existing file
%.1: void
	@exit 1
%.1: #MAKEFILE#
	@exit 0

# 2 - phony
%.2: void
	@exit 1
%.2: 2.phony
	@exit 0
.PHONY: 2.phony

# 3 - implicit-phony
%.3: void
	@exit 1
%.3: 3.implicit-phony
	@exit 0

3.implicit-phony:
!, '', '');

# TEST #1: make sure files that are built via implicit rules are marked
#          as targets (Savannah bug #12202).
#
run_make_test('
TARGETS := foo foo.out

.PHONY: all foo.in

all: $(TARGETS)

%: %.in
	@echo $@

%.out: %
	@echo $@

foo.in: ; @:

',
'',
'foo
foo.out');


# TEST #2: make sure intermediate files that also happened to be
#          prerequisites are not removed (Savannah bug #12267).
#
run_make_test('
$(dir)/foo.o:

$(dir)/foo.y:
	@echo $@

%.c: %.y
	touch $@

%.o: %.c
	@echo $@

.PHONY: install
install: $(dir)/foo.c

',
"dir=$dir",
"$dir/foo.y
touch $dir/foo.c
$dir/foo.o");

unlink("$dir/foo.c");


# TEST #3: make sure precious flag is set properly for targets
#          that are built via implicit rules (Savannah bug #13218).
#
run_make_test('
.DELETE_ON_ERROR:

.PRECIOUS: %.bar

%.bar:; @touch $@ && exit 1

$(dir)/foo.bar:

',
"dir=$dir",
"#MAKE#: *** [$dir/foo.bar] Error 1",
512);

unlink("$dir/foo.bar");


# TEST #4: make sure targets of a matched implicit pattern rule are
#          never considered intermediate (Savannah bug #13022).
#
run_make_test('
.PHONY: all
all: foo.c foo.o

%.h %.c: %.in
	touch $*.h
	touch $*.c

%.o: %.c %.h
	echo $+ >$@

%.o: %.c
	@echo wrong rule

foo.in:
	touch $@

',
'',
'touch foo.in
touch foo.h
touch foo.c
echo foo.c foo.h >foo.o');

unlink('foo.in', 'foo.h', 'foo.c', 'foo.o');

# TEST #5: make sure both prefix and suffix patterns work with multiple
#          target patterns (Savannah bug #26593).
#
run_make_test('
all: foo.s1 foo.s2 p1.foo p2.foo

p1.% p2.%: %.orig
	@echo $@
%.s1 %.s2: %.orig
	@echo $@

.PHONY: foo.orig
',
              '', "foo.s1\np1.foo\n");

# TEST 6: Make sure that non-target files are still eligible to be created
# as part of implicit rule chaining.  Savannah bug #17752.

run_make_test(q!
BIN = xyz
COPY = $(BIN).cp
SRC = $(BIN).c
allbroken: $(COPY) $(BIN) ; @echo ok
$(SRC): ; @echo 'main(){}' > $@
%.cp: % ; @cp $< $@
% : %.c ; @cp $< $@
clean: ; @rm -rf $(SRC) $(COPY) $(BIN)
!,
              '', "ok\n");

unlink(qw(xyz xyz.cp xyz.c));

# TEST 7: Make sure that all prereqs of all "also_make" targets get created
# before any of the things that depend on any of them.  Savannah bug #19108.

run_make_test(q!
final: x ; @echo $@
x: x.t1 x.t2 ; @echo $@
x.t2: dep
dep: ; @echo $@
%.t1 %.t2: ; @echo $*.t1 ; echo $*.t2
!,
              '', "dep\nx.t1\nx.t2\nx\nfinal\n");


# TEST 8: Verify we can remove pattern rules.  Savannah bug #18622.

my @f = (qw(foo.w foo.ch));
touch(@f);

run_make_test(q!
CWEAVE := :

# Disable builtin rules
%.tex : %.w
%.tex : %.w %.ch
!,
              'foo.tex',
              "#MAKE#: *** No rule to make target `foo.tex'.  Stop.", 512);

unlink(@f);


# This tells the test driver that the perl test script executed properly.
1;