| 1 |
#! -*-perl-*- |
| 2 |
|
| 3 |
$description = "Test the behaviour of the .SECONDARY target."; |
| 4 |
|
| 5 |
$details = "\ |
| 6 |
Test the behavior of the .SECONDARY special target. |
| 7 |
Create a makefile where a file would not normally be considered |
| 8 |
intermediate, then specify it as .SECONDARY. Build and note that it's |
| 9 |
not automatically deleted. Delete the file. Rebuild to ensure that |
| 10 |
it's not created if it doesn't exist but doesn't need to be built. |
| 11 |
Change the original and ensure that the secondary file and the ultimate |
| 12 |
target are both rebuilt, and that the secondary file is not deleted. |
| 13 |
|
| 14 |
Try this with implicit rules and explicit rules: both should work.\n"; |
| 15 |
|
| 16 |
open(MAKEFILE,"> $makefile"); |
| 17 |
|
| 18 |
print MAKEFILE <<'EOF'; |
| 19 |
|
| 20 |
.SECONDARY: foo.e |
| 21 |
|
| 22 |
# Implicit rule test |
| 23 |
%.d : %.e ; cp $< $@ |
| 24 |
%.e : %.f ; cp $< $@ |
| 25 |
|
| 26 |
foo.d: foo.e |
| 27 |
|
| 28 |
# Explicit rule test |
| 29 |
foo.c: foo.e ; cp $< $@ |
| 30 |
EOF |
| 31 |
|
| 32 |
close(MAKEFILE); |
| 33 |
|
| 34 |
# TEST #1 |
| 35 |
|
| 36 |
&utouch(-20, 'foo.f'); |
| 37 |
|
| 38 |
&run_make_with_options($makefile,'foo.d',&get_logfile); |
| 39 |
$answer = "cp foo.f foo.e\ncp foo.e foo.d\n"; |
| 40 |
&compare_output($answer, &get_logfile(1)); |
| 41 |
|
| 42 |
# TEST #2 |
| 43 |
|
| 44 |
unlink('foo.e'); |
| 45 |
|
| 46 |
&run_make_with_options($makefile,'foo.d',&get_logfile); |
| 47 |
$answer = "$make_name: 'foo.d' is up to date.\n"; |
| 48 |
&compare_output($answer, &get_logfile(1)); |
| 49 |
|
| 50 |
# TEST #3 |
| 51 |
|
| 52 |
&utouch(-10, 'foo.d'); |
| 53 |
&touch('foo.f'); |
| 54 |
|
| 55 |
&run_make_with_options($makefile,'foo.d',&get_logfile); |
| 56 |
$answer = "cp foo.f foo.e\ncp foo.e foo.d\n"; |
| 57 |
&compare_output($answer, &get_logfile(1)); |
| 58 |
|
| 59 |
# TEST #4 |
| 60 |
|
| 61 |
&run_make_with_options($makefile,'foo.c',&get_logfile); |
| 62 |
$answer = "cp foo.e foo.c\n"; |
| 63 |
&compare_output($answer, &get_logfile(1)); |
| 64 |
|
| 65 |
# TEST #5 |
| 66 |
|
| 67 |
unlink('foo.e'); |
| 68 |
|
| 69 |
&run_make_with_options($makefile,'foo.c',&get_logfile); |
| 70 |
$answer = "$make_name: 'foo.c' is up to date.\n"; |
| 71 |
&compare_output($answer, &get_logfile(1)); |
| 72 |
|
| 73 |
# TEST #6 |
| 74 |
|
| 75 |
&utouch(-10, 'foo.c'); |
| 76 |
&touch('foo.f'); |
| 77 |
|
| 78 |
&run_make_with_options($makefile,'foo.c',&get_logfile); |
| 79 |
$answer = "cp foo.f foo.e\ncp foo.e foo.c\n"; |
| 80 |
&compare_output($answer, &get_logfile(1)); |
| 81 |
|
| 82 |
unlink('foo.f', 'foo.e', 'foo.d', 'foo.c'); |
| 83 |
|
| 84 |
# TEST #7 -- test the "global" .SECONDARY, with no targets. |
| 85 |
|
| 86 |
$makefile2 = &get_tmpfile; |
| 87 |
|
| 88 |
open(MAKEFILE, "> $makefile2"); |
| 89 |
|
| 90 |
print MAKEFILE <<'EOF'; |
| 91 |
.SECONDARY: |
| 92 |
|
| 93 |
final: intermediate |
| 94 |
intermediate: source |
| 95 |
|
| 96 |
final intermediate source: ; echo $< > $@ |
| 97 |
EOF |
| 98 |
|
| 99 |
close(MAKEFILE); |
| 100 |
|
| 101 |
&utouch(-10, 'source'); |
| 102 |
touch('final'); |
| 103 |
|
| 104 |
&run_make_with_options($makefile2, '', &get_logfile); |
| 105 |
$answer = "$make_name: 'final' is up to date.\n"; |
| 106 |
&compare_output($answer, &get_logfile(1)); |
| 107 |
|
| 108 |
unlink('source', 'final', 'intermediate'); |
| 109 |
|
| 110 |
|
| 111 |
# TEST #8 -- test the "global" .SECONDARY, with .PHONY. |
| 112 |
|
| 113 |
touch('version2'); |
| 114 |
run_make_test(' |
| 115 |
.PHONY: version |
| 116 |
.SECONDARY: |
| 117 |
version2: version ; @echo GOOD |
| 118 |
all: version2', |
| 119 |
'all', 'GOOD'); |
| 120 |
|
| 121 |
unlink('version2'); |
| 122 |
|
| 123 |
# TEST #9 -- Savannah bug #15919 |
| 124 |
# The original fix for this bug caused a new bug, shown here. |
| 125 |
|
| 126 |
touch(qw(1.a 2.a)); |
| 127 |
|
| 128 |
run_make_test(' |
| 129 |
%.c : %.b ; cp $< $@ |
| 130 |
%.b : %.a ; cp $< $@ |
| 131 |
all : 1.c 2.c |
| 132 |
2.a: 1.c', '-rR -j', |
| 133 |
'cp 1.a 1.b |
| 134 |
cp 1.b 1.c |
| 135 |
cp 2.a 2.b |
| 136 |
cp 2.b 2.c |
| 137 |
rm 2.b 1.b'); |
| 138 |
|
| 139 |
unlink(qw(1.a 2.a 1.c 2.c)); |
| 140 |
|
| 141 |
# TEST #10 -- Savannah bug #15919 |
| 142 |
touch('test.0'); |
| 143 |
run_make_test(' |
| 144 |
.SECONDARY : test.1 test.2 test.3 |
| 145 |
|
| 146 |
test : test.4 |
| 147 |
|
| 148 |
%.4 : %.int %.3 ; touch $@ |
| 149 |
|
| 150 |
%.int : %.3 %.2 ; touch $@ |
| 151 |
|
| 152 |
%.3 : | %.2 ; touch $@ |
| 153 |
|
| 154 |
%.2 : %.1 ; touch $@ |
| 155 |
|
| 156 |
%.1 : %.0 ; touch $@', '-rR -j 2', |
| 157 |
'touch test.1 |
| 158 |
touch test.2 |
| 159 |
touch test.3 |
| 160 |
touch test.int |
| 161 |
touch test.4 |
| 162 |
rm test.int'); |
| 163 |
|
| 164 |
# After a touch of test.0 it should give the same output, except we don't need |
| 165 |
# to rebuild test.3 (order-only) |
| 166 |
sleep(1); |
| 167 |
touch('test.0'); |
| 168 |
run_make_test(undef, '-rR -j 2', |
| 169 |
'touch test.1 |
| 170 |
touch test.2 |
| 171 |
touch test.int |
| 172 |
touch test.4 |
| 173 |
rm test.int'); |
| 174 |
|
| 175 |
# With both test.0 and test.3 updated it should still build everything except |
| 176 |
# test.3 |
| 177 |
sleep(1); |
| 178 |
touch('test.0', 'test.3'); |
| 179 |
run_make_test(undef, '-rR -j 2', |
| 180 |
'touch test.1 |
| 181 |
touch test.2 |
| 182 |
touch test.int |
| 183 |
touch test.4 |
| 184 |
rm test.int'); |
| 185 |
|
| 186 |
unlink(qw(test.0 test.1 test.2 test.3 test.4)); |
| 187 |
|
| 188 |
# This tells the test driver that the perl test script executed properly. |
| 189 |
1; |