browseui: Update Korean resource.
[wine/multimedia.git] / tools / make_makefiles
blob29cb8d64720c68cd7215f26629b95f77bb335136
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 # Make rules files
25 my %makerules =
27 "MAKE_RULES" => "Make.rules",
28 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30 "MAKE_TEST_RULES" => "Maketest.rules",
31 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
34 # Programs that we want to install in the bin directory too
35 my %bin_install =
37 "msiexec" => 1,
38 "notepad" => 1,
39 "regedit" => 1,
40 "regsvr32" => 1,
41 "wineboot" => 1,
42 "winecfg" => 1,
43 "wineconsole" => 1,
44 "winedbg" => 1,
45 "winefile" => 1,
46 "winemine" => 1,
47 "winepath" => 1,
50 # Programs that we don't want to install at all
51 my %dont_install =
53 "cmdlgtst" => 1,
54 "view" => 1,
55 "winetest" => 1,
58 # Dlls and programs that are 16-bit specific
59 my %modules16 =
61 "ifsmgr.vxd" => 1,
62 "mmdevldr.vxd" => 1,
63 "monodebg.vxd" => 1,
64 "vdhcp.vxd" => 1,
65 "vmm.vxd" => 1,
66 "vnbt.vxd" => 1,
67 "vnetbios.vxd" => 1,
68 "vtdapi.vxd" => 1,
69 "vwin32.vxd" => 1,
70 "w32skrnl.dll" => 1,
71 "winevdm.exe" => 1,
72 "wow32.dll" => 1,
75 # Default patterns for top-level .gitignore
76 my @ignores = (
77 "*.[oa]",
78 "*.fake",
79 "*.man",
80 "*.ok",
81 "*.res",
82 "*.so",
83 "/autom4te.cache",
84 "/config.cache",
85 "/config.log",
86 "/config.status",
87 "/configure.lineno",
88 "/TAGS",
89 "/tags",
90 "/wine",
91 "Makefile",
92 "dlldata.c",
93 "dlls/*/*.def",
94 "dlls/shell32/AUTHORS",
95 "*/*/tests/*crosstest.exe",
96 "*/*/tests/testlist.c",
97 "include/config.h",
98 "include/stamp-h",
99 "programs/winetest/*_test.exe",
100 "programs/winetest/*_test.rc",
101 "programs/winetest/build.nfo",
102 "programs/winetest/build.rc",
103 "tools/makedep",
106 # Source files and their resulting target to ignore
107 my @ignore_srcs = (
108 [ 'BISON_SRCS', '\.y', '.tab.c' ],
109 [ 'BISON_SRCS', '\.y', '.tab.h' ],
110 [ 'LEX_SRCS', '\.l', '.yy.c' ],
111 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
112 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
113 [ 'IDL_H_SRCS', '\.idl', '.h' ],
114 [ 'IDL_C_SRCS', '\.idl', '.h' ],
115 [ 'IDL_I_SRCS', '\.idl', '.h' ],
116 [ 'IDL_P_SRCS', '\.idl', '.h' ],
117 [ 'IDL_S_SRCS', '\.idl', '.h' ],
118 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
119 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
120 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
121 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
124 my %exported_wine_headers = (
125 "wine/debug.h" => 1,
126 "wine/exception.h" => 1,
127 "wine/library.h" => 1,
128 "wine/unicode.h" => 1,
129 "wine/itss.idl" => 1,
130 "wine/svcctl.idl" => 1,
133 my %private_idl_headers = (
134 "access.idl" => 1,
135 "asynot.idl" => 1,
136 "asysta.idl" => 1,
137 "axcore.idl" => 1,
138 "axextend.idl" => 1,
139 "binres.idl" => 1,
140 "cmdbas.idl" => 1,
141 "cmdtxt.idl" => 1,
142 "crtrow.idl" => 1,
143 "dbccmd.idl" => 1,
144 "dbcses.idl" => 1,
145 "dbdsad.idl" => 1,
146 "dbinit.idl" => 1,
147 "dbprop.idl" => 1,
148 "dbs.idl" => 1,
149 "devenum.idl" => 1,
150 "dyngraph.idl" => 1,
151 "opnrst.idl" => 1,
152 "row.idl" => 1,
153 "rowchg.idl" => 1,
154 "rstbas.idl" => 1,
155 "rstinf.idl" => 1,
156 "rstloc.idl" => 1,
157 "sesprp.idl" => 1,
158 "vmrender.idl" => 1,
159 "wine/wined3d.idl" => 1,
160 "wine/winedxgi.idl" => 1,
163 my %ignored_source_files = (
164 "dlls/wineps.drv/afm2c.c" => 1,
165 "dlls/wineps.drv/mkagl.c" => 1,
166 "programs/winetest/dist.rc" => 1,
169 my (@all_files, @makefiles, %makefiles);
171 sub dirname($)
173 my $ret = shift;
174 return "" unless $ret =~ /\//;
175 $ret =~ s!/[^/]*$!!;
176 return $ret;
179 # update a file if changed
180 sub update_file($)
182 my $file = shift;
183 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
184 if (!$ret)
186 unlink "$file.new";
188 else
190 rename "$file.new", "$file";
191 print "$file updated\n";
192 if ($file eq "configure.ac")
194 system "autoconf";
195 print "configure updated\n";
198 return $ret;
201 # replace some lines in a file between two markers
202 sub replace_in_file($$$@)
204 my $file = shift;
205 my $start = shift;
206 my $end = shift;
208 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
210 if (defined($start))
212 open OLD_FILE, "$file" or die "cannot open $file";
213 while (<OLD_FILE>)
215 last if /$start/;
216 print NEW_FILE $_;
220 print NEW_FILE @_;
222 if (defined($end))
224 my $skip=1;
225 while (<OLD_FILE>)
227 print NEW_FILE $_ unless $skip;
228 $skip = 0 if /$end/;
232 close OLD_FILE if defined($start);
233 close NEW_FILE;
234 return update_file($file);
237 # replace a variable in a makefile
238 sub replace_makefile_variable($$)
240 my ($file, $var) = @_;
241 my $make = $makefiles{$file};
243 return unless defined ${$make}{"=$var"};
245 my @values = @{${$make}{"=$var"}};
246 ${$make}{$var} = \@values;
248 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
250 open OLD_FILE, "$file.in" or die "cannot open $file.in";
251 while (<OLD_FILE>)
253 if (/^\s*($var\s+)=/)
255 # try to preserve formatting
256 my $prefix = $1;
257 my $multiline = /\\$/ || (@values > 1);
258 while (/\\$/)
260 $_ = <OLD_FILE>;
261 last unless $_;
263 if ($multiline)
265 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
267 else
269 print NEW_FILE "$prefix= @values\n";
271 next;
273 print NEW_FILE $_;
275 close OLD_FILE;
276 close NEW_FILE;
277 return update_file("$file.in");
280 # parse the specified makefile to identify the rules file
281 sub parse_makefile($)
283 my $file = shift;
284 my %make;
286 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
288 open MAKE, "$file.in" or die "cannot open $file.in\n";
290 while (<MAKE>)
292 chomp;
293 next if (/^\s*#/);
294 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
295 next if (/^\s*$/);
297 if (/^\@(MAKE.*RULES)\@/)
299 my $var = $1;
300 $make{"=rules"} = $makerules{$var};
301 next;
303 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
305 $make{$1} = $2;
306 next;
308 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPRS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|PROGRAMS)\s*=\s*(.*)/)
310 my @list = split(/\s+/, $2);
311 $make{$1} = \@list;
312 next;
314 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
316 die "Variable $1 in $file.in is obsolete";
319 return %make;
322 # assign source files to their respective makefile
323 sub assign_sources_to_makefiles()
325 foreach my $file (@all_files)
327 next if defined $ignored_source_files{$file};
328 my $dir = dirname( $file );
330 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
331 next unless $dir;
333 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
335 my $make = $makefiles{"$dir/Makefile"};
336 my $basename = substr( $file, length($dir) + 1 );
338 if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
339 elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
340 elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
341 elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
342 elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
343 elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
347 ################################################################
348 # update the makefile list in configure.ac
350 sub update_makefiles(@)
352 my (@lines);
354 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
356 my $file = $makerules{$var};
357 my %make = %{$makefiles{$file}};
358 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
359 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
361 push @lines, "\n";
363 foreach my $file (sort @_)
365 my %make = %{$makefiles{$file}};
366 my $rules = $make{"=rules"};
367 my $args = "";
368 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
369 if ($rules eq $makerules{"MAKE_DLL_RULES"})
371 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
372 if ($name =~ /\./)
374 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
376 else
378 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
380 my $implib = $make{"IMPORTLIB"} || "";
381 my $implib_srcs = defined($make{"IMPLIB_SRCS"}) && join( " ", @{$make{"IMPLIB_SRCS"}} );
382 $args .= "," if $implib || $is_win16;
383 $args .= "enable_win16" if $is_win16;
384 $args .= ",[$implib]" if $implib;
385 $args .= ",[$implib_srcs]" if $implib_srcs;
386 push @lines, "WINE_CONFIG_DLL($name$args)\n";
388 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
390 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
391 if ($name =~ /\./)
393 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
395 else
397 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
399 my $install = $dont_install{$name} ? "" : "install";
400 $install .= "bin" if $bin_install{$name};
401 $args .= "," if $is_win16 || $install;
402 $args .= "$install" if $install;
403 $args .= ",enable_win16" if $is_win16;
404 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
406 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
408 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
409 push @lines, "WINE_CONFIG_TEST($dir)\n";
411 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
413 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
414 push @lines, "WINE_CONFIG_LIB($name)\n";
416 elsif ($file =~ /^tools.*\/Makefile$/)
418 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
419 push @lines, "WINE_CONFIG_TOOL($name)\n";
421 elsif ($file =~ /\/Makefile$/)
423 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
424 push @lines, "WINE_CONFIG_MAKEFILE([$name])\n";
428 # update the source variables in all the makefiles
430 foreach my $file (sort @_)
432 my %make = %{$makefiles{$file}};
434 replace_makefile_variable( $file, "LEX_SRCS" );
435 replace_makefile_variable( $file, "BISON_SRCS" );
436 replace_makefile_variable( $file, "MC_SRCS" );
437 replace_makefile_variable( $file, "SVG_SRCS" );
438 replace_makefile_variable( $file, "C_SRCS" );
439 replace_makefile_variable( $file, "RC_SRCS" );
442 push @lines, "dnl End of auto-generated output commands\n";
443 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
447 ################################################################
448 # process ignore targets for generic source files
450 sub update_ignores(@)
452 my @ignores;
454 foreach my $file (sort @_)
456 my %makefile = %{$makefiles{$file}};
457 my @list;
459 foreach my $src (@ignore_srcs)
461 my @pattern = @{$src};
462 next unless defined $makefile{$pattern[0]};
463 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
465 foreach my $f (@list)
467 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
470 if (defined $makefile{"IMPORTLIB"})
472 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
474 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
476 else
478 die "invalid importlib name $makefile{IMPORTLIB} in $file";
482 return @ignores;
486 ################################################################
487 # update include/Makefile.in
489 sub update_includes()
491 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
492 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
493 foreach my $incl (@includes)
495 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
496 next if ($incl =~ /\.in$/);
497 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
499 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
500 next;
502 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
503 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
505 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
506 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
507 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
508 else { die "unknown file $incl in include dir"; }
510 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
511 "PRIVATE_IDL_H_SRCS = \\\n\t",
512 join( " \\\n\t", sort @private_idl_srcs ),
513 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
514 join( " \\\n\t", sort @public_idl_srcs ),
515 "\n\nIDL_TLB_SRCS = \\\n\t",
516 join( " \\\n\t", sort @tlb_srcs ),
517 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
518 join( " \\\n\t", sort @h_srcs ),
519 "\n\nEXTRASUBDIRS = ",
520 join( " ", sort keys %subdirs ),
521 "\n\nINSTALLDIRS = \\\n" );
522 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
526 ################################################################
527 # update the main .gitignore
529 sub update_gitignore(@)
531 my @ignores = values %makerules;
533 foreach my $make (@makefiles)
535 my %makefile = %{$makefiles{$make}};
536 my $dir = $makefile{"=dir"};
537 if (defined $makefile{"PROGRAMS"})
539 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
543 # prepend a slash to paths that don't have one
544 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
546 # get rid of duplicates
547 my %ignores = ();
548 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
550 replace_in_file( ".gitignore", undef, undef,
551 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
552 join("\n", sort keys %ignores), "\n" );
556 die "needs to be run from a git checkout" unless -d ".git";
558 @all_files = split /\0/, `git ls-files -c -z`;
559 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
561 foreach my $file (sort values %makerules, @makefiles)
563 my %make = parse_makefile( $file );
564 $makefiles{$file} = \%make;
567 assign_sources_to_makefiles();
568 update_makefiles( @makefiles );
569 push @ignores, update_includes();
570 push @ignores, update_ignores( @makefiles );
571 update_gitignore( @ignores );