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