xref: /netbsd-src/external/gpl2/gmake/dist/tests/scripts/targets/INTERMEDIATE (revision 69606e3f5c9388e52aed8c120ad63c049ca45d8f)
1*69606e3fSchristos#                                                                    -*-perl-*-
2*69606e3fSchristos
3*69606e3fSchristos$description = "Test the behaviour of the .INTERMEDIATE target.";
4*69606e3fSchristos
5*69606e3fSchristos$details = "\
6*69606e3fSchristosTest the behavior of the .INTERMEDIATE special target.
7*69606e3fSchristosCreate a makefile where a file would not normally be considered
8*69606e3fSchristosintermediate, then specify it as .INTERMEDIATE.  Build and ensure it's
9*69606e3fSchristosdeleted properly.  Rebuild to ensure that it's not created if it doesn't
10*69606e3fSchristosexist but doesn't need to be built.  Change the original and ensure
11*69606e3fSchristosthat the intermediate file and the ultimate target are both rebuilt, and
12*69606e3fSchristosthat the intermediate file is again deleted.
13*69606e3fSchristos
14*69606e3fSchristosTry this with implicit rules and explicit rules: both should work.\n";
15*69606e3fSchristos
16*69606e3fSchristosopen(MAKEFILE,"> $makefile");
17*69606e3fSchristos
18*69606e3fSchristosprint MAKEFILE <<'EOF';
19*69606e3fSchristos
20*69606e3fSchristos.INTERMEDIATE: foo.e bar.e
21*69606e3fSchristos
22*69606e3fSchristos# Implicit rule test
23*69606e3fSchristos%.d : %.e ; cp $< $@
24*69606e3fSchristos%.e : %.f ; cp $< $@
25*69606e3fSchristos
26*69606e3fSchristosfoo.d: foo.e
27*69606e3fSchristos
28*69606e3fSchristos# Explicit rule test
29*69606e3fSchristosfoo.c: foo.e bar.e; cat $^ > $@
30*69606e3fSchristosEOF
31*69606e3fSchristos
32*69606e3fSchristosclose(MAKEFILE);
33*69606e3fSchristos
34*69606e3fSchristos# TEST #0
35*69606e3fSchristos
36*69606e3fSchristos&utouch(-20, 'foo.f', 'bar.f');
37*69606e3fSchristos
38*69606e3fSchristos&run_make_with_options($makefile,'foo.d',&get_logfile);
39*69606e3fSchristos$answer = "cp foo.f foo.e\ncp foo.e foo.d\nrm foo.e\n";
40*69606e3fSchristos&compare_output($answer, &get_logfile(1));
41*69606e3fSchristos
42*69606e3fSchristos# TEST #1
43*69606e3fSchristos
44*69606e3fSchristos&run_make_with_options($makefile,'foo.d',&get_logfile);
45*69606e3fSchristos$answer = "$make_name: `foo.d' is up to date.\n";
46*69606e3fSchristos&compare_output($answer, &get_logfile(1));
47*69606e3fSchristos
48*69606e3fSchristos# TEST #2
49*69606e3fSchristos
50*69606e3fSchristos&utouch(-10, 'foo.d');
51*69606e3fSchristos&touch('foo.f');
52*69606e3fSchristos
53*69606e3fSchristos&run_make_with_options($makefile,'foo.d',&get_logfile);
54*69606e3fSchristos$answer = "cp foo.f foo.e\ncp foo.e foo.d\nrm foo.e\n";
55*69606e3fSchristos&compare_output($answer, &get_logfile(1));
56*69606e3fSchristos
57*69606e3fSchristos# TEST #3
58*69606e3fSchristos
59*69606e3fSchristos&run_make_with_options($makefile,'foo.c',&get_logfile);
60*69606e3fSchristos$answer = "cp foo.f foo.e\ncp bar.f bar.e\ncat foo.e bar.e > foo.c\nrm bar.e foo.e\n";
61*69606e3fSchristos&compare_output($answer, &get_logfile(1));
62*69606e3fSchristos
63*69606e3fSchristos# TEST #4
64*69606e3fSchristos
65*69606e3fSchristos&run_make_with_options($makefile,'foo.c',&get_logfile);
66*69606e3fSchristos$answer = "$make_name: `foo.c' is up to date.\n";
67*69606e3fSchristos&compare_output($answer, &get_logfile(1));
68*69606e3fSchristos
69*69606e3fSchristos# TEST #5
70*69606e3fSchristos
71*69606e3fSchristos&utouch(-10, 'foo.c');
72*69606e3fSchristos&touch('foo.f');
73*69606e3fSchristos
74*69606e3fSchristos&run_make_with_options($makefile,'foo.c',&get_logfile);
75*69606e3fSchristos$answer = "cp foo.f foo.e\ncp bar.f bar.e\ncat foo.e bar.e > foo.c\nrm bar.e foo.e\n";
76*69606e3fSchristos&compare_output($answer, &get_logfile(1));
77*69606e3fSchristos
78*69606e3fSchristos# TEST #6 -- added for PR/1669: don't remove files mentioned on the cmd line.
79*69606e3fSchristos
80*69606e3fSchristos&run_make_with_options($makefile,'foo.e',&get_logfile);
81*69606e3fSchristos$answer = "cp foo.f foo.e\n";
82*69606e3fSchristos&compare_output($answer, &get_logfile(1));
83*69606e3fSchristos
84*69606e3fSchristosunlink('foo.f', 'foo.e', 'foo.d', 'foo.c', 'bar.f', 'bar.e', 'bar.d', 'bar.c');
85*69606e3fSchristos
86*69606e3fSchristos# TEST #7 -- added for PR/1423
87*69606e3fSchristos
88*69606e3fSchristos$makefile2 = &get_tmpfile;
89*69606e3fSchristos
90*69606e3fSchristosopen(MAKEFILE, "> $makefile2");
91*69606e3fSchristos
92*69606e3fSchristosprint MAKEFILE <<'EOF';
93*69606e3fSchristosall: foo
94*69606e3fSchristosfoo.a: ; touch $@
95*69606e3fSchristos%: %.a ; touch $@
96*69606e3fSchristos.INTERMEDIATE: foo.a
97*69606e3fSchristosEOF
98*69606e3fSchristos
99*69606e3fSchristosclose(MAKEFILE);
100*69606e3fSchristos
101*69606e3fSchristos&run_make_with_options($makefile2, '-R', &get_logfile);
102*69606e3fSchristos$answer = "touch foo.a\ntouch foo\nrm foo.a\n";
103*69606e3fSchristos&compare_output($answer, &get_logfile(1));
104*69606e3fSchristos
105*69606e3fSchristosunlink('foo');
106*69606e3fSchristos
107*69606e3fSchristos# This tells the test driver that the perl test script executed properly.
108*69606e3fSchristos1;
109