1 | # -*-perl-*-
|
---|
2 | $description = "Test order-only prerequisites.";
|
---|
3 |
|
---|
4 | $details = "\
|
---|
5 | Create makefiles with various combinations of normal and order-only
|
---|
6 | prerequisites and ensure they behave properly. Test the \$| variable.";
|
---|
7 |
|
---|
8 | open(MAKEFILE,"> $makefile");
|
---|
9 |
|
---|
10 | print MAKEFILE <<'EOF';
|
---|
11 | foo: bar | baz
|
---|
12 | @echo '$$^ = $^'
|
---|
13 | @echo '$$| = $|'
|
---|
14 | touch $@
|
---|
15 |
|
---|
16 | .PHONY: baz
|
---|
17 |
|
---|
18 | bar baz:
|
---|
19 | touch $@
|
---|
20 | EOF
|
---|
21 |
|
---|
22 | close(MAKEFILE);
|
---|
23 |
|
---|
24 |
|
---|
25 | # TEST #1 -- just the syntax
|
---|
26 |
|
---|
27 | &run_make_with_options($makefile, "", &get_logfile);
|
---|
28 | $answer = "touch bar\ntouch baz\n\$^ = bar\n\$| = baz\ntouch foo\n";
|
---|
29 | &compare_output($answer,&get_logfile(1));
|
---|
30 |
|
---|
31 |
|
---|
32 | # TEST #2 -- now we do it again: baz is PHONY but foo should _NOT_ be updated
|
---|
33 |
|
---|
34 | &run_make_with_options($makefile, "", &get_logfile);
|
---|
35 | $answer = "touch baz\n";
|
---|
36 | &compare_output($answer,&get_logfile(1));
|
---|
37 |
|
---|
38 | unlink(qw(foo bar baz));
|
---|
39 |
|
---|
40 | # Test prereqs that are both order and non-order
|
---|
41 |
|
---|
42 | $makefile2 = &get_tmpfile;
|
---|
43 |
|
---|
44 | open(MAKEFILE,"> $makefile2");
|
---|
45 |
|
---|
46 | print MAKEFILE <<'EOF';
|
---|
47 | foo: bar | baz
|
---|
48 | @echo '$$^ = $^'
|
---|
49 | @echo '$$| = $|'
|
---|
50 | touch $@
|
---|
51 |
|
---|
52 | foo: baz
|
---|
53 |
|
---|
54 | .PHONY: baz
|
---|
55 |
|
---|
56 | bar baz:
|
---|
57 | touch $@
|
---|
58 | EOF
|
---|
59 |
|
---|
60 | close(MAKEFILE);
|
---|
61 |
|
---|
62 | # TEST #3 -- Make sure the order-only prereq was promoted to normal.
|
---|
63 |
|
---|
64 | &run_make_with_options($makefile2, "", &get_logfile);
|
---|
65 | $answer = "touch bar\ntouch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
|
---|
66 | &compare_output($answer,&get_logfile(1));
|
---|
67 |
|
---|
68 |
|
---|
69 | # TEST #4 -- now we do it again
|
---|
70 |
|
---|
71 | &run_make_with_options($makefile2, "", &get_logfile);
|
---|
72 | $answer = "touch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
|
---|
73 | &compare_output($answer,&get_logfile(1));
|
---|
74 |
|
---|
75 | unlink(qw(foo bar baz));
|
---|
76 |
|
---|
77 | # Test empty normal prereqs
|
---|
78 |
|
---|
79 | $makefile3 = &get_tmpfile;
|
---|
80 |
|
---|
81 | open(MAKEFILE,"> $makefile3");
|
---|
82 |
|
---|
83 | print MAKEFILE <<'EOF';
|
---|
84 | foo:| baz
|
---|
85 | @echo '$$^ = $^'
|
---|
86 | @echo '$$| = $|'
|
---|
87 | touch $@
|
---|
88 |
|
---|
89 | .PHONY: baz
|
---|
90 |
|
---|
91 | baz:
|
---|
92 | touch $@
|
---|
93 | EOF
|
---|
94 |
|
---|
95 | close(MAKEFILE);
|
---|
96 |
|
---|
97 | # TEST #5 -- make sure the parser was correct.
|
---|
98 |
|
---|
99 | &run_make_with_options($makefile3, "", &get_logfile);
|
---|
100 | $answer = "touch baz\n\$^ = \n\$| = baz\ntouch foo\n";
|
---|
101 | &compare_output($answer,&get_logfile(1));
|
---|
102 |
|
---|
103 |
|
---|
104 | # TEST #6 -- now we do it again: this time foo won't be built
|
---|
105 |
|
---|
106 | &run_make_with_options($makefile3, "", &get_logfile);
|
---|
107 | $answer = "touch baz\n";
|
---|
108 | &compare_output($answer,&get_logfile(1));
|
---|
109 |
|
---|
110 | unlink(qw(foo baz));
|
---|
111 |
|
---|
112 | # Test order-only in pattern rules
|
---|
113 |
|
---|
114 | $makefile4 = &get_tmpfile;
|
---|
115 |
|
---|
116 | open(MAKEFILE,"> $makefile4");
|
---|
117 |
|
---|
118 | print MAKEFILE <<'EOF';
|
---|
119 | %.w : %.x | baz
|
---|
120 | @echo '$$^ = $^'
|
---|
121 | @echo '$$| = $|'
|
---|
122 | touch $@
|
---|
123 |
|
---|
124 | all: foo.w
|
---|
125 |
|
---|
126 | .PHONY: baz
|
---|
127 | foo.x baz:
|
---|
128 | touch $@
|
---|
129 | EOF
|
---|
130 |
|
---|
131 | close(MAKEFILE);
|
---|
132 |
|
---|
133 | # TEST #7 -- make sure the parser was correct.
|
---|
134 |
|
---|
135 | &run_make_with_options($makefile4, "", &get_logfile);
|
---|
136 | $answer = "touch foo.x\ntouch baz\n\$^ = foo.x\n\$| = baz\ntouch foo.w\n";
|
---|
137 | &compare_output($answer,&get_logfile(1));
|
---|
138 |
|
---|
139 | # TEST #8 -- now we do it again: this time foo.w won't be built
|
---|
140 |
|
---|
141 | &run_make_with_options($makefile4, "", &get_logfile);
|
---|
142 | $answer = "touch baz\n";
|
---|
143 | &compare_output($answer,&get_logfile(1));
|
---|
144 |
|
---|
145 | unlink(qw(foo.w foo.x baz));
|
---|
146 |
|
---|
147 | # TEST #9 -- make sure that $< is set correctly in the face of order-only
|
---|
148 | # prerequisites in pattern rules.
|
---|
149 |
|
---|
150 | run_make_test('
|
---|
151 | %r: | baz ; @echo $< $^ $|
|
---|
152 | bar: foo
|
---|
153 | foo:;@:
|
---|
154 | baz:;@:
|
---|
155 | ', '', "foo foo baz\n");
|
---|
156 |
|
---|
157 |
|
---|
158 | 1;
|
---|