user32: Change value of WM_MDICALCCHILDSCROLL to 0x003f.
[wine.git] / tools / make_makefiles
bloba5e8a05e35e82d70e03e52c406a28d00ad4e7caf
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 use strict;
24 # Dlls and programs that are 16-bit specific
25 my %modules16 =
27 "ifsmgr.vxd" => 1,
28 "mmdevldr.vxd" => 1,
29 "monodebg.vxd" => 1,
30 "vdhcp.vxd" => 1,
31 "vmm.vxd" => 1,
32 "vnbt.vxd" => 1,
33 "vnetbios.vxd" => 1,
34 "vtdapi.vxd" => 1,
35 "vwin32.vxd" => 1,
36 "w32skrnl.dll" => 1,
37 "winevdm.exe" => 1,
38 "wow32.dll" => 1,
41 my %exported_wine_headers = (
42 "wine/debug.h" => 1,
43 "wine/exception.h" => 1,
44 "wine/library.h" => 1,
45 "wine/unicode.h" => 1,
46 "wine/itss.idl" => 1,
47 "wine/svcctl.idl" => 1,
50 my %ignored_source_files = (
51 "dlls/wineps.drv/afm2c.c" => 1,
52 "dlls/wineps.drv/mkagl.c" => 1,
53 "include/config.h.in" => 1,
54 "programs/winetest/dist.rc" => 1,
55 "tools/makedep.c" => 1,
58 my (@makefiles, %makefiles);
60 sub dirname($)
62 my $ret = shift;
63 return "" unless $ret =~ /\//;
64 $ret =~ s!/[^/]*$!!;
65 return $ret;
68 # update a file if changed
69 sub update_file($)
71 my $file = shift;
72 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
73 if (!$ret)
75 unlink "$file.new";
77 else
79 rename "$file.new", "$file";
80 print "$file updated\n";
81 if ($file eq "configure.ac")
83 system "autoconf";
84 print "configure updated\n";
87 return $ret;
90 # replace some lines in a file between two markers
91 sub replace_in_file($$$@)
93 my $file = shift;
94 my $start = shift;
95 my $end = shift;
97 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
99 if (defined($start))
101 open OLD_FILE, "$file" or die "cannot open $file";
102 while (<OLD_FILE>)
104 last if /$start/;
105 print NEW_FILE $_;
109 print NEW_FILE @_;
111 if (defined($end))
113 my $skip=1;
114 while (<OLD_FILE>)
116 print NEW_FILE $_ unless $skip;
117 $skip = 0 if /$end/;
121 close OLD_FILE if defined($start);
122 close NEW_FILE;
123 return update_file($file);
126 # replace a variable in a makefile
127 sub replace_makefile_variable($$)
129 my ($file, $var) = @_;
130 my $make = $makefiles{$file};
131 my $replaced = 0;
132 my @values;
134 if (defined ${$make}{"=$var"})
136 @values = @{${$make}{"=$var"}};
137 ${$make}{$var} = \@values;
139 else
141 return unless defined ${$make}{$var};
142 undef ${$make}{$var};
145 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
147 open OLD_FILE, "$file.in" or die "cannot open $file.in";
148 while (<OLD_FILE>)
150 if (/^\s*($var\s*)=/)
152 # try to preserve formatting
153 my $prefix = $1;
154 my $multiline = /\\$/ || (@values > 1);
155 while (/\\$/)
157 $_ = <OLD_FILE>;
158 last unless $_;
160 if (!@values)
162 # nothing
164 elsif ($multiline)
166 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
168 else
170 print NEW_FILE "$prefix= @values\n";
172 $replaced = 1;
173 next;
175 if (/^\@MAKE/ && !$replaced && @values)
177 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
179 print NEW_FILE $_;
181 close OLD_FILE;
182 close NEW_FILE;
183 return update_file("$file.in");
186 # parse the specified makefile and load the variables
187 sub parse_makefile($)
189 my $file = shift;
190 my %make;
192 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
194 open MAKE, "$file.in" or die "cannot open $file.in\n";
196 while (<MAKE>)
198 chomp;
199 next if (/^\s*#/);
200 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
201 next if (/^\s*$/);
203 if (/\@[A-Z_]+\@/) # config.status substitution variable
205 die "Configure substitution is not allowed in $file" unless $file eq "Makefile";
207 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
209 my $var = $1;
210 $make{$var} = $2;
211 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
212 next;
214 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_SRCS|C_SRCS|OBJC_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|FONT_SRCS|IN_SRCS|PO_SRCS|PROGRAMS|EXTRA_TARGETS|MANPAGES|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
216 my $var = $1;
217 my @list = split(/\s+/, $2);
218 $make{$var} = \@list;
219 next;
221 if (/(install-lib|install-dev|clean)\s*:/)
223 ${$make{"=flags"}}{$1} = 1;
224 next;
226 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
228 die "Variable $1 in $file.in is obsolete";
232 if ($file =~ /^programs\/([^\/]+)\/Makefile/)
234 my $prog = $1;
235 if (defined $make{"INSTALL_LIB"})
237 ${$make{"=flags"}}{"install"} = 1 if grep { "$prog.exe" eq $_; } @{$make{"INSTALL_LIB"}};
238 ${$make{"=flags"}}{"installbin"} = 1 if grep { $prog eq $_; } @{$make{"INSTALL_LIB"}};
240 else
242 ${$make{"=flags"}}{"install"} = 1;
246 unless (defined $make{"MODULE"})
248 ${$make{"=flags"}}{"install-lib"} = 1 if defined $make{"INSTALL_LIB"};
249 ${$make{"=flags"}}{"install-dev"} = 1 if defined $make{"INSTALL_DEV"};
251 ${$make{"=flags"}}{"clean"} = 1 if defined $make{"PROGRAMS"} || defined $make{"EXTRA_TARGETS"} || defined $make{"EXTRA_OBJS"};
253 if (defined $make{"=flags"} && defined $make{"MODULE"})
255 die "Custom install-lib rule not allowed in $file" if defined ${$make{"=flags"}}{"install-lib"};
256 die "Custom install-dev rule not allowed in $file" if defined ${$make{"=flags"}}{"install-dev"};
259 return %make;
262 # read pragma makedep flags from a source file
263 sub get_makedep_flags($)
265 my $file = shift;
266 my %flags;
268 open FILE, $file or die "cannot open $file";
269 if ($file =~ /\.sfd$/)
271 while (<FILE>)
273 next unless /^UComments:\s*\"(.*)\"$/;
274 foreach my $pragma (split /\+AAoA/, $1)
276 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
277 foreach my $flag (split /\s+/, $1)
279 $flags{$flag} = 1;
280 last if $flag eq "font";
285 else
287 while (<FILE>)
289 next unless /^#\s*pragma\s+makedep\s+(.*)/;
290 foreach my $flag (split /\s+/, $1)
292 last if $flag eq "depend";
293 $flags{$flag} = 1;
297 close FILE;
298 return %flags;
301 sub get_parent_makefile($)
303 my $file = shift;
304 my %make = %{$makefiles{$file}};
305 my $reldir = $make{"PARENTSRC"} || "";
306 return "" unless $reldir;
307 (my $path = $file) =~ s/\/Makefile$/\//;
308 while ($reldir =~ /^\.\.\//)
310 $reldir =~ s/^\.\.\///;
311 $path =~ s/[^\/]+\/$//;
313 return "$path$reldir/Makefile";
316 # preserve shared source files that are listed in the existing makefile
317 sub preserve_shared_source_files($$$)
319 my ($make, $parent, $var) = @_;
320 my %srcs;
322 return unless defined ${$parent}{"=$var"};
323 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
324 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
326 foreach my $file (@{${$make}{$var}})
328 next unless defined $srcs{$file} && $srcs{$file} == 1;
329 push @{${$make}{"=$var"}}, $file;
333 # assign source files to their respective makefile
334 sub assign_sources_to_makefiles(@)
336 foreach my $file (@_)
338 next if defined $ignored_source_files{$file};
339 next if $file =~ /Makefile\.in$/;
340 my $dir = dirname( $file );
341 my $subdir = $dir;
343 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
344 $subdir =~ s/^$dir\/?//;
345 next unless $dir;
347 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
349 my $make = $makefiles{"$dir/Makefile"};
350 my $name = substr( $file, length($dir) + 1 );
351 my %flags = get_makedep_flags( $file );
353 next if $file =~ /^include\/wine\// && !%flags && !$exported_wine_headers{$name};
355 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
357 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
358 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
359 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
360 elsif ($name =~ /\.x$/) { push @{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
361 elsif ($name =~ /\.rh$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
362 elsif ($name =~ /\.inl$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
363 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
364 elsif ($name =~ /\.sfd$/)
366 ${${$make}{"=flags"}}{"clean"} = 1 if defined $flags{"font"};
367 ${${$make}{"=flags"}}{"install-lib"} = 1 if defined $flags{"install"};
368 push @{${$make}{"=FONT_SRCS"}}, $name;
370 elsif ($name =~ /\.c$/)
372 ${${$make}{"=flags"}}{"staticimplib"} = 1 if defined $flags{"implib"};
373 push @{${$make}{"=C_SRCS"}}, $name;
375 elsif ($name =~ /\.h$/)
377 next if $dir ne "include";
378 push @{${$make}{"=HEADER_SRCS"}}, $name;
379 ${${$make}{"=flags"}}{"install-dev"} = 1;
381 elsif ($name =~ /\.rc$/)
383 ${${$make}{"=flags"}}{"clean"} = 1 if defined $flags{"po"};
384 push @{${$make}{"=RC_SRCS"}}, $name;
386 elsif ($name =~ /\.mc$/)
388 push @{${$make}{"=MC_SRCS"}}, $name;
389 ${${$make}{"=flags"}}{"clean"} = 1;
391 elsif ($name =~ /\.po$/)
393 push @{${$make}{"=PO_SRCS"}}, $name;
394 ${${$make}{"=flags"}}{"clean"} = 1;
396 elsif ($name =~ /\.idl$/)
398 die "no makedep flags specified in $file" unless %flags || $dir eq "include";
399 push @{${$make}{"=IDL_SRCS"}}, $name;
400 ${${$make}{"=flags"}}{"clean"} = 1;
402 elsif ($name =~ /\.man\.in$/)
404 push @{${$make}{"=MANPAGES"}}, $name;
405 ${${$make}{"=flags"}}{($file =~ /^programs\//) ? "manpage" : "clean"} = 1;
407 elsif ($name =~ /\.in$/)
409 push @{${$make}{"=IN_SRCS"}}, $name;
413 # preserve shared source files from the parent makefile
414 foreach my $file (@makefiles)
416 my $make = $makefiles{$file};
417 my $parent = get_parent_makefile( $file );
418 next unless $parent;
419 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
420 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
421 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
422 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
423 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @{${$make}{"=IDL_SRCS"}};
427 ################################################################
428 # update the makefile list in configure.ac
430 sub update_makefiles(@)
432 my (@lines);
434 foreach my $file (sort @_)
436 my %make = %{$makefiles{$file}};
437 my $args = "";
438 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
439 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
440 if (defined($make{"TESTDLL"})) # test
442 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
443 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
444 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
445 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
446 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
448 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
450 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
451 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
452 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
453 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
454 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
456 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
458 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
459 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
460 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
461 if ($name =~ /\./)
463 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
465 else
467 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
469 $args .= "," if $is_win16 || defined $make{"=flags"};
470 $args .= "enable_win16" if $is_win16;
471 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
473 elsif (defined($make{"MODULE"})) # dll
475 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
476 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
477 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
478 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
479 if ($name =~ /\./)
481 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
483 else
485 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
487 my $implib = $make{"IMPORTLIB"} || "";
488 $args .= "," if $is_win16 || defined $make{"=flags"};
489 $args .= "enable_win16" if $is_win16;
490 $args .= $flag_args;
491 $args .= ",[$implib]" if $implib && $implib ne $name;
492 push @lines, "WINE_CONFIG_DLL($name$args)\n";
494 elsif ($file =~ /^tools.*\/Makefile$/)
496 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
497 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
498 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
499 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
501 elsif ($file =~ /\/Makefile$/)
503 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
504 $args = "[$name]";
505 $args .= "," if defined $make{"=flags"};
506 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
510 # update the source variables in all the makefiles
512 foreach my $file (sort @_)
514 replace_makefile_variable( $file, "LEX_SRCS" );
515 replace_makefile_variable( $file, "BISON_SRCS" );
516 replace_makefile_variable( $file, "MC_SRCS" );
517 replace_makefile_variable( $file, "SVG_SRCS" );
518 replace_makefile_variable( $file, "FONT_SRCS" );
519 replace_makefile_variable( $file, "C_SRCS" );
520 replace_makefile_variable( $file, "OBJC_SRCS" );
521 replace_makefile_variable( $file, "RC_SRCS" );
522 replace_makefile_variable( $file, "IDL_SRCS" );
523 replace_makefile_variable( $file, "HEADER_SRCS" );
524 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
525 replace_makefile_variable( $file, "PO_SRCS" );
526 replace_makefile_variable( $file, "IN_SRCS" );
527 replace_makefile_variable( $file, "MANPAGES" );
530 push @lines, "dnl End of auto-generated output commands\n";
531 replace_in_file( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
535 my $git_dir = $ENV{GIT_DIR} || ".git";
536 die "needs to be run from a git checkout" unless -d $git_dir;
538 my @all_files = split /\0/, `git ls-files -c -z`;
539 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
541 foreach my $file (sort @makefiles)
543 my %make = parse_makefile( $file );
544 $makefiles{$file} = \%make;
547 assign_sources_to_makefiles( @all_files );
548 update_makefiles( @makefiles );