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