Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / options / dash-f
1 #                                                                    -*-perl-*-
2 $description = "The following test tests that if you specify greater \n"
3               ."than one '-f makefilename' on the command line, \n"
4               ."that make concatenates them.  This test creates three \n"
5               ."makefiles and specifies all of them with the -f option \n"
6               ."on the command line.  To make sure they were concatenated, \n"
7               ."we then call make with the rules from the concatenated \n"
8               ."makefiles one at a time.  Finally, it calls all three \n"
9               ."rules in one call to make and checks that the output\n"
10               ."is in the correct order.";
11
12 $makefile2 = &get_tmpfile;
13 $makefile3 = &get_tmpfile;
14
15 open(MAKEFILE,"> $makefile");
16
17 # The Contents of the MAKEFILE ...
18
19 print MAKEFILE "all: \n";
20 print MAKEFILE "\t\@echo This is the output from the original makefile\n";
21
22 # END of Contents of MAKEFILE
23
24 close(MAKEFILE);
25
26 # Create a second makefile
27 open(MAKEFILE,"> $makefile2");
28 print MAKEFILE "TWO: \n";
29 print MAKEFILE "\t\@echo This is the output from makefile 2\n";
30 close(MAKEFILE);
31
32 # Create a third makefile
33 open(MAKEFILE,"> $makefile3");
34 print MAKEFILE "THREE: \n";
35 print MAKEFILE "\t\@echo This is the output from makefile 3\n";
36 close(MAKEFILE);
37
38
39 # Create the answer to what should be produced by this Makefile
40 $answer = "This is the output from the original makefile\n";
41
42 # Run make to catch the default rule
43 &run_make_with_options($makefile,"-f $makefile2 -f $makefile3",&get_logfile,0);
44
45 &compare_output($answer,&get_logfile(1));
46
47
48 # Run Make again with the rule from the second makefile: TWO
49 $answer = "This is the output from makefile 2\n";
50
51 &run_make_with_options($makefile,"-f $makefile2 -f $makefile3 TWO",&get_logfile,0);
52
53 &compare_output($answer,&get_logfile(1));
54
55
56 # Run Make again with the rule from the third makefile: THREE
57
58 $answer = "This is the output from makefile 3\n";
59 &run_make_with_options($makefile,
60                        "-f $makefile2 -f $makefile3 THREE",
61                        &get_logfile,
62                        0);
63 &compare_output($answer,&get_logfile(1));
64
65
66 # Run Make again with ALL three rules in the order 2 1 3 to make sure
67 # that all rules are executed in the proper order
68
69 $answer = "This is the output from makefile 2\n";
70 $answer .= "This is the output from the original makefile\n";
71 $answer .= "This is the output from makefile 3\n";
72 &run_make_with_options($makefile,
73                        "-f $makefile2 -f $makefile3 TWO all THREE",
74                        &get_logfile,
75                        0);
76 &compare_output($answer,&get_logfile(1));
77
78
79 # sv 62118.
80 # Validate all sorts of -f etc. options
81
82 my $hello = 'hello.mk';
83 my $bye = 'bye.mk';
84 my $byesrc = 'bye.mk.src';
85
86 create_file($hello, 'all:; $(info hello, world)
87 ');
88
89 create_file($bye, 'def:; $(info bye, world)
90 bye.mk: bye.mk.src; touch $@
91 bye.mk.src:; touch $@
92 ');
93
94 # These invocations use the empty filename string so that the test framework
95 # doesn't add any -f options on its own.
96
97 # Incorrect order of options. -R follows -f.
98 # Invocation of make is equivalent to
99 #   echo 'all:; $(info hello, world)' | make -f bye.mk -fR - all
100 # There is bye.mk, but there is no 'R'.
101 # make runs the recipes from bye.mk and prints the error about missing 'R'.
102
103 # Ensure the newly created bye.src.mk is newer than bye.mk.
104 &utouch(-600, $bye);
105 run_make_test('', "-f$bye -fR - all", "#MAKE#: R: No such file or directory
106 touch bye.mk.src
107 touch bye.mk
108 #MAKE#: *** No rule to make target 'R'.  Stop.
109 ", 512);
110
111 my @opts;
112 my $answer;
113
114 # Test double -f-.
115 @opts = ('-f- -f-', '-f - -f -', '-f- -f -', '-f - -f-',
116          '-f- --file=-', '-f- --file -', '-f - --file=-', '-f - --file -',
117          '-f- --makefile=-', '-f- --makefile -',
118          '-f - --makefile=-', '-f - --makefile -',
119          '--file=- --makefile=-', '--file=- --makefile -',
120          '--file - --makefile=-', '--file - --makefile -');
121
122 for my $opt (@opts) {
123     # We shouldn't need this; if the options are wrong then make shouldn't try
124     # to read from stdin.
125     close(STDIN);
126     open(STDIN, "<", $hello) || die "$0: cannot open $hello for reading: $!";
127     run_make_test('', "-f$bye $opt", "#MAKE#: *** Makefile from standard input specified twice.  Stop.\n", 512);
128 }
129
130 # -f is not followed by filename.
131 @opts = ('-f', '--file', '--makefile');
132 $answer = "/requires an argument/";
133 for my $opt (@opts) {
134     run_make_test('', $opt, $answer, 512);
135 }
136
137 # Test that make correctly parses all possible syntaxes to pipe make code to
138 # the standard input.
139
140 $answer = "touch bye.mk.src
141 touch bye.mk
142 hello, world
143 #MAKE#: 'all' is up to date.\n";
144
145 @opts = ('-f- all', '-f - all', '-Rf- all', '-Rf - all',
146          '--file=- all', '--file - all',
147          '--makefile=- all', '--makefile - all');
148 for my $opt (@opts) {
149     unlink($byesrc);
150     close(STDIN);
151     open(STDIN, "<", $hello) || die "$0: cannot open $hello for reading: $!";
152     # Ensure the newly created bye.src.mk is newer than bye.mk.
153     &utouch(-600, $bye);
154
155     run_make_test('', "-f$bye $opt", $answer);
156 }
157
158 close(STDIN);
159 unlink($hello, $bye, $byesrc);
160
161 # This tells the test driver that the perl test script executed properly.
162 1;