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