2004-09-22 04:36:17 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
|
|
|
|
$description = "Test pattern rules.";
|
|
|
|
|
|
|
|
$details = "";
|
|
|
|
|
2005-03-10 09:14:09 +00:00
|
|
|
use Cwd;
|
|
|
|
|
|
|
|
$dir = cwd;
|
|
|
|
$dir =~ s,.*/([^/]+)$,../$1,;
|
|
|
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
# 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.
|
2005-03-04 14:31:09 +00:00
|
|
|
#
|
2004-09-22 04:36:17 +00:00
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
run_make_test(q!
|
2004-09-22 04:36:17 +00:00
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
all: case.1 case.2 case.3
|
2009-06-10 02:21:09 +00:00
|
|
|
|
|
|
|
# We can't have this, due to "Implicit Rule Search Algorithm" step 5c
|
|
|
|
#xxx: void
|
2004-09-22 04:36:17 +00:00
|
|
|
|
|
|
|
# 1 - existing file
|
|
|
|
%.1: void
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 1
|
2004-09-22 04:36:17 +00:00
|
|
|
%.1: #MAKEFILE#
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 0
|
2004-09-22 04:36:17 +00:00
|
|
|
|
|
|
|
# 2 - phony
|
|
|
|
%.2: void
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 1
|
2004-09-22 04:36:17 +00:00
|
|
|
%.2: 2.phony
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 0
|
2004-09-22 04:36:17 +00:00
|
|
|
.PHONY: 2.phony
|
|
|
|
|
|
|
|
# 3 - implicit-phony
|
|
|
|
%.3: void
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 1
|
2004-09-22 04:36:17 +00:00
|
|
|
%.3: 3.implicit-phony
|
2005-07-04 03:50:59 +00:00
|
|
|
@exit 0
|
2004-09-22 04:36:17 +00:00
|
|
|
|
|
|
|
3.implicit-phony:
|
2009-06-10 02:21:09 +00:00
|
|
|
!, '', '');
|
2005-03-04 14:31:09 +00:00
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
# TEST #1: make sure files that are built via implicit rules are marked
|
2005-03-04 14:31:09 +00:00
|
|
|
# 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');
|
2004-09-22 04:36:17 +00:00
|
|
|
|
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
# TEST #2: make sure intermediate files that also happened to be
|
2005-03-10 09:14:09 +00:00
|
|
|
# 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");
|
|
|
|
|
2005-05-31 20:54:30 +00:00
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
# TEST #3: make sure precious flag is set properly for targets
|
2005-05-31 20:54:30 +00:00
|
|
|
# that are built via implicit rules (Savannah bug #13218).
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
|
|
|
.PRECIOUS: %.bar
|
|
|
|
|
2005-06-27 22:18:47 +00:00
|
|
|
%.bar:; @touch $@ && exit 1
|
2005-05-31 20:54:30 +00:00
|
|
|
|
|
|
|
$(dir)/foo.bar:
|
|
|
|
|
|
|
|
',
|
|
|
|
"dir=$dir",
|
2012-03-04 00:24:20 +00:00
|
|
|
"#MAKEFILE#:6: recipe for target '$dir/foo.bar' failed
|
2010-08-29 23:05:26 +00:00
|
|
|
#MAKE#: *** [$dir/foo.bar] Error 1",
|
2005-05-31 20:54:30 +00:00
|
|
|
512);
|
|
|
|
|
|
|
|
unlink("$dir/foo.bar");
|
|
|
|
|
2005-12-09 16:46:19 +00:00
|
|
|
|
2007-03-20 03:02:26 +00:00
|
|
|
# TEST #4: make sure targets of a matched implicit pattern rule are
|
2005-12-09 16:46:19 +00:00
|
|
|
# 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');
|
|
|
|
|
2009-06-04 06:30:27 +00:00
|
|
|
# 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");
|
|
|
|
|
2009-06-10 02:21:09 +00:00
|
|
|
# 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");
|
|
|
|
|
|
|
|
|
2009-09-24 02:41:44 +00:00
|
|
|
# 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',
|
2012-03-04 00:24:20 +00:00
|
|
|
"#MAKE#: *** No rule to make target 'foo.tex'. Stop.", 512);
|
2009-09-24 02:41:44 +00:00
|
|
|
|
|
|
|
unlink(@f);
|
|
|
|
|
2009-09-28 12:31:55 +00:00
|
|
|
# TEST #9: Test shortest stem selection in pattern rules.
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
%.x: ;@echo one
|
|
|
|
%-mt.x: ;@echo two
|
|
|
|
|
|
|
|
all: foo.x foo-mt.x
|
|
|
|
',
|
|
|
|
'',
|
|
|
|
"one\ntwo");
|
|
|
|
|
|
|
|
1;
|
2009-09-24 02:41:44 +00:00
|
|
|
|
2004-09-22 04:36:17 +00:00
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|