winemac: Use CVDisplayLink to limit window redrawing to the display refresh rate.
[wine.git] / tools / make_makefiles
blob28e448a9bd1b661da3a6a6f56be3e8c699a0a997
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 (@linguas, @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 (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
205 my $var = $1;
206 $make{$var} = $2;
207 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
208 next;
210 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_SRCS|C_SRCS|OBJC_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|FONT_SRCS|IN_SRCS|PROGRAMS|EXTRA_TARGETS|MANPAGES|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
212 my $var = $1;
213 my @list = split(/\s+/, $2);
214 $make{$var} = \@list;
215 next;
217 if (/(install-lib|install-dev|clean)\s*:/)
219 ${$make{"=flags"}}{$1} = 1;
220 next;
222 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
224 die "Variable $1 in $file.in is obsolete";
226 if (/\@[A-Z_]+\@/) # config.status substitution variable
228 ${$make{"=flags"}}{"config"} = 1;
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"};
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 while (<FILE>)
271 next unless /^#\s*pragma\s+makedep\s+(.*)/;
272 foreach my $flag (split /\s+/, $1)
274 last if $flag eq "depend";
275 $flags{$flag} = 1;
278 close FILE;
279 return %flags;
282 sub get_parent_makefile($)
284 my $file = shift;
285 my %make = %{$makefiles{$file}};
286 my $reldir = $make{"PARENTSRC"} || "";
287 return "" unless $reldir;
288 (my $path = $file) =~ s/\/Makefile$/\//;
289 while ($reldir =~ /^\.\.\//)
291 $reldir =~ s/^\.\.\///;
292 $path =~ s/[^\/]+\/$//;
294 return "$path$reldir/Makefile";
297 # preserve shared source files that are listed in the existing makefile
298 sub preserve_shared_source_files($$$)
300 my ($make, $parent, $var) = @_;
301 my %srcs;
303 return unless defined ${$parent}{"=$var"};
304 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
305 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
307 foreach my $file (@{${$make}{$var}})
309 next unless defined $srcs{$file} && $srcs{$file} == 1;
310 push @{${$make}{"=$var"}}, $file;
314 # assign source files to their respective makefile
315 sub assign_sources_to_makefiles(@)
317 foreach my $file (@_)
319 next if defined $ignored_source_files{$file};
320 next if $file =~ /Makefile\.in$/;
321 my $dir = dirname( $file );
322 my $subdir = $dir;
324 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
325 $subdir =~ s/^$dir\/?//;
326 next unless $dir;
328 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
330 my $make = $makefiles{"$dir/Makefile"};
331 my $name = substr( $file, length($dir) + 1 );
332 my %flags = get_makedep_flags( $file );
334 next if $file =~ /^include\/wine\// && !%flags && !$exported_wine_headers{$name};
336 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
338 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
339 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
340 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
341 elsif ($name =~ /\.x$/) { push @{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
342 elsif ($name =~ /\.rh$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
343 elsif ($name =~ /\.inl$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
344 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
345 elsif ($name =~ /\.sfd$/) { push @{${$make}{"=FONT_SRCS"}}, $name; }
346 elsif ($name =~ /\.c$/)
348 ${${$make}{"=flags"}}{"staticimplib"} = 1 if defined $flags{"implib"};
349 push @{${$make}{"=C_SRCS"}}, $name;
351 elsif ($name =~ /\.h$/)
353 next if $dir ne "include";
354 push @{${$make}{"=HEADER_SRCS"}}, $name;
355 ${${$make}{"=flags"}}{"install-dev"} = 1;
357 elsif ($name =~ /\.rc$/)
359 ${${$make}{"=flags"}}{"po"} = 1 if defined $flags{"po"};
360 push @{${$make}{"=RC_SRCS"}}, $name;
362 elsif ($name =~ /\.mc$/)
364 push @{${$make}{"=MC_SRCS"}}, $name;
365 ${${$make}{"=flags"}}{"mc"} = 1;
367 elsif ($name =~ /\.idl$/)
369 die "no makedep flags specified in $file" unless %flags || $dir eq "include";
370 push @{${$make}{"=IDL_SRCS"}}, $name;
371 ${${$make}{"=flags"}}{"clean"} = 1;
373 elsif ($name =~ /\.man\.in$/)
375 push @{${$make}{"=MANPAGES"}}, $name;
376 ${${$make}{"=flags"}}{"manpage"} = 1;
378 elsif ($name =~ /\.in$/)
380 push @{${$make}{"=IN_SRCS"}}, $name;
384 # preserve shared source files from the parent makefile
385 foreach my $file (@makefiles)
387 my $make = $makefiles{$file};
388 my $parent = get_parent_makefile( $file );
389 next unless $parent;
390 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
391 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
392 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
393 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
394 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @{${$make}{"=IDL_SRCS"}};
398 ################################################################
399 # update the makefile list in configure.ac
401 sub update_makefiles(@)
403 my (@lines);
405 foreach my $file (sort @_)
407 my %make = %{$makefiles{$file}};
408 my $args = "";
409 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
410 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
411 if (defined($make{"TESTDLL"})) # test
413 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
414 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
415 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
416 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
417 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
419 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
421 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
422 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
423 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
424 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
425 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
427 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
429 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
430 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
431 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
432 if ($name =~ /\./)
434 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
436 else
438 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
440 $args .= "," if $is_win16 || defined $make{"=flags"};
441 $args .= "enable_win16" if $is_win16;
442 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
444 elsif (defined($make{"MODULE"})) # dll
446 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
447 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
448 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
449 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
450 if ($name =~ /\./)
452 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
454 else
456 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
458 my $implib = $make{"IMPORTLIB"} || "";
459 $args .= "," if $is_win16 || defined $make{"=flags"};
460 $args .= "enable_win16" if $is_win16;
461 $args .= $flag_args;
462 $args .= ",[$implib]" if $implib && $implib ne $name;
463 push @lines, "WINE_CONFIG_DLL($name$args)\n";
465 elsif ($file =~ /^tools.*\/Makefile$/)
467 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
468 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
469 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
470 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
472 elsif ($file =~ /\/Makefile$/)
474 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
475 $args = "[$name]";
476 $args .= "," if defined $make{"=flags"};
477 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
481 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
483 # update the source variables in all the makefiles
485 foreach my $file (sort @_)
487 replace_makefile_variable( $file, "LEX_SRCS" );
488 replace_makefile_variable( $file, "BISON_SRCS" );
489 replace_makefile_variable( $file, "MC_SRCS" );
490 replace_makefile_variable( $file, "SVG_SRCS" );
491 replace_makefile_variable( $file, "FONT_SRCS" );
492 replace_makefile_variable( $file, "C_SRCS" );
493 replace_makefile_variable( $file, "OBJC_SRCS" );
494 replace_makefile_variable( $file, "RC_SRCS" );
495 replace_makefile_variable( $file, "IDL_SRCS" );
496 replace_makefile_variable( $file, "HEADER_SRCS" );
497 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
498 replace_makefile_variable( $file, "IN_SRCS" );
499 replace_makefile_variable( $file, "MANPAGES" );
502 push @lines, "dnl End of auto-generated output commands\n";
503 replace_in_file( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
507 ################################################################
508 # update the LINGUAS file
510 sub update_linguas(@)
512 replace_in_file( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
516 my $git_dir = $ENV{GIT_DIR} || ".git";
517 die "needs to be run from a git checkout" unless -d $git_dir;
519 my @all_files = split /\0/, `git ls-files -c -z`;
520 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\/.*\.po$/, @all_files;
521 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
523 foreach my $file (sort @makefiles)
525 my %make = parse_makefile( $file );
526 $makefiles{$file} = \%make;
529 assign_sources_to_makefiles( @all_files );
530 update_linguas( @linguas );
531 update_makefiles( @makefiles );