dwrite: Pass drawing effect to renderer in DrawStrikethrough().
[wine.git] / tools / make_makefiles
blobe65429f60ff90ef057c0275d96c8c774745f3ee5
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 (/\@[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|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"}}{"po"} = 1 if defined $flags{"po"};
384 push @{${$make}{"=RC_SRCS"}}, $name;
386 elsif ($name =~ /\.mc$/)
388 push @{${$make}{"=MC_SRCS"}}, $name;
389 ${${$make}{"=flags"}}{"mc"} = 1;
391 elsif ($name =~ /\.idl$/)
393 die "no makedep flags specified in $file" unless %flags || $dir eq "include";
394 push @{${$make}{"=IDL_SRCS"}}, $name;
395 ${${$make}{"=flags"}}{"clean"} = 1;
397 elsif ($name =~ /\.man\.in$/)
399 push @{${$make}{"=MANPAGES"}}, $name;
400 ${${$make}{"=flags"}}{($file =~ /^programs\//) ? "manpage" : "clean"} = 1;
402 elsif ($name =~ /\.in$/)
404 push @{${$make}{"=IN_SRCS"}}, $name;
408 # preserve shared source files from the parent makefile
409 foreach my $file (@makefiles)
411 my $make = $makefiles{$file};
412 my $parent = get_parent_makefile( $file );
413 next unless $parent;
414 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
415 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
416 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
417 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
418 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @{${$make}{"=IDL_SRCS"}};
422 ################################################################
423 # update the makefile list in configure.ac
425 sub update_makefiles(@)
427 my (@lines);
429 foreach my $file (sort @_)
431 my %make = %{$makefiles{$file}};
432 my $args = "";
433 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
434 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
435 if (defined($make{"TESTDLL"})) # test
437 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
438 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
439 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
440 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
441 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
443 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
445 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
446 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
447 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
448 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
449 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
451 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
453 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
454 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
455 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
456 if ($name =~ /\./)
458 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
460 else
462 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
464 $args .= "," if $is_win16 || defined $make{"=flags"};
465 $args .= "enable_win16" if $is_win16;
466 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
468 elsif (defined($make{"MODULE"})) # dll
470 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
471 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
472 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
473 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
474 if ($name =~ /\./)
476 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
478 else
480 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
482 my $implib = $make{"IMPORTLIB"} || "";
483 $args .= "," if $is_win16 || defined $make{"=flags"};
484 $args .= "enable_win16" if $is_win16;
485 $args .= $flag_args;
486 $args .= ",[$implib]" if $implib && $implib ne $name;
487 push @lines, "WINE_CONFIG_DLL($name$args)\n";
489 elsif ($file =~ /^tools.*\/Makefile$/)
491 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
492 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
493 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
494 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
496 elsif ($file =~ /\/Makefile$/)
498 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
499 $args = "[$name]";
500 $args .= "," if defined $make{"=flags"};
501 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
505 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
507 # update the source variables in all the makefiles
509 foreach my $file (sort @_)
511 replace_makefile_variable( $file, "LEX_SRCS" );
512 replace_makefile_variable( $file, "BISON_SRCS" );
513 replace_makefile_variable( $file, "MC_SRCS" );
514 replace_makefile_variable( $file, "SVG_SRCS" );
515 replace_makefile_variable( $file, "FONT_SRCS" );
516 replace_makefile_variable( $file, "C_SRCS" );
517 replace_makefile_variable( $file, "OBJC_SRCS" );
518 replace_makefile_variable( $file, "RC_SRCS" );
519 replace_makefile_variable( $file, "IDL_SRCS" );
520 replace_makefile_variable( $file, "HEADER_SRCS" );
521 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
522 replace_makefile_variable( $file, "IN_SRCS" );
523 replace_makefile_variable( $file, "MANPAGES" );
526 push @lines, "dnl End of auto-generated output commands\n";
527 replace_in_file( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
531 ################################################################
532 # update the LINGUAS file
534 sub update_linguas(@)
536 replace_in_file( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
540 my $git_dir = $ENV{GIT_DIR} || ".git";
541 die "needs to be run from a git checkout" unless -d $git_dir;
543 my @all_files = split /\0/, `git ls-files -c -z`;
544 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\/.*\.po$/, @all_files;
545 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
547 foreach my $file (sort @makefiles)
549 my %make = parse_makefile( $file );
550 $makefiles{$file} = \%make;
553 assign_sources_to_makefiles( @all_files );
554 update_linguas( @linguas );
555 update_makefiles( @makefiles );