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.";
12 $makefile2 = &get_tmpfile;
13 $makefile3 = &get_tmpfile;
15 open(MAKEFILE,"> $makefile");
17 # The Contents of the MAKEFILE ...
19 print MAKEFILE "all: \n";
20 print MAKEFILE "\t\@echo This is the output from the original makefile\n";
22 # END of Contents of MAKEFILE
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";
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";
39 # Create the answer to what should be produced by this Makefile
40 $answer = "This is the output from the original makefile\n";
42 # Run make to catch the default rule
43 &run_make_with_options($makefile,"-f $makefile2 -f $makefile3",&get_logfile,0);
45 &compare_output($answer,&get_logfile(1));
48 # Run Make again with the rule from the second makefile: TWO
49 $answer = "This is the output from makefile 2\n";
51 &run_make_with_options($makefile,"-f $makefile2 -f $makefile3 TWO",&get_logfile,0);
53 &compare_output($answer,&get_logfile(1));
56 # Run Make again with the rule from the third makefile: THREE
58 $answer = "This is the output from makefile 3\n";
59 &run_make_with_options($makefile,
60 "-f $makefile2 -f $makefile3 THREE",
63 &compare_output($answer,&get_logfile(1));
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
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",
76 &compare_output($answer,&get_logfile(1));
80 # Validate all sorts of -f etc. options
82 my $hello = 'hello.mk';
84 my $byesrc = 'bye.mk.src';
86 create_file($hello, 'all:; $(info hello, world)
89 create_file($bye, 'def:; $(info bye, world)
90 bye.mk: bye.mk.src; touch $@
94 # These invocations use the empty filename string so that the test framework
95 # doesn't add any -f options on its own.
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'.
103 # Ensure the newly created bye.src.mk is newer than bye.mk.
105 run_make_test('', "-f$bye -fR - all", "#MAKE#: R: No such file or directory
108 #MAKE#: *** No rule to make target 'R'. Stop.
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 -');
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.
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);
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);
137 # Test that make correctly parses all possible syntaxes to pipe make code to
138 # the standard input.
140 $answer = "touch bye.mk.src
143 #MAKE#: 'all' is up to date.\n";
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) {
151 open(STDIN, "<", $hello) || die "$0: cannot open $hello for reading: $!";
152 # Ensure the newly created bye.src.mk is newer than bye.mk.
155 run_make_test('', "-f$bye $opt", $answer);
159 unlink($hello, $bye, $byesrc);
161 # This tells the test driver that the perl test script executed properly.