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
25 "MAKE_RULES" => "Make.rules",
26 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
27 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
28 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
29 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
32 # Programs that we want to install in the bin directory too
52 # Programs that we don't want to install at all
60 my (@makefiles, %makefiles);
62 # update a file if changed
66 my $ret = system "cmp $file $file.new >/dev/null";
70 #print "$file is unchanged\n";
74 rename "$file.new", "$file";
75 print "$file updated\n";
80 # replace some lines in a file between two markers
81 sub replace_in_file
($$$@
)
87 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
91 open OLD_FILE
, "$file" or die "cannot open $file";
106 print NEW_FILE
$_ unless $skip;
111 close OLD_FILE
if defined($start);
113 return update_file
($file);
116 # parse the specified makefile to identify the rules file
117 sub parse_makefile
($)
122 open MAKE
, "$file.in" or die "cannot open $file.in\n";
127 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
129 if (/^\@(MAKE.*RULES)\@/)
132 $make{"=rules"} = $makerules{$var};
135 if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
137 $make{"MODULE"} = $1;
140 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
151 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
155 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s
/,`find . -name Makefile.in -print`);
158 foreach my $file (sort values %makerules, @makefiles)
160 my %make = parse_makefile
( $file );
161 $makefiles{$file} = \
%make;
164 ################################################################
165 # update the makefile list in configure.ac
169 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
171 push @lines, "$var=$makerules{$var}\n";
172 push @lines, "AC_SUBST_FILE($var)\n\n";
175 replace_in_file
( "configure.ac", '^MAKE_RULES', '\]\)$',
177 "AC_CONFIG_FILES([\n",
178 join ("\n", (sort values %makerules), (sort @makefiles) ), "])\n" );
181 ################################################################
182 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
184 my %modules = ( "gdi" => "gdi32", "user" => "user32" );
186 @lines = ( "TESTBINS =" );
188 foreach my $file (sort grep /^dlls\/.*\
/tests\/Makefile
/, @makefiles)
190 if ($file =~ /^dlls\/(.*)\
/tests\/Makefile
/)
193 my $mod = $modules{$dir} || $dir;
195 push @lines, " \\\n\t${mod}_test.exe";
200 foreach my $test (sort keys %tests)
202 my $dir = $tests{$test};
203 push @lines, "${test}_test.exe: \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT)\n";
204 push @lines, "\tcp \$(DLLDIR)/$dir/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
206 push @lines, "\n# Special rules\n";
208 replace_in_file
( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
211 foreach my $test (sort keys %tests)
213 push @lines, "${test}_test.exe TESTRES \"${test}_test.exe\"\n";
216 replace_in_file
( "programs/winetest/winetest.rc", ' TESTRES ', undef, @lines );
218 ################################################################
219 # update the makefile list in Makefile.in
224 foreach my $file (sort values %makerules)
226 push @targets, $file;
227 my %make = %{$makefiles{$file}};
228 if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
229 else { push @depends, "$file: $file.in Make.rules"; }
232 foreach my $file (sort @makefiles)
234 push @targets, $file unless $file eq "Makefile";
235 my $dep = ${$makefiles{$file}}{"=rules"};
236 push @depends, "$file: $file.in $dep";
240 push @lines, "ALL_MAKEFILES = \\\n\t";
241 push @lines, join (" \\\n\t", @targets ), "\n\n";
242 push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
243 push @lines, "\t\@./config.status \$\@\n\n";
244 push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
245 push @lines, "distclean::\n";
246 push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
247 push @lines, join ("\n", @depends ), "\n";
249 replace_in_file
( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
252 ################################################################
253 # update dlls/Makefile.in
255 my @dll_makefiles = grep /^dlls\//, @makefiles;
256 system "dlls/make_dlls", @dll_makefiles;
259 ################################################################
260 # update programs/Makefile.in and programs/.gitignore
264 my (@subdirs, @install_subdirs, @install_progs);
273 foreach my $make (@_)
275 my %makefile = %{$makefiles{$make}};
276 my $module = $makefile{"MODULE"};
277 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile
$/$1/;
278 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
279 next if defined $makefile{"=skip"};
281 push @ignores, "$dir/$dir";
282 push @install_subdirs, $dir unless $dont_install{$dir};
283 push @install_progs, $dir if $bin_install{$dir};
286 replace_in_file
( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
288 join( " \\\n\t", @subdirs ),
289 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
290 join( " \\\n\t", @install_subdirs ),
291 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
292 join( " \\\n\t", @install_progs ),
293 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
295 replace_in_file
( "programs/.gitignore", undef, undef,
296 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
297 join("\n", sort @ignores), "\n" );
300 update_progs
( sort grep /^programs\/.*\
/Makefile$/, @makefiles );