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