vwin32.vxd: Win64 printf format warning fixes.
[wine/wine-kai.git] / tools / make_makefiles
blob5518808994a00d4ff33524f83c3b494fccac1610
1 #!/usr/bin/perl -w
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
22 # Make rules files
23 my %makerules =
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
33 my %bin_install =
35 "msiexec" => 1,
36 "notepad" => 1,
37 "progman" => 1,
38 "regedit" => 1,
39 "regsvr32" => 1,
40 "uninstaller" => 1,
41 "wineboot" => 1,
42 "winebrowser" => 1,
43 "winecfg" => 1,
44 "wineconsole" => 1,
45 "winedbg" => 1,
46 "winefile" => 1,
47 "winemine" => 1,
48 "winepath" => 1,
49 "winhelp" => 1,
52 # Programs that we don't want to install at all
53 my %dont_install =
55 "cmdlgtst" => 1,
56 "view" => 1,
57 "winetest" => 1,
60 my (@makefiles, %makefiles);
62 # update a file if changed
63 sub update_file($)
65 my $file = shift;
66 my $ret = system "cmp $file $file.new >/dev/null";
67 if (!$ret)
69 unlink "$file.new";
70 #print "$file is unchanged\n";
72 else
74 rename "$file.new", "$file";
75 print "$file updated\n";
77 return $ret;
80 # replace some lines in a file between two markers
81 sub replace_in_file($$$@)
83 my $file = shift;
84 my $start = shift;
85 my $end = shift;
87 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
89 if (defined($start))
91 open OLD_FILE, "$file" or die "cannot open $file";
92 while (<OLD_FILE>)
94 last if /$start/;
95 print NEW_FILE $_;
99 print NEW_FILE @_;
101 if (defined($end))
103 my $skip=1;
104 while (<OLD_FILE>)
106 print NEW_FILE $_ unless $skip;
107 $skip = 0 if /$end/;
111 close OLD_FILE if defined($start);
112 close NEW_FILE;
113 return update_file($file);
116 # parse the specified makefile to identify the rules file
117 sub parse_makefile($)
119 my $file = shift;
120 my %make;
122 open MAKE, "$file.in" or die "cannot open $file.in\n";
124 while (<MAKE>)
126 chomp;
127 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
129 if (/^\@(MAKE.*RULES)\@/)
131 my $var = $1;
132 $make{"=rules"} = $makerules{$var};
133 next;
135 if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
137 $make{"MODULE"} = $1;
138 next;
140 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
142 $make{"=skip"} = 1;
143 next;
146 return %make;
149 if (-d ".git")
151 @makefiles = map { s/\.in$//; $_; } split /\s/, `git ls-files -c Makefile.in \\*/Makefile.in`;
153 else
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
167 my @lines = ();
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', '\]\)$',
176 @lines,
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" );
185 my %tests;
186 @lines = ( "TESTBINS =" );
188 foreach my $file (sort grep /^dlls\/.*\/tests\/Makefile/, @makefiles)
190 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/)
192 my $dir = $1;
193 my $mod = $modules{$dir} || $dir;
194 $tests{$mod} = $dir;
195 push @lines, " \\\n\t${mod}_test.exe";
198 push @lines, "\n\n";
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 );
210 @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
221 my @targets;
222 my @depends;
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";
239 @lines = ();
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
262 sub update_progs(@)
264 my (@subdirs, @install_subdirs, @install_progs);
266 my @ignores =
268 "/Makeprog.rules",
269 "/wineapploader",
270 "/winelauncher",
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"};
280 push @subdirs, $dir;
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',
287 "SUBDIRS = \\\n\t",
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 );