summaryrefslogtreecommitdiff
path: root/tests/scripts/targets/SECONDARY
blob: 447c275e8563102bdf32772597bddb2637300742 (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
#! -*-perl-*-

$description = "Test the behaviour of the .SECONDARY target.";

$details = "\
Test the behavior of the .SECONDARY special target.
Create a makefile where a file would not normally be considered
intermediate, then specify it as .SECONDARY.  Build and note that it's
not automatically deleted.  Delete the file.  Rebuild to ensure that
it's not created if it doesn't exist but doesn't need to be built.
Change the original and ensure that the secondary file and the ultimate
target are both rebuilt, and that the secondary file is not deleted.

Try this with implicit rules and explicit rules: both should work.\n";

open(MAKEFILE,"> $makefile");

print MAKEFILE <<'EOF';

.SECONDARY: foo.e

# Implicit rule test
%.d : %.e ; cp $< $@
%.e : %.f ; cp $< $@

foo.d: foo.e

# Explicit rule test
foo.c: foo.e ; cp $< $@
EOF

close(MAKEFILE);

# TEST #1

&utouch(-20, 'foo.f');

&run_make_with_options($makefile,'foo.d',&get_logfile);
$answer = "cp foo.f foo.e\ncp foo.e foo.d\n";
&compare_output($answer, &get_logfile(1));

# TEST #2

unlink('foo.e');

&run_make_with_options($makefile,'foo.d',&get_logfile);
$answer = "$make_name: 'foo.d' is up to date.\n";
&compare_output($answer, &get_logfile(1));

# TEST #3

&utouch(-10, 'foo.d');
&touch('foo.f');

&run_make_with_options($makefile,'foo.d',&get_logfile);
$answer = "cp foo.f foo.e\ncp foo.e foo.d\n";
&compare_output($answer, &get_logfile(1));

# TEST #4

&run_make_with_options($makefile,'foo.c',&get_logfile);
$answer = "cp foo.e foo.c\n";
&compare_output($answer, &get_logfile(1));

# TEST #5

unlink('foo.e');

&run_make_with_options($makefile,'foo.c',&get_logfile);
$answer = "$make_name: 'foo.c' is up to date.\n";
&compare_output($answer, &get_logfile(1));

# TEST #6

&utouch(-10, 'foo.c');
&touch('foo.f');

&run_make_with_options($makefile,'foo.c',&get_logfile);
$answer = "cp foo.f foo.e\ncp foo.e foo.c\n";
&compare_output($answer, &get_logfile(1));

unlink('foo.f', 'foo.e', 'foo.d', 'foo.c');

# TEST #7 -- test the "global" .SECONDARY, with no targets.

$makefile2 = &get_tmpfile;

open(MAKEFILE, "> $makefile2");

print MAKEFILE <<'EOF';
.SECONDARY:

final: intermediate
intermediate: source

final intermediate source:
	echo $< > $@
EOF

close(MAKEFILE);

&utouch(-10, 'source');
touch('final');

&run_make_with_options($makefile2, '', &get_logfile);
$answer = "$make_name: 'final' is up to date.\n";
&compare_output($answer, &get_logfile(1));

unlink('source', 'final', 'intermediate');


# TEST #8 -- test the "global" .SECONDARY, with .PHONY.

touch('version2');
run_make_test('
.PHONY: version
.SECONDARY:
version2: version ; @echo GOOD
all: version2',
              'all', 'GOOD');

unlink('version2');

# TEST #9 -- Savannah bug #15919
# The original fix for this bug caused a new bug, shown here.

touch(qw(1.a 2.a));

run_make_test('
%.c : %.b ; cp $< $@
%.b : %.a ; cp $< $@
all : 1.c 2.c
2.a: 1.c', '-rR -j',
'cp 1.a 1.b
cp 1.b 1.c
cp 2.a 2.b
cp 2.b 2.c
rm 1.b 2.b');

unlink(qw(1.a 2.a 1.c 2.c));

# TEST #10 -- Savannah bug #15919
touch('test.0');
run_make_test('
.SECONDARY : test.1 test.2 test.3

test : test.4

%.4 : %.int %.3 ; touch $@

%.int : %.3 %.2 ; touch $@

%.3 : | %.2 ; touch $@

%.2 : %.1 ; touch $@

%.1 : %.0 ; touch $@', '-rR -j 2',
'touch test.1
touch test.2
touch test.3
touch test.int
touch test.4
rm test.int');

# After a touch of test.0 it should give the same output, except we don't need
# to rebuild test.3 (order-only)
sleep(1);
touch('test.0');
run_make_test(undef, '-rR -j 2',
'touch test.1
touch test.2
touch test.int
touch test.4
rm test.int');

# With both test.0 and test.3 updated it should still build everything except
# test.3
sleep(1);
touch('test.0', 'test.3');
run_make_test(undef, '-rR -j 2',
'touch test.1
touch test.2
touch test.int
touch test.4
rm test.int');

unlink(qw(test.0 test.1 test.2 test.3 test.4));

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