gdi32: Take into account the mask's offset.
[wine.git] / tools / make_makefiles
blob7229d061a5ea8066ec17d6720db36ebccff3765f
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 %private_idl_headers = (
51 "access.idl" => 1,
52 "asynot.idl" => 1,
53 "asysta.idl" => 1,
54 "axcore.idl" => 1,
55 "axextend.idl" => 1,
56 "binres.idl" => 1,
57 "chprst.idl" => 1,
58 "cmdbas.idl" => 1,
59 "cmdtxt.idl" => 1,
60 "crtrow.idl" => 1,
61 "dbccmd.idl" => 1,
62 "dbcses.idl" => 1,
63 "dbdsad.idl" => 1,
64 "dbinit.idl" => 1,
65 "dbprop.idl" => 1,
66 "dbs.idl" => 1,
67 "devenum.idl" => 1,
68 "dyngraph.idl" => 1,
69 "errrec.idl" => 1,
70 "opnrst.idl" => 1,
71 "row.idl" => 1,
72 "rowchg.idl" => 1,
73 "rowpos.idl" => 1,
74 "rowpsc.idl" => 1,
75 "rstbas.idl" => 1,
76 "rstinf.idl" => 1,
77 "rstloc.idl" => 1,
78 "rstnot.idl" => 1,
79 "srcrst.idl" => 1,
80 "sesprp.idl" => 1,
81 "vmrender.idl" => 1,
82 "xmldom.idl" => 1,
83 "xmldso.idl" => 1,
84 "wine/winedxgi.idl" => 1,
87 my %ignored_source_files = (
88 "dlls/wineps.drv/afm2c.c" => 1,
89 "dlls/wineps.drv/mkagl.c" => 1,
90 "programs/winetest/dist.rc" => 1,
91 "tools/makedep.c" => 1,
94 my (@linguas, @makefiles, %makefiles);
96 sub dirname($)
98 my $ret = shift;
99 return "" unless $ret =~ /\//;
100 $ret =~ s!/[^/]*$!!;
101 return $ret;
104 # update a file if changed
105 sub update_file($)
107 my $file = shift;
108 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
109 if (!$ret)
111 unlink "$file.new";
113 else
115 rename "$file.new", "$file";
116 print "$file updated\n";
117 if ($file eq "configure.ac")
119 system "autoconf";
120 print "configure updated\n";
123 return $ret;
126 # replace some lines in a file between two markers
127 sub replace_in_file($$$@)
129 my $file = shift;
130 my $start = shift;
131 my $end = shift;
133 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
135 if (defined($start))
137 open OLD_FILE, "$file" or die "cannot open $file";
138 while (<OLD_FILE>)
140 last if /$start/;
141 print NEW_FILE $_;
145 print NEW_FILE @_;
147 if (defined($end))
149 my $skip=1;
150 while (<OLD_FILE>)
152 print NEW_FILE $_ unless $skip;
153 $skip = 0 if /$end/;
157 close OLD_FILE if defined($start);
158 close NEW_FILE;
159 return update_file($file);
162 # replace a variable in a makefile
163 sub replace_makefile_variable($$)
165 my ($file, $var) = @_;
166 my $make = $makefiles{$file};
167 my $replaced = 0;
168 my @values;
170 if (defined ${$make}{"=$var"})
172 @values = @{${$make}{"=$var"}};
173 ${$make}{$var} = \@values;
175 else
177 return unless defined ${$make}{$var};
178 undef ${$make}{$var};
181 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
183 open OLD_FILE, "$file.in" or die "cannot open $file.in";
184 while (<OLD_FILE>)
186 if (/^\s*($var\s*)=/)
188 # try to preserve formatting
189 my $prefix = $1;
190 my $multiline = /\\$/ || (@values > 1);
191 while (/\\$/)
193 $_ = <OLD_FILE>;
194 last unless $_;
196 if (!@values)
198 # nothing
200 elsif ($multiline)
202 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
204 else
206 print NEW_FILE "$prefix= @values\n";
208 $replaced = 1;
209 next;
211 if (/^\@MAKE/ && !$replaced && @values)
213 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
215 print NEW_FILE $_;
217 close OLD_FILE;
218 close NEW_FILE;
219 return update_file("$file.in");
222 # parse the specified makefile and load the variables
223 sub parse_makefile($)
225 my $file = shift;
226 my %make;
228 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
230 open MAKE, "$file.in" or die "cannot open $file.in\n";
232 while (<MAKE>)
234 chomp;
235 next if (/^\s*#/);
236 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
237 next if (/^\s*$/);
239 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
241 my $var = $1;
242 $make{$var} = $2;
243 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
244 next;
246 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_SRCS|IMPLIB_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*(.*)/)
248 my $var = $1;
249 my @list = split(/\s+/, $2);
250 $make{$var} = \@list;
251 next;
253 if (/(install-lib|install-dev|clean)\s*:/)
255 ${$make{"=flags"}}{$1} = 1;
256 next;
258 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
260 die "Variable $1 in $file.in is obsolete";
262 if (/\@[A-Z_]+\@/) # config.status substitution variable
264 ${$make{"=flags"}}{"config"} = 1;
268 if ($file =~ /^programs\/([^\/]+)\/Makefile/)
270 my $prog = $1;
271 if (defined $make{"INSTALL_LIB"})
273 ${$make{"=flags"}}{"install"} = 1 if grep { "$prog.exe" eq $_; } @{$make{"INSTALL_LIB"}};
274 ${$make{"=flags"}}{"installbin"} = 1 if grep { $prog eq $_; } @{$make{"INSTALL_LIB"}};
276 else
278 ${$make{"=flags"}}{"install"} = 1;
282 unless (defined $make{"MODULE"})
284 ${$make{"=flags"}}{"install-lib"} = 1 if defined $make{"INSTALL_LIB"};
285 ${$make{"=flags"}}{"install-dev"} = 1 if defined $make{"INSTALL_DEV"};
287 ${$make{"=flags"}}{"clean"} = 1 if defined $make{"PROGRAMS"} || defined $make{"EXTRA_TARGETS"};
289 if (defined $make{"=flags"} && defined $make{"MODULE"})
291 die "Custom install-lib rule not allowed in $file" if defined ${$make{"=flags"}}{"install-lib"};
292 die "Custom install-dev rule not allowed in $file" if defined ${$make{"=flags"}}{"install-dev"};
295 return %make;
298 # read pragma makedep flags from a source file
299 sub get_makedep_flags($)
301 my $file = shift;
302 my %flags;
304 open FILE, $file or die "cannot open $file";
305 while (<FILE>)
307 next unless /^#\s*pragma\s+makedep\s+(.*)/;
308 foreach my $flag (split /\s+/, $1)
310 last if $flag eq "depend";
311 $flags{$flag} = 1;
314 close FILE;
315 return %flags;
318 sub get_parent_makefile($)
320 my $file = shift;
321 my %make = %{$makefiles{$file}};
322 my $reldir = $make{"PARENTSRC"} || "";
323 return "" unless $reldir;
324 (my $path = $file) =~ s/\/Makefile$/\//;
325 while ($reldir =~ /^\.\.\//)
327 $reldir =~ s/^\.\.\///;
328 $path =~ s/[^\/]+\/$//;
330 return "$path$reldir/Makefile";
333 # preserve shared source files that are listed in the existing makefile
334 sub preserve_shared_source_files($$$)
336 my ($make, $parent, $var) = @_;
337 my %srcs;
339 return unless defined ${$parent}{"=$var"};
340 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
341 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
343 foreach my $file (@{${$make}{$var}})
345 next unless defined $srcs{$file} && $srcs{$file} == 1;
346 push @{${$make}{"=$var"}}, $file;
350 # assign source files to their respective makefile
351 sub assign_sources_to_makefiles(@)
353 foreach my $file (@_)
355 next if defined $ignored_source_files{$file};
356 next if $file =~ /Makefile\.in$/;
357 my $dir = dirname( $file );
358 my $subdir = $dir;
360 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
361 $subdir =~ s/^$dir\/?//;
362 next unless $dir;
364 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
366 my $make = $makefiles{"$dir/Makefile"};
367 my $name = substr( $file, length($dir) + 1 );
369 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
371 if ($dir eq "include")
373 next if ($name =~ /\.in$/);
374 if ($name =~ /^wine\// && !$exported_wine_headers{$name})
376 if ($private_idl_headers{$name}) { push @{${$make}{"=PRIVATE_IDL_H_SRCS"}}, $name; }
377 next;
379 if ($name =~ /stdole2\.idl$/) { push @{${$make}{"=IDL_TLB_SRCS"}}, $name; }
380 elsif ($private_idl_headers{$name}) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
381 elsif ($name =~ /\.h$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
382 elsif ($name =~ /\.x$/) { push @{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
383 elsif ($name =~ /\.rh$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
384 elsif ($name =~ /\.inl$/) { push @{${$make}{"=HEADER_SRCS"}}, $name; }
385 elsif ($name =~ /\.idl$/) { push @{${$make}{"=PUBLIC_IDL_H_SRCS"}}, $name; }
386 else { die "unknown file $name in include dir"; }
388 else
390 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
391 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
392 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
393 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
394 elsif ($name =~ /\.sfd$/) { push @{${$make}{"=FONT_SRCS"}}, $name; }
395 elsif ($name =~ /\.c$/)
397 my %flags = get_makedep_flags( $file );
398 if (defined $flags{"implib"})
400 push @{${$make}{"=IMPLIB_SRCS"}}, $name;
401 ${${$make}{"=flags"}}{"staticimplib"} = 1;
403 push @{${$make}{"=C_SRCS"}}, $name;
405 elsif ($name =~ /\.rc$/)
407 my %flags = get_makedep_flags( $file );
408 ${${$make}{"=flags"}}{"po"} = 1 if defined $flags{"po"};
409 push @{${$make}{"=RC_SRCS"}}, $name;
411 elsif ($name =~ /\.mc$/)
413 push @{${$make}{"=MC_SRCS"}}, $name;
414 ${${$make}{"=flags"}}{"mc"} = 1;
416 elsif ($name =~ /\.idl$/)
418 my %flags = get_makedep_flags( $file );
419 die "no makedep flags specified in $file" unless %flags;
420 push @{${$make}{"=IDL_SRCS"}}, $name;
421 ${${$make}{"=flags"}}{"clean"} = 1;
423 elsif ($name =~ /\.man\.in$/)
425 push @{${$make}{"=MANPAGES"}}, $name;
426 ${${$make}{"=flags"}}{"manpage"} = 1;
428 elsif ($name =~ /\.in$/)
430 push @{${$make}{"=IN_SRCS"}}, $name;
435 # add extra variables to include source list
436 my $make = $makefiles{"include/Makefile"};
437 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(PUBLIC_IDL_H_SRCS)";
438 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(IDL_TLB_SRCS)";
439 unshift @{${$make}{"=IDL_SRCS"}}, "\$(IDL_H_SRCS) \$(IDL_TLB_SRCS)";
441 # preserve shared source files from the parent makefile
442 foreach my $file (@makefiles)
444 my $make = $makefiles{$file};
445 my $parent = get_parent_makefile( $file );
446 next unless $parent;
447 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
448 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
449 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
450 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
451 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @{${$make}{"=IDL_SRCS"}};
455 ################################################################
456 # update the makefile list in configure.ac
458 sub update_makefiles(@)
460 my (@lines);
462 foreach my $file (sort @_)
464 my %make = %{$makefiles{$file}};
465 my $args = "";
466 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
467 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
468 if (defined($make{"TESTDLL"})) # test
470 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
471 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
472 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
473 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
474 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
476 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
478 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
479 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
480 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
481 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
482 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
484 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
486 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
487 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
488 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
489 if ($name =~ /\./)
491 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
493 else
495 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
497 $args .= "," if $is_win16 || defined $make{"=flags"};
498 $args .= "enable_win16" if $is_win16;
499 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
501 elsif (defined($make{"MODULE"})) # dll
503 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
504 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
505 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
506 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
507 if ($name =~ /\./)
509 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
511 else
513 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
515 my $implib = $make{"IMPORTLIB"} || "";
516 $args .= "," if $is_win16 || defined $make{"=flags"};
517 $args .= "enable_win16" if $is_win16;
518 $args .= $flag_args;
519 $args .= ",[$implib]" if $implib && $implib ne $name;
520 push @lines, "WINE_CONFIG_DLL($name$args)\n";
522 elsif ($file =~ /^tools.*\/Makefile$/)
524 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
525 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
526 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
527 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
529 elsif ($file =~ /\/Makefile$/)
531 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
532 $args = "[$name]";
533 $args .= "," if defined $make{"=flags"};
534 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
538 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
540 # update the source variables in all the makefiles
542 foreach my $file (sort @_)
544 replace_makefile_variable( $file, "LEX_SRCS" );
545 replace_makefile_variable( $file, "BISON_SRCS" );
546 replace_makefile_variable( $file, "MC_SRCS" );
547 replace_makefile_variable( $file, "SVG_SRCS" );
548 replace_makefile_variable( $file, "FONT_SRCS" );
549 replace_makefile_variable( $file, "C_SRCS" );
550 replace_makefile_variable( $file, "OBJC_SRCS" );
551 replace_makefile_variable( $file, "RC_SRCS" );
552 replace_makefile_variable( $file, "IDL_SRCS" );
553 replace_makefile_variable( $file, "HEADER_SRCS" );
554 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
555 replace_makefile_variable( $file, "IN_SRCS" );
556 replace_makefile_variable( $file, "IMPLIB_SRCS" );
557 replace_makefile_variable( $file, "MANPAGES" );
558 next unless $file eq "include/Makefile";
559 replace_makefile_variable( $file, "PRIVATE_IDL_H_SRCS" );
560 replace_makefile_variable( $file, "PUBLIC_IDL_H_SRCS" );
561 replace_makefile_variable( $file, "IDL_TLB_SRCS" );
562 replace_makefile_variable( $file, "SRCDIR_INCLUDES" );
565 push @lines, "dnl End of auto-generated output commands\n";
566 replace_in_file( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
570 ################################################################
571 # update the LINGUAS file
573 sub update_linguas(@)
575 replace_in_file( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
579 my $git_dir = $ENV{GIT_DIR} || ".git";
580 die "needs to be run from a git checkout" unless -d $git_dir;
582 my @all_files = split /\0/, `git ls-files -c -z`;
583 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\/.*\.po$/, @all_files;
584 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
586 foreach my $file (sort @makefiles)
588 my %make = parse_makefile( $file );
589 $makefiles{$file} = \%make;
592 assign_sources_to_makefiles( @all_files );
593 update_linguas( @linguas );
594 update_makefiles( @makefiles );