ntdll/tests: Fix a test failure on NT4.
[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 use strict;
23
24 # Make rules files
25 my %makerules =
26 (
27  "MAKE_RULES" => "Make.rules",
28  "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29  "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30  "MAKE_TEST_RULES" => "dlls/Maketest.rules",
31  "MAKE_PROG_RULES" => "programs/Makeprog.rules",
32 );
33
34 # Programs that we want to install in the bin directory too
35 my %bin_install =
36 (
37   "msiexec" => 1,
38   "notepad" => 1,
39   "regedit" => 1,
40   "regsvr32" => 1,
41   "wineboot" => 1,
42   "winecfg" => 1,
43   "wineconsole" => 1,
44   "winedbg" => 1,
45   "winefile" => 1,
46   "winemine" => 1,
47   "winepath" => 1,
48 );
49
50 # Programs that we don't want to install at all
51 my %dont_install =
52 (
53   "cmdlgtst" => 1,
54   "view" => 1,
55   "winetest" => 1,
56 );
57
58 # Default patterns for top-level .gitignore
59 my @ignores = (
60     "*.[oa]",
61     "*.fake",
62     "*.ok",
63     "*.res",
64     "*.so",
65     "/autom4te.cache",
66     "/config.cache",
67     "/config.log",
68     "/config.status",
69     "/configure.lineno",
70     "/TAGS",
71     "/tags",
72     "Makefile",
73     "dlldata.c",
74     "dlls/*/*.def",
75     "dlls/*/tests/*crosstest.exe",
76     "dlls/*/tests/testlist.c",
77     "include/config.h",
78     "include/stamp-h",
79     "programs/winetest/*_test.exe",
80     "programs/winetest/*_test.rc",
81     "programs/winetest/build.rc",
82 );
83
84 # Source files and their resulting target to ignore
85 my @ignore_srcs = (
86     [ 'BISON_SRCS',   '\.y',   '.tab.c' ],
87     [ 'BISON_SRCS',   '\.y',   '.tab.h' ],
88     [ 'LEX_SRCS',     '\.l',   '.yy.c' ],
89     [ 'MC_SRCS',      '\.mc',  '.mc.rc' ],
90     [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
91     [ 'IDL_H_SRCS',   '\.idl', '.h' ],
92     [ 'IDL_C_SRCS',   '\.idl', '.h' ],
93     [ 'IDL_I_SRCS',   '\.idl', '.h' ],
94     [ 'IDL_P_SRCS',   '\.idl', '.h' ],
95     [ 'IDL_S_SRCS',   '\.idl', '.h' ],
96     [ 'IDL_C_SRCS',   '\.idl', '_c.c' ],
97     [ 'IDL_I_SRCS',   '\.idl', '_i.c' ],
98     [ 'IDL_P_SRCS',   '\.idl', '_p.c' ],
99     [ 'IDL_S_SRCS',   '\.idl', '_s.c' ],
100 );
101
102 my %exported_wine_headers = (
103     "wine/debug.h" => 1,
104     "wine/exception.h" => 1,
105     "wine/library.h" => 1,
106     "wine/unicode.h" => 1,
107     "wine/itss.idl" => 1,
108     "wine/svcctl.idl" => 1,
109 );
110
111 my %private_idl_headers = (
112     "access.idl" => 1,
113     "asynot.idl" => 1,
114     "asysta.idl" => 1,
115     "axcore.idl" => 1,
116     "axextend.idl" => 1,
117     "binres.idl" => 1,
118     "cmdbas.idl" => 1,
119     "cmdtxt.idl" => 1,
120     "crtrow.idl" => 1,
121     "dbccmd.idl" => 1,
122     "dbcses.idl" => 1,
123     "dbdsad.idl" => 1,
124     "dbinit.idl" => 1,
125     "dbprop.idl" => 1,
126     "dbs.idl" => 1,
127     "devenum.idl" => 1,
128     "dyngraph.idl" => 1,
129     "opnrst.idl" => 1,
130     "row.idl" => 1,
131     "rowchg.idl" => 1,
132     "rstbas.idl" => 1,
133     "rstinf.idl" => 1,
134     "rstloc.idl" => 1,
135     "sesprp.idl" => 1,
136     "vmrender.idl" => 1,
137     "wine/wined3d.idl" => 1,
138     "wine/winedxgi.idl" => 1,
139 );
140
141 my %ignored_source_files = (
142     "dlls/wineps.drv/afm2c.c" => 1,
143     "dlls/wineps.drv/mkagl.c" => 1,
144     "programs/winetest/dist.rc" => 1,
145 );
146
147 my (@all_files, @makefiles, %makefiles);
148
149 sub dirname($)
150 {
151     my $ret = shift;
152     return "" unless $ret =~ /\//;
153     $ret =~ s!/[^/]*$!!;
154     return $ret;
155 }
156
157 # update a file if changed
158 sub update_file($)
159 {
160     my $file = shift;
161     my $ret = !(-f $file) || system "cmp $file $file.new >/dev/null";
162     if (!$ret)
163     {
164         unlink "$file.new";
165     }
166     else
167     {
168         rename "$file.new", "$file";
169         print "$file updated\n";
170         if ($file eq "configure.ac")
171         {
172             system "autoconf";
173             print "configure updated\n";
174         }
175     }
176     return $ret;
177 }
178
179 # replace some lines in a file between two markers
180 sub replace_in_file($$$@)
181 {
182     my $file = shift;
183     my $start = shift;
184     my $end = shift;
185
186     open NEW_FILE, ">$file.new" or die "cannot create $file.new";
187
188     if (defined($start))
189     {
190         open OLD_FILE, "$file" or die "cannot open $file";
191         while (<OLD_FILE>)
192         {
193             last if /$start/;
194             print NEW_FILE $_;
195         }
196     }
197
198     print NEW_FILE @_;
199
200     if (defined($end))
201     {
202         my $skip=1;
203         while (<OLD_FILE>)
204         {
205             print NEW_FILE $_ unless $skip;
206             $skip = 0 if /$end/;
207         }
208     }
209
210     close OLD_FILE if defined($start);
211     close NEW_FILE;
212     return update_file($file);
213 }
214
215 # replace a variable in a makefile
216 sub replace_makefile_variable($$)
217 {
218     my ($file, $var) = @_;
219     my $make = $makefiles{$file};
220
221     return unless defined ${$make}{"=$var"};
222
223     my @values = @{${$make}{"=$var"}};
224     ${$make}{$var} = \@values;
225
226     open NEW_FILE, ">$file.in.new" or die "cannot create $file.in.new";
227
228     open OLD_FILE, "$file.in" or die "cannot open $file.in";
229     while (<OLD_FILE>)
230     {
231         if (/^\s*($var\s+)=/)
232         {
233             # try to preserve formatting
234             my $prefix = $1;
235             my $multiline = /\\$/ || (@values > 1);
236             while (/\\$/)
237             {
238                 $_ = <OLD_FILE>;
239                 last unless $_;
240             }
241             if ($multiline)
242             {
243                 print NEW_FILE "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
244             }
245             else
246             {
247                 print NEW_FILE "$prefix= @values\n";
248             }
249             next;
250         }
251         print NEW_FILE $_;
252     }
253     close OLD_FILE;
254     close NEW_FILE;
255     return update_file("$file.in");
256 }
257
258 # parse the specified makefile to identify the rules file
259 sub parse_makefile($)
260 {
261     my $file = shift;
262     my %make;
263
264     ($make{"=dir"} = $file) =~ s/[^\/]+$//;
265
266     open MAKE, "$file.in" or die "cannot open $file.in\n";
267
268     while (<MAKE>)
269     {
270         chomp;
271         next if (/^\s*#/);
272         while (/\\$/) { chop; $_ .= <MAKE>; chomp; }  # merge continued lines
273         next if (/^\s*$/);
274
275         if (/^\@(MAKE.*RULES)\@/)
276         {
277             my $var = $1;
278             $make{"=rules"} = $makerules{$var};
279             next;
280         }
281         if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
282         {
283             $make{$1} = $2;
284             next;
285         }
286         if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|MANPAGES|PROGRAMS)\s*=\s*(.*)/)
287         {
288             my @list = split(/\s+/, $2);
289             $make{$1} = \@list;
290             next;
291         }
292     }
293     return %make;
294 }
295
296 # assign source files to their respective makefile
297 sub assign_sources_to_makefiles()
298 {
299     foreach my $file (@all_files)
300     {
301         next if defined $ignored_source_files{$file};
302         my $dir = dirname( $file );
303
304         while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname( $dir ); }
305         next unless $dir;
306
307         die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
308
309         my $make = $makefiles{"$dir/Makefile"};
310         my $basename = substr( $file, length($dir) + 1 );
311
312         if ($basename =~ /\.c$/) { push @{${$make}{"=C_SRCS"}}, $basename; }
313         elsif ($basename =~ /\.l$/) { push @{${$make}{"=LEX_SRCS"}}, $basename; }
314         elsif ($basename =~ /\.y$/) { push @{${$make}{"=BISON_SRCS"}}, $basename; }
315         elsif ($basename =~ /\.rc$/) { push @{${$make}{"=RC_SRCS"}}, $basename; }
316         elsif ($basename =~ /\.mc$/) { push @{${$make}{"=MC_SRCS"}}, $basename; }
317         elsif ($basename =~ /\.svg$/) { push @{${$make}{"=SVG_SRCS"}}, $basename; }
318     }
319 }
320
321 ################################################################
322 # update the makefile list in configure.ac
323
324 sub update_makefiles(@)
325 {
326     my (@lines);
327
328     foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
329     {
330         my $file = $makerules{$var};
331         my %make = %{$makefiles{$file}};
332         my $rules = $make{"=rules"} ? ",[$make{\"=rules\"}]" : "";
333         push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
334     }
335     push @lines, "\n";
336
337     foreach my $file (sort @_)
338     {
339         my %make = %{$makefiles{$file}};
340         my $rules = $make{"=rules"};
341         my $args = "";
342         if ($rules eq $makerules{"MAKE_DLL_RULES"})
343         {
344             $args = ",[dlls],[ALL_DLL_DIRS]";
345             $args .= ",[enable_win16]" if $make{"MODULE"} =~ /(16|\.vxd)$/;
346         }
347         elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"}) { $args = ",[dlls],[ALL_IMPLIB_DIRS]"; }
348         elsif ($rules eq $makerules{"MAKE_TEST_RULES"}) { $args = ",[dlls],[ALL_TEST_DIRS],[enable_tests]"; }
349         elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
350         {
351             (my $name = $file) =~ s/^programs\/(.*)\/Makefile/$1/;
352             $args = ",[programs],[ALL_PROGRAM_DIRS";
353             $args .= ",ALL_PROGRAM_INSTALL_DIRS" unless $dont_install{$name};
354             $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
355             $args .= "]";
356             $args .= ",[enable_win16]" if $make{"MODULE"} =~ /16$/;
357         }
358         elsif ($file =~ /^[^\/]*\/Makefile$/) { $args = ",[],[ALL_TOP_DIRS]"; }
359         push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules]$args)\n";
360     }
361
362     # update the source variables in all the makefiles
363
364     foreach my $file (sort @_)
365     {
366         my %make = %{$makefiles{$file}};
367
368         replace_makefile_variable( $file, "LEX_SRCS" );
369         replace_makefile_variable( $file, "BISON_SRCS" );
370         replace_makefile_variable( $file, "MC_SRCS" );
371         replace_makefile_variable( $file, "SVG_SRCS" );
372         replace_makefile_variable( $file, "C_SRCS" );
373         replace_makefile_variable( $file, "RC_SRCS" );
374     }
375
376     push @lines, "\ndnl Build dependencies for test files compiled into winetest\n";
377     replace_in_file( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl Build dependencies for test files compiled into winetest$', @lines);
378 }
379
380
381 ################################################################
382 # process ignore targets for generic source files
383
384 sub update_ignores(@)
385 {
386     my @ignores;
387
388     foreach my $file (sort @_)
389     {
390         my %makefile = %{$makefiles{$file}};
391         my @list;
392
393         foreach my $src (@ignore_srcs)
394         {
395             my @pattern = @{$src};
396             next unless defined $makefile{$pattern[0]};
397             push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @{$makefile{$pattern[0]}};
398         }
399         foreach my $f (@list)
400         {
401             push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/;  # skip make variables
402         }
403     }
404     return @ignores;
405 }
406
407 ################################################################
408 # update dlls/Makefile.in
409
410 sub update_dlls(@)
411 {
412     my (%directories, %importlibs, %static_implibs, %staticlib_dirs, %altnames);
413     my $text = "";
414     my @ignores = ();
415
416     foreach my $make (@_)
417     {
418         my %makefile = %{$makefiles{$make}};
419         next if ($makefile{"=rules"} eq $makerules{"MAKE_TEST_RULES"});
420
421         next unless defined $makefile{"MODULE"};
422         my $module = $makefile{"MODULE"};
423         (my $dir = $makefile{"=dir"}) =~ s/^dlls\/(.*)\//$1/;
424
425         if ($makefile{"=rules"} eq $makerules{"MAKE_IMPLIB_RULES"})
426         {
427             $staticlib_dirs{$module} = $dir;
428             die "invalid module $module in dir $staticlib_dirs{$module}\n" if "$staticlib_dirs{$module}" ne $module;
429         }
430         else
431         {
432             die "invalid module $module" unless $module =~ /\./;
433             (my $mod = $module) =~ s/\.dll$//;
434             die "invalid directory $dir for module $module\n" unless $mod eq $dir;
435             $directories{$module} = $dir;
436         }
437
438         if (defined $makefile{"IMPORTLIB"})
439         {
440             if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
441             {
442                 $importlibs{$module} = $1;
443             }
444             else
445             {
446                 die "invalid importlib name $makefile{IMPORTLIB} in $make";
447             }
448         }
449
450         $static_implibs{$module} = 1 if defined $makefile{"IMPLIB_SRCS"};
451     }
452
453     $text .= "\@MAKE_RULES\@\n\n";
454
455     # output the all: target
456
457     $text .= "# Main target\n\n";
458     $text .= "all: \$(BUILDSUBDIRS)\n\n";
459
460     # output the import libraries rules
461
462     $text .= "# Import libraries\n\n";
463     $text .= "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n";
464
465     my @lib_symlinks = ();
466     foreach my $mod (sort keys %importlibs)
467     {
468         my $dir = $directories{$mod};
469         my $lib = $importlibs{$mod};
470         if ($lib ne $dir) { push @lib_symlinks, $mod; }
471     }
472     $text .= "IMPORT_SYMLINKS =";
473     foreach my $mod (sort @lib_symlinks)
474     {
475         $text .= sprintf " \\\n\tlib%s.\$(IMPLIBEXT)", $importlibs{$mod};
476     }
477
478     $text .= "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)";
479     foreach my $mod (sort keys %staticlib_dirs)
480     {
481         $text .= sprintf " \\\n\t%s/lib%s.a", $staticlib_dirs{$mod}, $mod;
482     }
483     foreach my $mod (sort keys %importlibs)
484     {
485         $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(IMPLIBEXT)";
486         next unless defined $static_implibs{$mod};
487         $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.\$(STATIC_IMPLIBEXT)";
488     }
489     $text .= "\n\nCROSS_IMPLIBS =";
490     foreach my $mod (sort @lib_symlinks)
491     {
492         next if $mod =~ /16$/;
493         $text .= sprintf " \\\n\tlib%s.a", $importlibs{$mod};
494     }
495     foreach my $mod (sort keys %importlibs)
496     {
497         next if $mod =~ /16$/;
498         next if defined $static_implibs{$mod};
499         $text .= " \\\n\t$directories{$mod}/lib$importlibs{$mod}.a";
500     }
501     $text .= "\n\n";
502     $text .= "\$(TESTSUBDIRS:%=%/__crosstest__): \$(CROSS_IMPLIBS)\n\n";
503     $text .= "implib: \$(IMPORT_LIBS)\n\n";
504     $text .= "testsubdirs: \$(TESTSUBDIRS)\n\n";
505     $text .= ".PHONY: implib testsubdirs\n\n";
506
507     foreach my $mod (sort keys %importlibs)
508     {
509         my $dir = $directories{$mod};
510         my $lib = $importlibs{$mod};
511         my $spec = $mod;
512         $spec =~ s/\.dll$//;
513         if (defined($static_implibs{$mod}))
514         {
515             $text .= sprintf "%s/lib%s.def: %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec;
516             $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.def\n\n", $dir, $lib;
517             $text .= sprintf "%s/lib%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec;
518             $text .= sprintf "\t\@cd %s && \$(MAKE) lib%s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib;
519         }
520         else
521         {
522             $text .= sprintf "%s/lib%s.def %s/lib%s.a: %s/%s.spec \$(WINEBUILD)\n",
523                              $dir, $lib, $dir, $lib, $dir, $spec;
524             $text .= sprintf "\t\@cd %s && \$(MAKE) `basename \$\@`\n\n", $dir;
525         }
526     }
527     foreach my $mod (sort @lib_symlinks)
528     {
529         my $dir = $directories{$mod};
530         my $lib = "lib" . $importlibs{$mod};
531         $text .= sprintf "%s.a: %s/%s.a\n", $lib, $dir, $lib;
532         $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.a \$@\n\n", $dir, $lib;
533         $text .= sprintf "%s.def: %s/%s.def\n", $lib, $dir, $lib;
534         $text .= sprintf "\t\$(RM) \$@ && \$(LN_S) %s/%s.def \$@\n\n", $dir, $lib;
535     }
536
537     $text .= "\$(BUILDSUBDIRS): \$(IMPORT_LIBS)\n";
538     $text .= "\$(INSTALLSUBDIRS:%=%/__install__) \$(INSTALLSUBDIRS:%=%/__install-lib__): \$(IMPORT_LIBS)\n\n";
539
540     # output the inter-dll dependencies and rules
541
542     $text .= "# Map library name to the corresponding directory\n\n";
543
544     foreach my $mod (sort keys %staticlib_dirs)
545     {
546         $text .= sprintf "%s/lib%s.a: %s\n", $staticlib_dirs{$mod}, $mod, $staticlib_dirs{$mod};
547     }
548     $text .= "\n# Misc rules\n";
549
550     replace_in_file( "dlls/Makefile.in",
551                      '^\@MAKE_RULES\@',
552                      '^# Misc rules',
553                      $text );
554
555     # .gitignore file
556
557     foreach my $mod (sort @lib_symlinks)
558     {
559         push @ignores, "dlls/lib$importlibs{$mod}.def";
560     }
561     return @ignores;
562 }
563
564
565 ################################################################
566 # update include/Makefile.in
567
568 sub update_includes()
569 {
570     my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
571     my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\//, @all_files;
572     foreach my $incl (@includes)
573     {
574         if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
575         next if ($incl =~ /\.in$/);
576         if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
577         {
578             if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
579             next;
580         }
581         if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
582         elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
583         elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
584         elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
585         elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
586         elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
587         else { die "unknown file $incl in include dir"; }
588     }
589     replace_in_file( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
590                      "PRIVATE_IDL_H_SRCS = \\\n\t",
591                      join( " \\\n\t", sort @private_idl_srcs ),
592                      "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
593                      join( " \\\n\t", sort @public_idl_srcs ),
594                      "\n\nIDL_TLB_SRCS = \\\n\t",
595                      join( " \\\n\t", sort @tlb_srcs ),
596                      "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
597                      join( " \\\n\t", sort @h_srcs ),
598                      "\n\nEXTRASUBDIRS = ",
599                      join( " ", sort keys %subdirs ),
600                      "\n\nINSTALLDIRS = \\\n" );
601     return map { s/(.*)\.idl$/include\/$1.h/; $_; } @public_idl_srcs, @private_idl_srcs;
602 }
603
604
605 ################################################################
606 # update the main .gitignore
607
608 sub update_gitignore(@)
609 {
610     my @ignores = values %makerules;
611
612     foreach my $make (@makefiles)
613     {
614         my %makefile = %{$makefiles{$make}};
615         my $dir = $makefile{"=dir"};
616         if (defined $makefile{"MANPAGES"})
617         {
618             push @ignores, map { $dir . $_; } @{$makefile{"MANPAGES"}};
619         }
620         if (defined $makefile{"PROGRAMS"})
621         {
622             push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @{$makefile{"PROGRAMS"}};
623         }
624     }
625
626     # prepend a slash to paths that don't have one
627     @ignores = map { $_ =~ s/^([^\/]+)$/\/$1/; $_; } @ignores;
628
629     # get rid of duplicates
630     my %ignores = ();
631     foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
632
633     replace_in_file( ".gitignore", undef, undef,
634                      "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
635                      join("\n", sort keys %ignores), "\n" );
636 }
637
638
639 die "needs to be run from a git checkout" unless -d ".git";
640
641 @all_files = split /\0/, `git ls-files -c -z`;
642 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
643
644 foreach my $file (sort values %makerules, @makefiles)
645 {
646     my %make = parse_makefile( $file );
647     $makefiles{$file} = \%make;
648 }
649
650 assign_sources_to_makefiles();
651 update_makefiles( @makefiles );
652 push @ignores, update_includes();
653 push @ignores, update_ignores( @makefiles );
654 push @ignores, update_dlls( sort grep /^dlls\//, @makefiles );
655 update_gitignore( @ignores );