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