oledlg: Add the Serbian (Latin and Cyrillic) translation.
[wine/multimedia.git] / tools / make_makefiles
blob4673fea2f705909d0268adc3d8980a2866cd7617
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 "*.ok",
80 "*.res",
81 "*.so",
82 "/autom4te.cache",
83 "/config.cache",
84 "/config.log",
85 "/config.status",
86 "/configure.lineno",
87 "/TAGS",
88 "/tags",
89 "/wine",
90 "Makefile",
91 "dlldata.c",
92 "dlls/*/*.def",
93 "*/*/tests/*crosstest.exe",
94 "*/*/tests/testlist.c",
95 "include/config.h",
96 "include/stamp-h",
97 "programs/winetest/*_test.exe",
98 "programs/winetest/*_test.rc",
99 "programs/winetest/build.nfo",
100 "programs/winetest/build.rc",
101 "tools/makedep",
104 # Source files and their resulting target to ignore
105 my @ignore_srcs = (
106 [ 'BISON_SRCS', '\.y', '.tab.c' ],
107 [ 'BISON_SRCS', '\.y', '.tab.h' ],
108 [ 'LEX_SRCS', '\.l', '.yy.c' ],
109 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
110 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
111 [ 'IDL_H_SRCS', '\.idl', '.h' ],
112 [ 'IDL_C_SRCS', '\.idl', '.h' ],
113 [ 'IDL_I_SRCS', '\.idl', '.h' ],
114 [ 'IDL_P_SRCS', '\.idl', '.h' ],
115 [ 'IDL_S_SRCS', '\.idl', '.h' ],
116 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
117 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
118 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
119 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
122 my %exported_wine_headers = (
123 "wine/debug.h" => 1,
124 "wine/exception.h" => 1,
125 "wine/library.h" => 1,
126 "wine/unicode.h" => 1,
127 "wine/itss.idl" => 1,
128 "wine/svcctl.idl" => 1,
131 my %private_idl_headers = (
132 "access.idl" => 1,
133 "asynot.idl" => 1,
134 "asysta.idl" => 1,
135 "axcore.idl" => 1,
136 "axextend.idl" => 1,
137 "binres.idl" => 1,
138 "cmdbas.idl" => 1,
139 "cmdtxt.idl" => 1,
140 "crtrow.idl" => 1,
141 "dbccmd.idl" => 1,
142 "dbcses.idl" => 1,
143 "dbdsad.idl" => 1,
144 "dbinit.idl" => 1,
145 "dbprop.idl" => 1,
146 "dbs.idl" => 1,
147 "devenum.idl" => 1,
148 "dyngraph.idl" => 1,
149 "opnrst.idl" => 1,
150 "row.idl" => 1,
151 "rowchg.idl" => 1,
152 "rstbas.idl" => 1,
153 "rstinf.idl" => 1,
154 "rstloc.idl" => 1,
155 "sesprp.idl" => 1,
156 "vmrender.idl" => 1,
157 "wine/wined3d.idl" => 1,
158 "wine/winedxgi.idl" => 1,
161 my %ignored_source_files = (
162 "dlls/wineps.drv/afm2c.c" => 1,
163 "dlls/wineps.drv/mkagl.c" => 1,
164 "programs/winetest/dist.rc" => 1,
167 my (@all_files, @makefiles, %makefiles);
169 sub dirname($)
171 my $ret = shift;
172 return "" unless $ret =~ /\//;
173 $ret =~ s!/[^/]*$!!;
174 return $ret;
177 # update a file if changed
178 sub update_file($)
180 my $file = shift;
181 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
182 if (!$ret)
184 unlink "$file.new";
186 else
188 rename "$file.new", "$file";
189 print "$file updated\n";
190 if ($file eq "configure.ac")
192 system "autoconf";
193 print "configure updated\n";
196 return $ret;
199 # replace some lines in a file between two markers
200 sub replace_in_file($$$@)
202 my $file = shift;
203 my $start = shift;
204 my $end = shift;
206 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
208 if (defined($start))
210 open OLD_FILE, "$file" or die "cannot open $file";
211 while (<OLD_FILE>)
213 last if /$start/;
214 print NEW_FILE $_;
218 print NEW_FILE @_;
220 if (defined($end))
222 my $skip=1;
223 while (<OLD_FILE>)
225 print NEW_FILE $_ unless $skip;
226 $skip = 0 if /$end/;
230 close OLD_FILE if defined($start);
231 close NEW_FILE;
232 return update_file($file);
235 # replace a variable in a makefile
236 sub replace_makefile_variable($$)
238 my ($file, $var) = @_;
239 my $make = $makefiles{$file};
241 return unless defined ${$make}{"=$var"};
243 my @values = @{${$make}{"=$var"}};
244 ${$make}{$var} = \@values;
246 open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
248 open OLD_FILE, "$file.in" or die "cannot open $file.in";
249 while (<OLD_FILE>)
251 if (/^\s*($var\s+)=/)
253 # try to preserve formatting
254 my $prefix = $1;
255 my $multiline = /\\$/ || (@values > 1);
256 while (/\\$/)
258 $_ = <OLD_FILE>;
259 last unless $_;
261 if ($multiline)
263 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
265 else
267 print NEW_FILE "$prefix= @values\n";
269 next;
271 print NEW_FILE $_;
273 close OLD_FILE;
274 close NEW_FILE;
275 return update_file("$file.in");
278 # parse the specified makefile to identify the rules file
279 sub parse_makefile($)
281 my $file = shift;
282 my %make;
284 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
286 open MAKE, "$file.in" or die "cannot open $file.in\n";
288 while (<MAKE>)
290 chomp;
291 next if (/^\s*#/);
292 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
293 next if (/^\s*$/);
295 if (/^\@(MAKE.*RULES)\@/)
297 my $var = $1;
298 $make{"=rules"} = $makerules{$var};
299 next;
301 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
303 $make{$1} = $2;
304 next;
306 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
308 my @list = split(/\s+/, $2);
309 $make{$1} = \@list;
310 next;
312 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
314 die "Variable $1 in $file.in is obsolete";
317 return %make;
320 # assign source files to their respective makefile
321 sub assign_sources_to_makefiles()
323 foreach my $file (@all_files)
325 next if defined $ignored_source_files{$file};
326 my $dir = dirname( $file );
328 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
329 next unless $dir;
331 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
333 my $make = $makefiles{"$dir/Makefile"};
334 my $basename = substr( $file, length($dir) + 1 );
336 if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
337 elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
338 elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
339 elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
340 elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
341 elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
345 ################################################################
346 # update the makefile list in configure.ac
348 sub update_makefiles(@)
350 my (@lines);
352 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
354 my $file = $makerules{$var};
355 my %make = %{$makefiles{$file}};
356 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
357 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
359 push @lines, "\n";
361 foreach my $file (sort @_)
363 my %make = %{$makefiles{$file}};
364 my $rules = $make{"=rules"};
365 my $args = "";
366 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
367 if ($rules eq $makerules{"MAKE_DLL_RULES"})
369 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
370 if ($name =~ /\./)
372 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
374 else
376 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
378 my $implib = $make{"IMPORTLIB"} || "";
379 my $implib_srcs = defined($make{"IMPLIB_SRCS"}) && join( " ", @{$make{"IMPLIB_SRCS"}} );
380 $args .= "," if $implib || $is_win16;
381 $args .= "enable_win16" if $is_win16;
382 $args .= ",[$implib]" if $implib;
383 $args .= ",[$implib_srcs]" if $implib_srcs;
384 push @lines, "WINE_CONFIG_DLL($name$args)\n";
386 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
388 (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
389 if ($name =~ /\./)
391 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
393 else
395 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
397 my $install = $dont_install{$name} ? "" : "install";
398 $install .= "bin" if $bin_install{$name};
399 $args .= "," if $is_win16 || $install;
400 $args .= "$install" if $install;
401 $args .= ",enable_win16" if $is_win16;
402 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
404 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
406 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
407 push @lines, "WINE_CONFIG_TEST($dir)\n";
409 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
411 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile/$1/;
412 push @lines, "WINE_CONFIG_LIB($name)\n";
414 elsif ($file =~ /^tools.*\/Makefile$/)
416 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
417 push @lines, "WINE_CONFIG_TOOL($name)\n";
419 elsif ($file =~ /\/Makefile$/)
421 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
422 push @lines, "WINE_CONFIG_MAKEFILE([$name])\n";
426 # update the source variables in all the makefiles
428 foreach my $file (sort @_)
430 my %make = %{$makefiles{$file}};
432 replace_makefile_variable( $file, "LEX_SRCS" );
433 replace_makefile_variable( $file, "BISON_SRCS" );
434 replace_makefile_variable( $file, "MC_SRCS" );
435 replace_makefile_variable( $file, "SVG_SRCS" );
436 replace_makefile_variable( $file, "C_SRCS" );
437 replace_makefile_variable( $file, "RC_SRCS" );
440 push @lines, "dnl End of auto-generated output commands\n";
441 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
445 ################################################################
446 # process ignore targets for generic source files
448 sub update_ignores(@)
450 my @ignores;
452 foreach my $file (sort @_)
454 my %makefile = %{$makefiles{$file}};
455 my @list;
457 foreach my $src (@ignore_srcs)
459 my @pattern = @{$src};
460 next unless defined $makefile{$pattern[0]};
461 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
463 foreach my $f (@list)
465 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
468 if (defined $makefile{"IMPORTLIB"})
470 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
472 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
474 else
476 die "invalid importlib name $makefile{IMPORTLIB} in $file";
480 return @ignores;
484 ################################################################
485 # update include/Makefile.in
487 sub update_includes()
489 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
490 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
491 foreach my $incl (@includes)
493 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
494 next if ($incl =~ /\.in$/);
495 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
497 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
498 next;
500 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
501 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
502 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
503 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
504 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
505 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
506 else { die "unknown file $incl in include dir"; }
508 replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
509 "PRIVATE_IDL_H_SRCS = \\\n\t",
510 join( " \\\n\t", sort @private_idl_srcs ),
511 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
512 join( " \\\n\t", sort @public_idl_srcs ),
513 "\n\nIDL_TLB_SRCS = \\\n\t",
514 join( " \\\n\t", sort @tlb_srcs ),
515 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
516 join( " \\\n\t", sort @h_srcs ),
517 "\n\nEXTRASUBDIRS = ",
518 join( " ", sort keys %subdirs ),
519 "\n\nINSTALLDIRS = \\\n" );
520 return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
524 ################################################################
525 # update the main .gitignore
527 sub update_gitignore(@)
529 my @ignores = values %makerules;
531 foreach my $make (@makefiles)
533 my %makefile = %{$makefiles{$make}};
534 my $dir = $makefile{"=dir"};
535 if (defined $makefile{"MANPAGES"})
537 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
539 if (defined $makefile{"PROGRAMS"})
541 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
545 # prepend a slash to paths that don't have one
546 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
548 # get rid of duplicates
549 my %ignores = ();
550 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
552 replace_in_file( ".gitignore", undef, undef,
553 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
554 join("\n", sort keys %ignores), "\n" );
558 die "needs to be run from a git checkout" unless -d ".git";
560 @all_files = split /\0/, `git ls-files -c -z`;
561 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
563 foreach my $file (sort values %makerules, @makefiles)
565 my %make = parse_makefile( $file );
566 $makefiles{$file} = \%make;
569 assign_sources_to_makefiles();
570 update_makefiles( @makefiles );
571 push @ignores, update_includes();
572 push @ignores, update_ignores( @makefiles );
573 update_gitignore( @ignores );