regedit: Fix possible memory leaks.
[wine/hacks.git] / tools / make_makefiles
blobc44bafe48887b349585478914e9f2baa0e005cdf
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 # Make rules files
23 my %makerules =
25 "MAKE_RULES" => "Make.rules",
26 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
27 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
28 "MAKE_TEST_RULES" => "dlls/Maketest.rules",
29 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
32 # Programs that we want to install in the bin directory too
33 my %bin_install =
35 "msiexec" => 1,
36 "notepad" => 1,
37 "progman" => 1,
38 "regedit" => 1,
39 "regsvr32" => 1,
40 "uninstaller" => 1,
41 "wineboot" => 1,
42 "winebrowser" => 1,
43 "winecfg" => 1,
44 "wineconsole" => 1,
45 "winedbg" => 1,
46 "winefile" => 1,
47 "winemine" => 1,
48 "winepath" => 1,
51 # Programs that we don't want to install at all
52 my %dont_install =
54 "cmdlgtst" => 1,
55 "view" => 1,
56 "winetest" => 1,
59 # Special dlls that can be switched on or off by configure
60 my %special_dlls =
62 "glu32" => "GLU32FILES",
63 "opengl32" => "OPENGLFILES",
64 "winex11.drv" => "XFILES",
65 "winequartz.drv" => "QUARTZFILES"
68 # Default patterns for top-level .gitignore
69 my @ignores = (
70 "*.[oa]",
71 "*.ok",
72 "*.res",
73 "*.so",
74 "/autom4te.cache",
75 "/config.cache",
76 "/config.log",
77 "/config.status",
78 "/TAGS",
79 "/tags",
80 "Makefile",
81 "dlldata.c",
82 "dlls/*/*.def",
83 "dlls/*/tests/*crosstest.exe",
84 "dlls/*/tests/testlist.c",
85 "include/config.h",
86 "include/stamp-h"
89 # Source files and their resulting target to ignore
90 my @ignore_srcs = (
91 [ 'BISON_SRCS', '\.y', '.tab.c' ],
92 [ 'BISON_SRCS', '\.y', '.tab.h' ],
93 [ 'LEX_SRCS', '\.l', '.yy.c' ],
94 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
95 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
96 [ 'IDL_H_SRCS', '\.idl', '.h' ],
97 [ 'IDL_C_SRCS', '\.idl', '.h' ],
98 [ 'IDL_I_SRCS', '\.idl', '.h' ],
99 [ 'IDL_P_SRCS', '\.idl', '.h' ],
100 [ 'IDL_S_SRCS', '\.idl', '.h' ],
101 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
102 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
103 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
104 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
107 my %exported_wine_headers = (
108 "wine/debug.h" => 1,
109 "wine/exception.h" => 1,
110 "wine/library.h" => 1,
111 "wine/unicode.h" => 1,
112 "wine/itss.idl" => 1,
113 "wine/svcctl.idl" => 1,
116 my %private_idl_headers = (
117 "axcore.idl" => 1,
118 "axextend.idl" => 1,
119 "dbinit.idl" => 1,
120 "dbprop.idl" => 1,
121 "dbs.idl" => 1,
122 "devenum.idl" => 1,
123 "dyngraph.idl" => 1,
124 "vmrender.idl" => 1,
127 my (@makefiles, %makefiles);
129 # update a file if changed
130 sub update_file($)
132 my $file = shift;
133 my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
134 if (!$ret)
136 unlink "$file.new";
138 else
140 rename "$file.new", "$file";
141 print "$file updated\n";
142 if ($file eq "configure.ac")
144 system "autoconf";
145 print "configure updated\n";
148 return $ret;
151 # replace some lines in a file between two markers
152 sub replace_in_file($$$@)
154 my $file = shift;
155 my $start = shift;
156 my $end = shift;
158 open NEW_FILE, ">$file.new" or die "cannot create $file.new";
160 if (defined($start))
162 open OLD_FILE, "$file" or die "cannot open $file";
163 while (<OLD_FILE>)
165 last if /$start/;
166 print NEW_FILE $_;
170 print NEW_FILE @_;
172 if (defined($end))
174 my $skip=1;
175 while (<OLD_FILE>)
177 print NEW_FILE $_ unless $skip;
178 $skip = 0 if /$end/;
182 close OLD_FILE if defined($start);
183 close NEW_FILE;
184 return update_file($file);
187 # parse the specified makefile to identify the rules file
188 sub parse_makefile($)
190 my $file = shift;
191 my %make;
193 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
195 open MAKE, "$file.in" or die "cannot open $file.in\n";
197 while (<MAKE>)
199 chomp;
200 while (/\\$/) { chop; $_ .= <MAKE>; chomp; } # merge continued lines
202 if (/^\@(MAKE.*RULES)\@/)
204 my $var = $1;
205 $make{"=rules"} = $makerules{$var};
206 next;
208 if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
210 $make{$1} = $2;
211 next;
213 if (/^(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|MC_SRCS|RC_SRCS|RC_SRCS16|RC_BINARIES|SPEC_SRCS16|EXTRA_OBJS16|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
215 my @list = split(/\s+/, $2);
216 $make{$1} = \@list;
217 next;
219 if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
221 $make{"=skip"} = 1;
222 next;
225 return %make;
229 ################################################################
230 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
232 sub update_winetest(@)
234 my (@tests, @lines);
236 foreach my $file (@_)
238 if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
240 push @lines, "TESTBINS =";
241 push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
242 push @lines, "\n\n";
244 foreach my $test (sort @tests)
246 push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
247 push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
249 push @lines, "\n# Special rules\n";
251 replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
253 replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
254 map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
256 # return a list of test exe files for .gitignore
257 return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
261 ################################################################
262 # update the makefile list in configure.ac
264 sub update_makefiles(@)
266 my (@lines);
268 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
270 my $file = $makerules{$var};
271 my %make = %{$makefiles{$file}};
272 my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
273 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
275 push @lines, "\n";
277 foreach my $file (sort @_)
279 my %make = %{$makefiles{$file}};
280 my $rules = $make{"=rules"};
281 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules])\n";
284 push @lines, "\nAC_OUTPUT\n";
285 replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^AC_OUTPUT$', @lines);
289 ################################################################
290 # process ignore targets for generic source files
292 sub update_ignores(@)
294 my @ignores;
296 foreach my $file (sort @_)
298 my %makefile = %{$makefiles{$file}};
299 my @list;
301 foreach my $src (@ignore_srcs)
303 my @pattern = @{$src};
304 next unless defined $makefile{$pattern[0]};
305 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
307 push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
308 foreach my $f (@list)
310 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
313 return @ignores;
316 ################################################################
317 # update dlls/Makefile.in
319 sub update_dlls(@)
321 my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
322 my $text = "";
323 my @ignores = ();
325 foreach my $make (@_)
327 my %makefile = %{$makefiles{$make}};
328 next if defined $makefile{"=skip"};
330 if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
332 $testdirs{$1} = "$1/tests";
333 (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
334 next;
337 next unless defined $makefile{"MODULE"};
338 my $module = $makefile{"MODULE"};
339 (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
341 if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
343 $staticlib_dirs{$module} = $dir;
344 die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
346 else
348 die "invalid module $module" unless $module =~ /\./;
349 (my $mod = $module) =~ s/\.dll$//;
350 die "invalid directory $dir for module $module\n" unless $mod eq $dir;
351 $directories{$module} = $dir;
354 if (defined $makefile{"IMPORTLIB"})
356 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
358 $importlibs{$module} = $1;
360 else
362 die "invalid importlib name $makefile{IMPORTLIB} in $make";
366 $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
368 if (defined $makefile{"SPEC_SRCS16"})
370 my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
371 $altnames{$module} = \@list;
373 if (defined $makefile{"EXTRA_OBJS16"})
375 foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
377 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
382 # output special dlls configure definitions
384 $text .= "# special configure-dependent targets\n\n";
385 my %specials = ();
386 foreach my $mod (sort keys %special_dlls)
388 $specials{$special_dlls{$mod}} .= " " . $mod;
390 foreach my $i (sort keys %specials)
392 $text .= $i . " =" . $specials{$i} . "\n";
394 $text .= "EXTRADIRS =";
395 foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
396 $text .= "\n\n";
398 # output the subdirs list
400 $text .= "# Subdir list\n\n";
401 $text .= "BASEDIRS =";
402 foreach my $dir (sort values %directories)
404 next if defined($special_dlls{$dir}); # skip special dlls
405 $text .= " \\\n\t" . $dir;
408 $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
409 $text .= join " \\\n\t", sort values %staticlib_dirs;
411 $text .= "\n\nTESTSUBDIRS = \\\n\t";
412 $text .= join " \\\n\t", sort values %testdirs;
414 $text .= "\n\nSUBDIRS = \\\n\t";
415 $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
417 $text .= "\n\nBUILDSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
418 $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
419 $text .= "DOCSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS)\n";
421 # output the list of 16-bit files
423 my @targets16 = ();
424 foreach my $mod (sort keys %directories)
426 next unless defined $altnames{$mod};
427 foreach my $i (sort @{$altnames{$mod}})
429 push @targets16, $i . "16";
432 $text .= "\n# 16-bit dlls\n\n";
433 $text .= "WIN16_FILES = \\\n";
434 $text .= "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
435 $text .= "\@MAKE_RULES\@\n\n";
437 # output the all: target
439 $text .= "# Main target\n\n";
440 $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
442 # output the lib name -> directory rules
444 $text .= "# Placeholders for 16-bit libraries\n\n";
445 foreach my $mod (sort keys %directories)
447 next unless defined $altnames{$mod};
448 $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
449 $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
452 # output the import libraries rules
454 $text .= "# Import libraries\n\n";
455 $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
457 my @lib_symlinks = ();
458 foreach my $mod (sort keys %importlibs)
460 my $dir = $directories{$mod};
461 my $lib = $importlibs{$mod};
462 if ($lib ne $dir) { push @lib_symlinks, $mod; }
464 $text .= "IMPORT_SYMLINKS =";
465 foreach my $mod (sort @lib_symlinks)
467 $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
470 $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
471 foreach my $mod (sort keys %staticlib_dirs)
473 $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
475 foreach my $mod (sort keys %importlibs)
477 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
478 next unless defined $static_implibs{$mod};
479 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
481 $text .= "\n\nCROSS_IMPLIBS =";
482 foreach my $mod (sort @lib_symlinks)
484 $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
486 foreach my $mod (sort keys %importlibs)
488 next if defined $static_implibs{$mod};
489 $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
491 $text .= "\n\n";
492 $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
493 $text .= "implib: \$(IMPORT_LIBS)\n\n";
494 $text .= ".PHONY: implib\n\n";
496 foreach my $mod (sort keys %importlibs)
498 my $dir = $directories{$mod};
499 my $lib = $importlibs{$mod};
500 my $spec = $mod;
501 $spec =~ s/\.dll$//;
502 if (defined($static_implibs{$mod}))
504 $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
505 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
506 $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
507 $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
509 else
511 $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
512 $dir, $lib, $dir, $lib, $dir, $spec;
513 $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
516 foreach my $mod (sort @lib_symlinks)
518 my $dir = $directories{$mod};
519 my $lib = "lib" . $importlibs{$mod};
520 $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
521 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
522 $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
523 $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
526 $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
527 $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
529 # output the inter-dll dependencies and rules
531 $text .= "# Map library name to the corresponding directory\n\n";
533 foreach my $mod (sort keys %staticlib_dirs)
535 $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
537 $text .= "\n# Misc rules\n";
539 replace_in_file( "dlls/Makefile.in",
540 '^# special configure-dependent targets',
541 '^# Misc rules',
542 $text );
544 # .gitignore file
546 foreach my $mod (sort @lib_symlinks)
548 push @ignores, "dlls/lib$importlibs{$mod}.def";
550 foreach my $mod (sort keys %directories)
552 next unless defined $altnames{$mod};
553 push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
556 return @ignores;
560 ################################################################
561 # update programs/Makefile.in
563 sub update_progs(@)
565 my (@subdirs, @install_subdirs, @install_progs);
567 my @ignores = ();
569 foreach my $make (@_)
571 my %makefile = %{$makefiles{$make}};
572 my $module = $makefile{"MODULE"};
573 (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
574 die "Invalid module $module in $make" unless "$dir.exe" eq $module;
575 next if defined $makefile{"=skip"};
576 push @subdirs, $dir;
577 push @ignores, "programs/$dir/$dir";
578 push @install_subdirs, $dir unless $dont_install{$dir};
579 push @install_progs, $dir if $bin_install{$dir};
582 replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
583 "SUBDIRS = \\\n\t",
584 join( " \\\n\t", @subdirs ),
585 "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
586 join( " \\\n\t", @install_subdirs ),
587 "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
588 join( " \\\n\t", @install_progs ),
589 "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
591 return @ignores;
595 ################################################################
596 # update include/Makefile.in
598 sub update_includes()
600 return unless -d ".git";
601 my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
602 my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
603 foreach my $incl (@includes)
605 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
606 next if ($incl =~ /^wine\// && !$exported_wine_headers{$incl});
607 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
608 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
609 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
610 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
611 elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
613 replace_in_file( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
614 "IDL_H_SRCS = \\\n\t",
615 join( " \\\n\t", sort @idl_srcs ),
616 "\n\nIDL_TLB_SRCS = \\\n\t",
617 join( " \\\n\t", sort @tlb_srcs ),
618 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
619 join( " \\\n\t", sort @h_srcs ),
620 "\n\nEXTRASUBDIRS = ",
621 join( " ", sort keys %subdirs ),
622 "\n\nINSTALLDIRS = \\\n" );
626 ################################################################
627 # update the main .gitignore
629 sub update_gitignore(@)
631 my @ignores = values %makerules;
633 foreach my $make (@makefiles)
635 my %makefile = %{$makefiles{$make}};
636 my $dir = $makefile{"=dir"};
637 if (defined $makefile{"MANPAGES"})
639 push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
641 if (defined $makefile{"PROGRAMS"})
643 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
647 # prepend a slash to paths that don't have one
648 @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
650 # get rid of duplicates
651 my %ignores = ();
652 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
654 replace_in_file( ".gitignore", undef, undef,
655 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
656 join("\n", sort keys %ignores), "\n" );
660 if (-d ".git")
662 @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
664 else
666 @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
669 update_includes();
671 foreach my $file (sort values %makerules, @makefiles)
673 my %make = parse_makefile( $file );
674 $makefiles{$file} = \%make;
677 update_makefiles( @makefiles );
678 push @ignores, update_ignores( @makefiles );
679 push @ignores, update_winetest( @makefiles );
680 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
681 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
682 update_gitignore( @ignores );