winex11.drv: Track external changes to _NET_WM_STATE in net_wm_state.
[wine.git] / tools / make_makefiles
blobf0b40c0e8f267020cad85931bfb3e3f9f3211e1c
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 # Programs that we want to install in the bin directory too
25 my %bin_install =
27 "msiexec" => 1,
28 "notepad" => 1,
29 "regedit" => 1,
30 "regsvr32" => 1,
31 "wineboot" => 1,
32 "winecfg" => 1,
33 "wineconsole" => 1,
34 "winedbg" => 1,
35 "winefile" => 1,
36 "winemine" => 1,
37 "winepath" => 1,
40 # Programs that we don't want to install at all
41 my %dont_install =
43 "winetest" => 1,
46 # Dlls and programs that are 16-bit specific
47 my %modules16 =
49 "ifsmgr.vxd" => 1,
50 "mmdevldr.vxd" => 1,
51 "monodebg.vxd" => 1,
52 "vdhcp.vxd" => 1,
53 "vmm.vxd" => 1,
54 "vnbt.vxd" => 1,
55 "vnetbios.vxd" => 1,
56 "vtdapi.vxd" => 1,
57 "vwin32.vxd" => 1,
58 "w32skrnl.dll" => 1,
59 "winevdm.exe" => 1,
60 "wow32.dll" => 1,
63 my %exported_wine_headers = (
64 "wine/debug.h" => 1,
65 "wine/exception.h" => 1,
66 "wine/library.h" => 1,
67 "wine/unicode.h" => 1,
68 "wine/itss.idl" => 1,
69 "wine/svcctl.idl" => 1,
72 my %private_idl_headers = (
73 "access.idl" => 1,
74 "asynot.idl" => 1,
75 "asysta.idl" => 1,
76 "axcore.idl" => 1,
77 "axextend.idl" => 1,
78 "binres.idl" => 1,
79 "chprst.idl" => 1,
80 "cmdbas.idl" => 1,
81 "cmdtxt.idl" => 1,
82 "crtrow.idl" => 1,
83 "dbccmd.idl" => 1,
84 "dbcses.idl" => 1,
85 "dbdsad.idl" => 1,
86 "dbinit.idl" => 1,
87 "dbprop.idl" => 1,
88 "dbs.idl" => 1,
89 "devenum.idl" => 1,
90 "dyngraph.idl" => 1,
91 "errrec.idl" => 1,
92 "opnrst.idl" => 1,
93 "row.idl" => 1,
94 "rowchg.idl" => 1,
95 "rowpos.idl" => 1,
96 "rowpsc.idl" => 1,
97 "rstbas.idl" => 1,
98 "rstinf.idl" => 1,
99 "rstloc.idl" => 1,
100 "rstnot.idl" => 1,
101 "srcrst.idl" => 1,
102 "sesprp.idl" => 1,
103 "vmrender.idl" => 1,
104 "xmldom.idl" => 1,
105 "xmldso.idl" => 1,
106 "wine/winedxgi.idl" => 1,
109 my %ignored_source_files = (
110 "dlls/wineps.drv/afm2c.c" => 1,
111 "dlls/wineps.drv/mkagl.c" => 1,
112 "programs/winetest/dist.rc" => 1,
115 my (@linguas, @makefiles, %makefiles);
117 sub dirname($)
119 my $ret = shift;
120 return "" unless $ret =~ /\//;
121 $ret =~ s!/[^/]*$!!;
122 return $ret;
125 # update a file if changed
126 sub update_file($)
128 my $file = shift;
129 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
130 if (!$ret)
132 unlink "$file.new";
134 else
136 rename "$file.new", "$file";
137 print "$file updated\n";
138 if ($file eq "configure.ac")
140 system "autoconf";
141 print "configure updated\n";
144 return $ret;
147 # replace some lines in a file between two markers
148 sub replace_in_file($$$@)
150 my $file = shift;
151 my $start = shift;
152 my $end = shift;
154 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
156 if (defined($start))
158 open OLD_FILE, "$file" or die "cannot open $file";
159 while (<OLD_FILE>)
161 last if /$start/;
162 print NEW_FILE $_;
166 print NEW_FILE @_;
168 if (defined($end))
170 my $skip=1;
171 while (<OLD_FILE>)
173 print NEW_FILE $_ unless $skip;
174 $skip = 0 if /$end/;
178 close OLD_FILE if defined($start);
179 close NEW_FILE;
180 return update_file($file);
183 # replace a variable in a makefile
184 sub replace_makefile_variable($$)
186 my ($file, $var) = @_;
187 my $make = $makefiles{$file};
188 my $replaced = 0;
189 my @values;
191 if (defined ${$make}{"=$var"})
193 @values = @{${$make}{"=$var"}};
194 ${$make}{$var} = \@values;
196 else
198 return unless defined ${$make}{$var};
199 undef ${$make}{$var};
202 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
204 open OLD_FILE, "$file.in" or die "cannot open $file.in";
205 while (<OLD_FILE>)
207 if (/^\s*($var\s*)=/)
209 # try to preserve formatting
210 my $prefix = $1;
211 my $multiline = /\\$/ || (@values > 1);
212 while (/\\$/)
214 $_ = <OLD_FILE>;
215 last unless $_;
217 if (!@values)
219 # nothing
221 elsif ($multiline)
223 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
225 else
227 print NEW_FILE "$prefix= @values\n";
229 $replaced = 1;
230 next;
232 if (/^\@MAKE/ && !$replaced && @values)
234 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
236 print NEW_FILE $_;
238 close OLD_FILE;
239 close NEW_FILE;
240 return update_file("$file.in");
243 # parse the specified makefile and load the variables
244 sub parse_makefile($)
246 my $file = shift;
247 my %make;
249 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
251 open MAKE, "$file.in" or die "cannot open $file.in\n";
253 while (<MAKE>)
255 chomp;
256 next if (/^\s*#/);
257 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
258 next if (/^\s*$/);
260 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
262 my $var = $1;
263 $make{$var} = $2;
264 ${$make{"=flags"}}{"implib"} = 1 if $var eq "IMPORTLIB";
265 next;
267 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)\s*=\s*(.*)/)
269 my $var = $1;
270 my @list = split(/\s+/, $2);
271 $make{$var} = \@list;
272 ${$make{"=flags"}}{"clean"} = 1 if $var eq "PROGRAMS";
273 ${$make{"=flags"}}{"clean"} = 1 if $var eq "EXTRA_TARGETS";
274 next;
276 if (/(install-lib|install-dev|clean)\s*:/)
278 ${$make{"=flags"}}{$1} = 1;
279 next;
281 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
283 die "Variable $1 in $file.in is obsolete";
287 if ($file =~ /^programs\/([^\/]+)\/Makefile/)
289 ${$make{"=flags"}}{"install"} = 1 unless $dont_install{$1};
290 ${$make{"=flags"}}{"installbin"} = 1 if $bin_install{$1};
293 if (defined $make{"=flags"} && defined $make{"MODULE"})
295 die "Custom install-lib rule not allowed in $file" if defined ${$make{"=flags"}}{"install-lib"};
296 die "Custom install-dev rule not allowed in $file" if defined ${$make{"=flags"}}{"install-dev"};
299 return %make;
302 # read pragma makedep flags from a source file
303 sub get_makedep_flags($)
305 my $file = shift;
306 my %flags;
308 open FILE, $file or die "cannot open $file";
309 while (<FILE>)
311 next unless /^#\s*pragma\s+makedep\s+(.*)/;
312 foreach my $flag (split /\s+/, $1)
314 last if $flag eq "depend";
315 $flags{$flag} = 1;
318 close FILE;
319 return %flags;
322 sub get_parent_makefile($)
324 my $file = shift;
325 my %make = %{$makefiles{$file}};
326 my $reldir = $make{"PARENTSRC"} || "";
327 return "" unless $reldir;
328 (my $path = $file) =~ s/\/Makefile$/\//;
329 while ($reldir =~ /^\.\.\//)
331 $reldir =~ s/^\.\.\///;
332 $path =~ s/[^\/]+\/$//;
334 return "$path$reldir/Makefile";
337 # preserve shared source files that are listed in the existing makefile
338 sub preserve_shared_source_files($$$)
340 my ($make, $parent, $var) = @_;
341 my %srcs;
343 return unless defined ${$parent}{"=$var"};
344 foreach my $file (@{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
345 foreach my $file (@{${$make}{"=$var"}}) { $srcs{$file} = 0; }
347 foreach my $file (@{${$make}{$var}})
349 next unless defined $srcs{$file} && $srcs{$file} == 1;
350 push @{${$make}{"=$var"}}, $file;
354 # assign source files to their respective makefile
355 sub assign_sources_to_makefiles(@)
357 foreach my $file (@_)
359 next if defined $ignored_source_files{$file};
360 next if $file =~ /Makefile\.in$/;
361 my $dir = dirname( $file );
362 my $subdir = $dir;
364 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
365 $subdir =~ s/^$dir\/?//;
366 next unless $dir;
368 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
370 my $make = $makefiles{"$dir/Makefile"};
371 my $name = substr( $file, length($dir) + 1 );
373 ${$make}{"=flags"}{"clean"} = 1 if $subdir;
375 if ($dir eq "include")
377 next if ($name =~ /\.in$/);
378 if ($name =~ /^wine\// && !$exported_wine_headers{$name})
380 if ($private_idl_headers{$name}) { push @{${$make}{"=PRIVATE_IDL_H_SRCS"}}, $name; }
381 next;
383 if ($name =~ /stdole2\.idl$/) { push @{${$make}{"=IDL_TLB_SRCS"}}, $name; }
384 elsif ($private_idl_headers{$name}) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
385 elsif ($name =~ /\.h$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
386 elsif ($name =~ /\.x$/) { push @{${$make}{"=XTEMPLATE_SRCS"}}, $name; }
387 elsif ($name =~ /\.rh$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
388 elsif ($name =~ /\.inl$/) { push @{${$make}{"=SRCDIR_INCLUDES"}}, $name; }
389 elsif ($name =~ /\.idl$/) { push @{${$make}{"=PUBLIC_IDL_H_SRCS"}}, $name; }
390 else { die "unknown file $name in include dir"; }
392 else
394 if ($name =~ /\.m$/) { push @{${$make}{"=OBJC_SRCS"}}, $name; }
395 elsif ($name =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $name; }
396 elsif ($name =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $name; }
397 elsif ($name =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $name; }
398 elsif ($name =~ /\.sfd$/) { push @{${$make}{"=FONT_SRCS"}}, $name; }
399 elsif ($name =~ /\.c$/)
401 my %flags = get_makedep_flags( $file );
402 if (defined $flags{"implib"})
404 push @{${$make}{"=IMPLIB_SRCS"}}, $name;
405 ${${$make}{"=flags"}}{"staticimplib"} = 1;
407 push @{${$make}{"=C_SRCS"}}, $name;
409 elsif ($name =~ /\.rc$/)
411 my %flags = get_makedep_flags( $file );
412 ${${$make}{"=flags"}}{"po"} = 1 if defined $flags{"po"};
413 push @{${$make}{"=RC_SRCS"}}, $name;
415 elsif ($name =~ /\.mc$/)
417 push @{${$make}{"=MC_SRCS"}}, $name;
418 ${${$make}{"=flags"}}{"mc"} = 1;
420 elsif ($name =~ /\.idl$/)
422 push @{${$make}{"=IDL_SRCS"}}, $name;
423 ${${$make}{"=flags"}}{"clean"} = 1;
425 elsif ($name =~ /\.man\.in$/)
427 push @{${$make}{"=MANPAGES"}}, $name;
428 ${${$make}{"=flags"}}{"manpage"} = 1;
430 elsif ($name =~ /\.in$/)
432 push @{${$make}{"=IN_SRCS"}}, $name;
437 # add extra variables to include source list
438 my $make = $makefiles{"include/Makefile"};
439 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(XTEMPLATE_SRCS)";
440 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(PUBLIC_IDL_H_SRCS)";
441 unshift @{${$make}{"=SRCDIR_INCLUDES"}}, "\$(IDL_TLB_SRCS)";
442 unshift @{${$make}{"=IDL_SRCS"}}, "\$(IDL_H_SRCS) \$(IDL_TLB_SRCS)";
444 # preserve shared source files from the parent makefile
445 foreach my $file (@makefiles)
447 my $make = $makefiles{$file};
448 my $parent = get_parent_makefile( $file );
449 next unless $parent;
450 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
451 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
452 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
453 preserve_shared_source_files( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
454 ${${$make}{"=flags"}}{"clean"} = 1 if defined ${$make}{"=IDL_SRCS"} && @{${$make}{"=IDL_SRCS"}};
458 ################################################################
459 # update the makefile list in configure.ac
461 sub update_makefiles(@)
463 my (@lines);
465 foreach my $file (sort @_)
467 my %make = %{$makefiles{$file}};
468 my $args = "";
469 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
470 my $flag_args = defined $make{"=flags"} ? ",[" . join(",",sort keys %{$make{"=flags"}}) ."]" : "";
471 if (defined($make{"TESTDLL"})) # test
473 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\/Makefile$/;
474 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
475 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
476 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
477 push @lines, "WINE_CONFIG_TEST($dir$flag_args)\n";
479 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
481 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
482 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
483 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
484 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
485 push @lines, "WINE_CONFIG_LIB($name$flag_args)\n";
487 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
489 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
490 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
491 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
492 if ($name =~ /\./)
494 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
496 else
498 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
500 $args .= "," if $is_win16 || defined $make{"=flags"};
501 $args .= "enable_win16" if $is_win16;
502 push @lines, "WINE_CONFIG_PROGRAM($name$args$flag_args)\n";
504 elsif (defined($make{"MODULE"})) # dll
506 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
507 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
508 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
509 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
510 if ($name =~ /\./)
512 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
514 else
516 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
518 my $implib = $make{"IMPORTLIB"} || "";
519 $args .= "," if $is_win16 || defined $make{"=flags"};
520 $args .= "enable_win16" if $is_win16;
521 $args .= $flag_args;
522 $args .= ",[$implib]" if $implib && $implib ne $name;
523 push @lines, "WINE_CONFIG_DLL($name$args)\n";
525 elsif ($file =~ /^tools.*\/Makefile$/)
527 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
528 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
529 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
530 push @lines, "WINE_CONFIG_TOOL($name$flag_args)\n";
532 elsif ($file =~ /\/Makefile$/)
534 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
535 $args = "[$name]";
536 $args .= "," if defined $make{"=flags"};
537 push @lines, "WINE_CONFIG_MAKEFILE($args$flag_args)\n";
541 push @lines, "\nAC_SUBST([LINGUAS],[\"\\\n", join( " \\\n", sort @linguas ), "\"])\n\n";
543 # update the source variables in all the makefiles
545 foreach my $file (sort @_)
547 replace_makefile_variable( $file, "LEX_SRCS" );
548 replace_makefile_variable( $file, "BISON_SRCS" );
549 replace_makefile_variable( $file, "MC_SRCS" );
550 replace_makefile_variable( $file, "SVG_SRCS" );
551 replace_makefile_variable( $file, "FONT_SRCS" );
552 replace_makefile_variable( $file, "C_SRCS" );
553 replace_makefile_variable( $file, "OBJC_SRCS" );
554 replace_makefile_variable( $file, "RC_SRCS" );
555 replace_makefile_variable( $file, "IDL_SRCS" );
556 replace_makefile_variable( $file, "XTEMPLATE_SRCS" );
557 replace_makefile_variable( $file, "IN_SRCS" );
558 replace_makefile_variable( $file, "IMPLIB_SRCS" );
559 replace_makefile_variable( $file, "MANPAGES" );
560 next unless $file eq "include/Makefile";
561 replace_makefile_variable( $file, "PRIVATE_IDL_H_SRCS" );
562 replace_makefile_variable( $file, "PUBLIC_IDL_H_SRCS" );
563 replace_makefile_variable( $file, "IDL_TLB_SRCS" );
564 replace_makefile_variable( $file, "SRCDIR_INCLUDES" );
567 push @lines, "dnl End of auto-generated output commands\n";
568 replace_in_file( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
572 ################################################################
573 # update the LINGUAS file
575 sub update_linguas(@)
577 replace_in_file( "po/LINGUAS", undef, undef, join("\n", sort @_), "\n" );
581 my $git_dir = $ENV{GIT_DIR} || ".git";
582 die "needs to be run from a git checkout" unless -d $git_dir;
584 my @all_files = split /\0/, `git ls-files -c -z`;
585 @linguas = map { (my $ret = $_) =~ s/^po\/(.*)\.po/$1/; $ret; } grep /^po\/.*\.po$/, @all_files;
586 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
588 foreach my $file (sort @makefiles)
590 my %make = parse_makefile( $file );
591 $makefiles{$file} = \%make;
594 assign_sources_to_makefiles( @all_files );
595 update_linguas( @linguas );
596 update_makefiles( @makefiles );