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