gdiplus: Implement GdipGetEmHeight.
[wine] / tools / make_makefiles
1 #!/usr/bin/perl -w
2 #
3 # Build the auto-generated parts of the Wine makefiles.
4 #
5 # Copyright 2006 Alexandre Julliard
6 #
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.
11 #
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.
16 #
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
20 #
21
22 # Make rules files
23 my %makerules =
24 (
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",
30 );
31
32 # Programs that we want to install in the bin directory too
33 my %bin_install =
34 (
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,
49 );
50
51 # Programs that we don't want to install at all
52 my %dont_install =
53 (
54   "cmdlgtst" => 1,
55   "view" => 1,
56   "winetest" => 1,
57 );
58
59 # Special dlls that can be switched on or off by configure
60 my %special_dlls =
61 (
62   "glu32"    => "GLU32FILES",
63   "opengl32" => "OPENGLFILES",
64   "winex11.drv" => "XFILES",
65   "winequartz.drv" => "QUARTZFILES"
66 );
67
68 # Default patterns for top-level .gitignore
69 my @ignores = (
70     "*.[oa]",
71     "*.res",
72     "*.so",
73     "/autom4te.cache",
74     "/config.cache",
75     "/config.log",
76     "/config.status",
77     "/TAGS",
78     "/tags",
79     "Makefile",
80     "dlldata.c",
81     "include/config.h",
82     "include/stamp-h"
83 );
84
85 # Source files and their resulting target to ignore
86 my @ignore_srcs = (
87     [ 'BISON_SRCS',   '\.y',   '.tab.c' ],
88     [ 'BISON_SRCS',   '\.y',   '.tab.h' ],
89     [ 'LEX_SRCS',     '\.l',   '.yy.c' ],
90     [ 'MC_SRCS',      '\.mc',  '.mc.rc' ],
91     [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
92     [ 'IDL_H_SRCS',   '\.idl', '.h' ],
93     [ 'IDL_C_SRCS',   '\.idl', '.h' ],
94     [ 'IDL_I_SRCS',   '\.idl', '.h' ],
95     [ 'IDL_P_SRCS',   '\.idl', '.h' ],
96     [ 'IDL_S_SRCS',   '\.idl', '.h' ],
97     [ 'IDL_C_SRCS',   '\.idl', '_c.c' ],
98     [ 'IDL_I_SRCS',   '\.idl', '_i.c' ],
99     [ 'IDL_P_SRCS',   '\.idl', '_p.c' ],
100     [ 'IDL_S_SRCS',   '\.idl', '_s.c' ],
101 );
102
103 my %private_headers = (
104     "wine/irot.idl" => 1,
105     "wine/list.h" => 1,
106     "wine/mmsystem16.h" => 1,
107     "wine/mscvpdb.h" => 1,
108     "wine/port.h" => 1,
109     "wine/pthread.h" => 1,
110     "wine/rpcfc.h" => 1,
111     "wine/server.h" => 1,
112     "wine/server_protocol.h" => 1,
113     "wine/test.h" => 1,
114     "wine/wgl.h" => 1,
115     "wine/winaspi.h" => 1,
116     "wine/winbase16.h" => 1,
117     "wine/windef16.h" => 1,
118     "wine/wined3d_caps.h" => 1,
119     "wine/wined3d_gl.h" => 1,
120     "wine/wined3d_interface.h" => 1,
121     "wine/wined3d_types.h" => 1,
122     "wine/wingdi16.h" => 1,
123     "wine/winnet16.h" => 1,
124     "wine/winsock16.h" => 1,
125     "wine/winuser16.h" => 1,
126     "wine/wpp.h" => 1
127 );
128
129 my %private_idl_headers = (
130     "axcore.idl" => 1,
131     "axextend.idl" => 1,
132     "dbinit.idl" => 1,
133     "dbprop.idl" => 1,
134     "dbs.idl" => 1,
135     "devenum.idl" => 1,
136     "dyngraph.idl" => 1
137 );
138
139 my (@makefiles, %makefiles);
140
141 # update a file if changed
142 sub update_file($)
143 {
144     my $file = shift;
145     my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
146     if (!$ret)
147     {
148         unlink "$file.new";
149     }
150     else
151     {
152         rename "$file.new", "$file";
153         print "$file updated\n";
154         if ($file eq "configure.ac")
155         {
156             system "autoconf";
157             print "configure updated\n";
158         }
159     }
160     return $ret;
161 }
162
163 # replace some lines in a file between two markers
164 sub replace_in_file($$$@)
165 {
166     my $file = shift;
167     my $start = shift;
168     my $end = shift;
169
170     open NEW_FILE, ">$file.new" or die "cannot create $file.new";
171
172     if (defined($start))
173     {
174         open OLD_FILE, "$file" or die "cannot open $file";
175         while (<OLD_FILE>)
176         {
177             last if /$start/;
178             print NEW_FILE $_;
179         }
180     }
181
182     print NEW_FILE @_;
183
184     if (defined($end))
185     {
186         my $skip=1;
187         while (<OLD_FILE>)
188         {
189             print NEW_FILE $_ unless $skip;
190             $skip = 0 if /$end/;
191         }
192     }
193
194     close OLD_FILE if defined($start);
195     close NEW_FILE;
196     return update_file($file);
197 }
198
199 # parse the specified makefile to identify the rules file
200 sub parse_makefile($)
201 {
202     my $file = shift;
203     my %make;
204
205     ($make{"=dir"} = $file) =~ s/[^\/]+$//;
206
207     open MAKE, "$file.in" or die "cannot open $file.in\n";
208
209     while (<MAKE>)
210     {
211         chomp;
212         while (/\\$/) { chop; $_ .= <MAKE>; chomp; }  # merge continued lines
213
214         if (/^\@(MAKE.*RULES)\@/)
215         {
216             my $var = $1;
217             $make{"=rules"} = $makerules{$var};
218             next;
219         }
220         if (/^(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
221         {
222             $make{$1} = $2;
223             next;
224         }
225         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*(.*)/)
226         {
227             my @list = split(/\s+/, $2);
228             $make{$1} = \@list;
229             next;
230         }
231         if (/^\#\s*MKDLL_SKIP/ || /^\#\s*MKPROG_SKIP/)
232         {
233             $make{"=skip"} = 1;
234             next;
235         }
236     }
237     return %make;
238 }
239
240
241 ################################################################
242 # update the makefile list in configure.ac
243
244 sub update_makerules(@)
245 {
246 }
247
248
249 ################################################################
250 # update the tests list in programs/winetest/Makefile.in and programs/winetest/winetest.rc
251
252 sub update_winetest(@)
253 {
254     my (@tests, @lines);
255
256     foreach my $file (@_)
257     {
258         if ($file =~ /^dlls\/(.*)\/tests\/Makefile/) { push @tests, $1; }
259     }
260     push @lines, "TESTBINS =";
261     push @lines, map { " \\\n\t" . $_ . "_test.exe"; } sort @tests;
262     push @lines, "\n\n";
263
264     foreach my $test (sort @tests)
265     {
266         push @lines, "${test}_test.exe: \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT)\n";
267         push @lines, "\tcp \$(DLLDIR)/$test/tests/${test}_test.exe\$(DLLEXT) \$\@ && \$(STRIP) \$\@\n";
268     }
269     push @lines, "\n# Special rules\n";
270
271     replace_in_file( "programs/winetest/Makefile.in", '^TESTBINS\s*=', '^# Special rules', @lines );
272
273     replace_in_file( "programs/winetest/winetest.rc", ' TESTRES ', undef,
274                      map { $_ . "_test.exe TESTRES \"" . $_ . "_test.exe\"\n"; } sort @tests );
275
276     # return a list of test exe files for .gitignore
277     return map { "programs/winetest/" . $_ . "_test.exe"; } sort @tests;
278 }
279
280
281 ################################################################
282 # update the makefile list in configure.ac and Makefile.in
283
284 sub update_makefiles(@)
285 {
286     my (@targets, @depends, @lines);
287
288     foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
289     {
290         push @lines, "$var=$makerules{$var}\n";
291         push @lines, "AC_SUBST_FILE($var)\n\n";
292     }
293
294     foreach my $var ((sort values %makerules), (sort @_))
295     {
296         push @lines, "AC_CONFIG_FILES([$var])\n";
297     }
298
299     push @lines, "\nAC_OUTPUT\n";
300     replace_in_file( "configure.ac", '^MAKE_RULES', '^AC_OUTPUT$', @lines);
301
302     foreach my $file (sort values %makerules)
303     {
304         push @targets, $file;
305         my %make = %{$makefiles{$file}};
306         if (!defined($make{"=rules"})) { push @depends, "$file: $file.in"; }
307         else { push @depends, "$file: $file.in Make.rules"; }
308     }
309
310     foreach my $file (sort @_)
311     {
312         push @targets, $file unless $file eq "Makefile";
313         my %makefile = %{$makefiles{$file}};
314         my $dep = $makefile{"=rules"};
315         push @depends, "$file: $file.in $dep";
316     }
317
318
319     @lines = ();
320     push @lines, "ALL_MAKEFILES = \\\n\t";
321     push @lines, join (" \\\n\t", @targets ), "\n\n";
322     push @lines, "Makefile \$(ALL_MAKEFILES): config.status\n";
323     push @lines, "\t\@./config.status \$\@\n";
324     push @lines, ".INIT: Makefile\n";
325     push @lines, ".BEGIN: Makefile\n\n";
326     push @lines, "\$(RECURSE_TARGETS) \$(MAKEDEP): \$(ALL_MAKEFILES)\n\n";
327     push @lines, "distclean::\n";
328     push @lines, "\t\$(RM) Makefile \$(ALL_MAKEFILES)\n\n";
329     push @lines, join ("\n", @depends ), "\n";
330
331     replace_in_file( "Makefile.in", '^ALL_MAKEFILES\s*=', undef, @lines );
332 }
333
334
335 ################################################################
336 # process ignore targets for generic source files
337
338 sub update_ignores(@)
339 {
340     my @ignores;
341
342     foreach my $file (sort @_)
343     {
344         my %makefile = %{$makefiles{$file}};
345         my @list;
346
347         foreach my $src (@ignore_srcs)
348         {
349             my @pattern = @{$src};
350             next unless defined $makefile{$pattern[0]};
351             push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
352         }
353         push @list, @{$makefile{"RC_BINARIES"}} if defined $makefile{"RC_BINARIES"};
354         foreach my $f (@list)
355         {
356             push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/;  # skip make variables
357         }
358     }
359     return @ignores;
360 }
361
362 ################################################################
363 # update dlls/Makefile.in
364
365 sub update_dlls(@)
366 {
367     my (%directories, %testdirs, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
368     my $text = "";
369     my @ignores = ();
370
371     foreach my $make (@_)
372     {
373         my %makefile = %{$makefiles{$make}};
374         next if defined $makefile{"=skip"};
375
376         if ($make =~ /dlls\/(.*)\/tests\/Makefile/)
377         {
378             $testdirs{$1} = "$1/tests";
379             (my $crosstest = $makefile{"TESTDLL"}) =~ s/\.dll$//;
380             push @ignores, $makefile{"=dir"} . $crosstest . "_crosstest.exe";
381             push @ignores, $makefile{"=dir"} . "testlist.c";
382             push @ignores, $makefile{"=dir"} . "*.ok";
383             next;
384         }
385
386         next unless defined $makefile{"MODULE"};
387         my $module = $makefile{"MODULE"};
388         (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
389
390         if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
391         {
392             $staticlib_dirs{$module} = $dir;
393             die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
394         }
395         else
396         {
397             die "invalid module $module" unless $module =~ /\./;
398             (my $mod = $module) =~ s/\.dll$//;
399             die "invalid directory $dir for module $module\n" unless $mod eq $dir;
400             $directories{$module} = $dir;
401         }
402
403         if (defined $makefile{"IMPORTLIB"})
404         {
405             if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
406             {
407                 $importlibs{$module} = $1;
408             }
409             else
410             {
411                 die "invalid importlib name $makefile{IMPORTLIB} in $make";
412             }
413         }
414
415         $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
416
417         if (defined $makefile{"SPEC_SRCS16"})
418         {
419             my @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @{$makefile{"SPEC_SRCS16"}};
420             $altnames{$module} = \@list;
421         }
422         if (defined $makefile{"EXTRA_OBJS16"})
423         {
424             foreach my $obj (@{$makefile{"EXTRA_OBJS16"}})
425             {
426                 if ($obj =~ /^(.*\.(exe|mod))\.o/) { push @{$altnames{$module}}, $1; }
427             }
428         }
429     }
430
431     # output special dlls configure definitions
432
433     $text .= "# special configure-dependent targets\n\n";
434     my %specials = ();
435     foreach my $mod (sort keys %special_dlls)
436     {
437         $specials{$special_dlls{$mod}} .= " " . $mod;
438     }
439     foreach my $i (sort keys %specials)
440     {
441         $text .= $i . " =" . $specials{$i} . "\n";
442     }
443     $text .= "EXTRADIRS =";
444     foreach my $i (sort keys %specials) { $text .= sprintf " \@%s\@", $i; }
445     $text .= "\n\n";
446
447     # output the subdirs list
448
449     $text .= "# Subdir list\n\n";
450     $text .= "BASEDIRS =";
451     foreach my $dir (sort values %directories)
452     {
453         next if defined($special_dlls{$dir});  # skip special dlls
454         $text .= " \\\n\t" . $dir;
455     }
456
457     $text .= "\n\nIMPLIBSUBDIRS = \\\n\t";
458     $text .=  join " \\\n\t", sort values %staticlib_dirs;
459
460     $text .= "\n\nTESTSUBDIRS = \\\n\t";
461     $text .= join " \\\n\t", sort values %testdirs;
462
463     $text .=  "\n\nSUBDIRS = \\\n\t";
464     $text .= join " \\\n\t", "\$(BASEDIRS)", "\$(IMPLIBSUBDIRS)", "\$(TESTSUBDIRS)", sort keys %special_dlls;
465
466     $text .= "\n\nBUILDSUBDIRS   = \$(BASEDIRS) \$(EXTRADIRS) \$(TESTSUBDIRS)\n";
467     $text .= "INSTALLSUBDIRS = \$(BASEDIRS) \$(EXTRADIRS) \$(IMPLIBSUBDIRS)\n";
468     $text .= "DOCSUBDIRS     = \$(BASEDIRS) \$(EXTRADIRS)\n";
469
470     # output the list of 16-bit files
471
472     my @targets16 = ();
473     foreach my $mod (sort keys %directories)
474     {
475         next unless defined $altnames{$mod};
476         foreach my $i (sort @{$altnames{$mod}})
477         {
478             push @targets16, $i . "16";
479         }
480     }
481     $text .= "\n# 16-bit dlls\n\n";
482     $text .= "WIN16_FILES = \\\n";
483     $text .=  "\t" . join( " \\\n\t", sort @targets16 ) . "\n\n";
484     $text .= "\@MAKE_RULES\@\n\n";
485
486     # output the all: target
487
488     $text .= "# Main target\n\n";
489     $text .= "all: \$(BUILDSUBDIRS) \@WIN16_FILES\@\n\n";
490
491     # output the lib name -> directory rules
492
493     $text .= "# Placeholders for 16-bit libraries\n\n";
494     foreach my $mod (sort keys %directories)
495     {
496         next unless defined $altnames{$mod};
497         $text .= sprintf "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}});
498         $text .= sprintf "\techo \"%s\" >\$\@\n\n", $mod;
499     }
500
501     # output the import libraries rules
502
503     $text .= "# Import libraries\n\n";
504     $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
505
506     my @lib_symlinks = ();
507     foreach my $mod (sort keys %importlibs)
508     {
509         my $dir = $directories{$mod};
510         my $lib = $importlibs{$mod};
511         if ($lib ne $dir) { push @lib_symlinks, $mod; }
512     }
513     $text .= "IMPORT_SYMLINKS =";
514     foreach my $mod (sort @lib_symlinks)
515     {
516         $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
517     }
518
519     $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
520     foreach my $mod (sort keys %staticlib_dirs)
521     {
522         $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
523     }
524     foreach my $mod (sort keys %importlibs)
525     {
526         $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
527         next unless defined $static_implibs{$mod};
528         $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
529     }
530     $text .= "\n\n";
531     $text .= "implib: \$(IMPORT_LIBS)\n\n";
532     $text .= ".PHONY: implib\n\n";
533
534     foreach my $mod (sort keys %importlibs)
535     {
536         my $dir = $directories{$mod};
537         my $lib = $importlibs{$mod};
538         my $spec = $mod;
539         $spec =~ s/\.dll$//;
540         if (defined($static_implibs{$mod}))
541         {
542             $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
543             $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
544             $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
545             $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
546         }
547         else
548         {
549             $text .= sprintf "%s/lib%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
550             $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(IMPLIBEXT)\n\n", $dir, $lib;
551         }
552     }
553     foreach my $mod (sort @lib_symlinks)
554     {
555         my $dir = $directories{$mod};
556         my $lib = "lib" . $importlibs{$mod} . ".\$(IMPLIBEXT)";
557         $text .= sprintf "%s: %s/%s\n", $lib, $dir, $lib;
558         $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib;
559     }
560
561     $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
562     $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
563
564     # output the inter-dll dependencies and rules
565
566     $text .= "# Map library name to the corresponding directory\n\n";
567
568     foreach my $mod (sort keys %staticlib_dirs)
569     {
570         $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
571     }
572     $text .= "\n# Misc rules\n";
573
574     replace_in_file( "dlls/Makefile.in",
575                      '^# special configure-dependent targets',
576                      '^# Misc rules',
577                      $text );
578
579     # .gitignore file
580
581     foreach my $mod (sort @lib_symlinks)
582     {
583         push @ignores, "dlls/lib$importlibs{$mod}.def";
584     }
585     foreach my $mod (sort keys %directories)
586     {
587         next unless defined $altnames{$mod};
588         push @ignores, map { "dlls/" . $_ . "16"; } @{$altnames{$mod}};
589     }
590     foreach my $mod (sort keys %importlibs)
591     {
592         push @ignores, "dlls/$directories{$mod}/lib$importlibs{$mod}.def";
593     }
594
595     return @ignores;
596 }
597
598
599 ################################################################
600 # update programs/Makefile.in
601
602 sub update_progs(@)
603 {
604     my (@subdirs, @install_subdirs, @install_progs);
605
606     my @ignores = ();
607
608     foreach my $make (@_)
609     {
610         my %makefile = %{$makefiles{$make}};
611         my $module = $makefile{"MODULE"};
612         (my $dir = $make) =~ s/^programs\/(.*)\/Makefile$/$1/;
613         die "Invalid module $module in $make" unless "$dir.exe" eq $module;
614         next if defined $makefile{"=skip"};
615         push @subdirs, $dir;
616         push @ignores, "programs/$dir/$dir";
617         push @install_subdirs, $dir unless $dont_install{$dir};
618         push @install_progs, $dir if $bin_install{$dir};
619     }
620
621     replace_in_file( "programs/Makefile.in", '^SUBDIRS\s*=', '^INSTALLDIRS',
622                      "SUBDIRS = \\\n\t",
623                      join( " \\\n\t", @subdirs ),
624                      "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS = \\\n\t",
625                      join( " \\\n\t", @install_subdirs ),
626                      "\n\n# Programs to install in bin directory\nINSTALLPROGS = \\\n\t",
627                      join( " \\\n\t", @install_progs ),
628                      "\n\nINSTALLDIRS = \$(DESTDIR)\$(bindir)\n" );
629
630     return @ignores;
631 }
632
633
634 ################################################################
635 # update include/Makefile.in
636
637 sub update_includes()
638 {
639     return unless -d ".git";
640     my (@h_srcs, @idl_srcs, @tlb_srcs, %subdirs);
641     my @includes = map { s/^include\///; $_; } split /\0/, `git ls-files -c -z include`;
642     foreach my $incl (@includes)
643     {
644         if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
645         next if ($private_headers{$incl});
646         if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
647         elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
648         elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
649         elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
650         elsif ($incl =~ /\.idl$/) { push @idl_srcs, $incl; }
651     }
652     replace_in_file( "include/Makefile.in", '^IDL_H_SRCS\s*=', '^INSTALLDIRS',
653                      "IDL_H_SRCS = \\\n\t",
654                      join( " \\\n\t", sort @idl_srcs ),
655                      "\n\nIDL_TLB_SRCS = \\\n\t",
656                      join( " \\\n\t", sort @tlb_srcs ),
657                      "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(IDL_H_SRCS) \\\n\t",
658                      join( " \\\n\t", sort @h_srcs ),
659                      "\n\nEXTRASUBDIRS = ",
660                      join( " ", sort keys %subdirs ),
661                      "\n\nINSTALLDIRS = \\\n" );
662 }
663
664
665 ################################################################
666 # update the main .gitignore
667
668 sub update_gitignore(@)
669 {
670     my @ignores = values %makerules;
671
672     foreach my $make (@makefiles)
673     {
674         my %makefile = %{$makefiles{$make}};
675         my $dir = $makefile{"=dir"};
676         if (defined $makefile{"MANPAGES"})
677         {
678             push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
679         }
680         if (defined $makefile{"PROGRAMS"})
681         {
682             push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
683         }
684     }
685
686     # prepend a slash to paths that don't have one
687     @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
688
689     # get rid of duplicates
690     my %ignores = ();
691     foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
692
693     replace_in_file( ".gitignore", undef, undef,
694                      "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
695                      join("\n", sort keys %ignores), "\n" );
696 }
697
698
699 if (-d ".git")
700 {
701     @makefiles = map { s/\.in$//; $_; } split /\0/, `git ls-files -c -z Makefile.in \\*/Makefile.in`;
702 }
703 else
704 {
705     @makefiles = map { s/^\.\/(.*)\.in/$1/; $_; } split(/\s/,`find . -name Makefile.in -print`);
706 }
707
708 update_includes();
709
710 foreach my $file (sort values %makerules, @makefiles)
711 {
712     my %make = parse_makefile( $file );
713     $makefiles{$file} = \%make;
714 }
715
716 update_makefiles( @makefiles );
717 push @ignores, update_ignores( @makefiles );
718 push @ignores, update_winetest( @makefiles );
719 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
720 push @ignores, update_progs( sort grep /^programs\/.*\/Makefile$/, @makefiles );
721 update_gitignore( @ignores );