3 # Build the auto-generated parts of the Wine makefiles.
5 # Copyright 2006 Alexandre Julliard
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 "MAKE_RULES" => "Make.rules",
25 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
26 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
27 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
28 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
31 my (@makefiles, %makefiles);
33 # update a file if changed
37 my $ret = system "cmp $file $file.new >/dev/null";
41 #print "$file is unchanged\n";
45 rename "$file.new", "$file";
46 print "$file updated\n";
51 # replace some lines in a file between two markers
52 sub replace_in_file($$$@)
58 open OLD_FILE, "$file" or die "cannot open $file";
59 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
74 print NEW_FILE $_ unless $skip;
81 return update_file($file);
84 # parse the specified makefile to identify the rules file
89 open MAKE, "$file.in" or die "cannot open $file.in\n";
94 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
96 if (/^\@(MAKE.*RULES)\@/)
99 $makefiles{$file} = $makerules{$var};
107 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
111 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
114 foreach my $file (sort values %makerules, @makefiles)
116 parse_makefile( $file );
119 ################################################################
120 # update the makefile list in configure.ac
124 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
126 push @lines, "$var=$makerules{$var}\n";
127 push @lines, "AC_SUBST_FILE($var)\n\n";
130 replace_in_file( "configure.ac", '^MAKE_RULES', '\]\)$',
132 "AC_CONFIG_FILES([\n",
133 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
136 ################################################################
137 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
139 my %modules = ( "gdi" => "gdi32", "user" => "user32" );
141 @lines = ( "TESTBINS =" );
143 foreach my $file (sort grep /^dlls\/.*\/tests\/Makefile/, @makefiles)
145 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/)
148 my $mod = $modules{$dir} || $dir;
150 push @lines, " \\\n\t${mod}_test.exe";
155 foreach my $test (sort keys %tests)
157 my $dir = $tests{$test};
158 push @lines, "${test}_test.exe: \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT)\n";
159 push @lines, "\tcp \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
161 push @lines, "\n# Special rules\n";
163 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
166 foreach my $test (sort keys %tests)
168 push @lines, "${test}_test.exe TESTRES \"${test}_test.exe\"\n";
171 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef, @lines );
173 ################################################################
174 # update the makefile list in Makefile.in
179 foreach my $file (sort values %makerules)
181 push @targets, $file;
182 if (!defined($makefiles{$file})) { push @depends, "$file: $file.in"; }
183 else { push @depends, "$file: $file.in Make.rules"; }
186 foreach my $file (sort @makefiles)
188 push @targets, $file unless $file eq "Makefile";
189 my $dep = $makefiles{$file};
190 push @depends, "$file: $file.in $dep";
194 push @lines, "ALL_MAKEFILES = \\\n\t";
195 push @lines, join (" \\\n\t", @targets ), "\n\n";
196 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
197 push @lines, "\t\@./config.status \$\@\n\n";
198 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
199 push @lines, "distclean::\n";
200 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
201 push @lines, join ("\n", @depends ), "\n";
203 replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
206 ################################################################
207 # update dlls/Makefile.in
209 my @dll_makefiles = grep /^dlls\//, @makefiles;
210 system "dlls/make_dlls", @dll_makefiles;
213 ################################################################
214 # update programs/Makefile.in
216 my @prog_makefiles = grep /^programs\//, @makefiles;
217 system "programs/make_progs", @prog_makefiles;