3 # Build the auto-generated parts of the Wine makefiles.
5 # Copyright 2006 Alexandre Julliard
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.
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.
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
27 "MAKE_RULES" => "Make.rules",
28 "MAKE_DLL_RULES" => "dlls/Makedll.rules",
29 "MAKE_IMPLIB_RULES" => "dlls/Makeimplib.rules",
30 "MAKE_TEST_RULES" => "Maketest.rules",
31 "MAKE_PROG_RULES" => "programs/Makeprog.rules",
34 # Programs that we want to install in the bin directory too
50 # Programs that we don't want to install at all
58 # Dlls and programs that are 16-bit specific
75 # Default patterns for top-level .gitignore
93 "*/*/tests/*crosstest.exe",
94 "*/*/tests/testlist.c",
97 "programs/winetest/*_test.exe",
98 "programs/winetest/*_test.rc",
99 "programs/winetest/build.rc",
102 # Source files and their resulting target to ignore
104 [ 'BISON_SRCS', '\.y', '.tab.c' ],
105 [ 'BISON_SRCS', '\.y', '.tab.h' ],
106 [ 'LEX_SRCS', '\.l', '.yy.c' ],
107 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
108 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
109 [ 'IDL_H_SRCS', '\.idl', '.h' ],
110 [ 'IDL_C_SRCS', '\.idl', '.h' ],
111 [ 'IDL_I_SRCS', '\.idl', '.h' ],
112 [ 'IDL_P_SRCS', '\.idl', '.h' ],
113 [ 'IDL_S_SRCS', '\.idl', '.h' ],
114 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
115 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
116 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
117 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
120 my %exported_wine_headers = (
122 "wine/exception.h" => 1,
123 "wine/library.h" => 1,
124 "wine/unicode.h" => 1,
125 "wine/itss.idl" => 1,
126 "wine/svcctl.idl" => 1,
129 my %private_idl_headers = (
155 "wine/wined3d.idl" => 1,
156 "wine/winedxgi.idl" => 1,
159 my %ignored_source_files = (
160 "dlls/wineps.drv/afm2c.c" => 1,
161 "dlls/wineps.drv/mkagl.c" => 1,
162 "programs/winetest/dist.rc" => 1,
165 my (@all_files, @makefiles, %makefiles);
170 return "" unless $ret =~ /\//;
175 # update a file if changed
179 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
186 rename "$file.new", "$file";
187 print "$file updated\n";
188 if ($file eq "configure.ac")
191 print "configure updated\n";
197 # replace some lines in a file between two markers
198 sub replace_in_file
($$$@
)
204 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
208 open OLD_FILE
, "$file" or die "cannot open $file";
223 print NEW_FILE
$_ unless $skip;
228 close OLD_FILE
if defined($start);
230 return update_file
($file);
233 # replace a variable in a makefile
234 sub replace_makefile_variable
($$)
236 my ($file, $var) = @_;
237 my $make = $makefiles{$file};
239 return unless defined ${$make}{"=$var"};
241 my @values = @
{${$make}{"=$var"}};
242 ${$make}{$var} = \
@values;
244 open NEW_FILE
, ">$file.in.new" or die "cannot create $file.in.new";
246 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
249 if (/^\s*($var\s+)=/)
251 # try to preserve formatting
253 my $multiline = /\\$/ || (@values > 1);
261 print NEW_FILE
"$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
265 print NEW_FILE
"$prefix= @values\n";
273 return update_file
("$file.in");
276 # parse the specified makefile to identify the rules file
277 sub parse_makefile
($)
282 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
284 open MAKE
, "$file.in" or die "cannot open $file.in\n";
290 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
293 if (/^\@(MAKE.*RULES)\@/)
296 $make{"=rules"} = $makerules{$var};
299 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
304 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*(.*)/)
306 my @list = split(/\s+/, $2);
314 # assign source files to their respective makefile
315 sub assign_sources_to_makefiles
()
317 foreach my $file (@all_files)
319 next if defined $ignored_source_files{$file};
320 my $dir = dirname
( $file );
322 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
325 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
327 my $make = $makefiles{"$dir/Makefile"};
328 my $basename = substr( $file, length($dir) + 1 );
330 if ($basename =~ /\.c$/) { push @
{${$make}{"=C_SRCS"}}, $basename; }
331 elsif ($basename =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $basename; }
332 elsif ($basename =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $basename; }
333 elsif ($basename =~ /\.rc$/) { push @
{${$make}{"=RC_SRCS"}}, $basename; }
334 elsif ($basename =~ /\.mc$/) { push @
{${$make}{"=MC_SRCS"}}, $basename; }
335 elsif ($basename =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $basename; }
339 ################################################################
340 # update the makefile list in configure.ac
342 sub update_makefiles
(@
)
346 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
348 my $file = $makerules{$var};
349 my %make = %{$makefiles{$file}};
350 my $rules = $make{"=rules"} ?
",[$make{\"=rules\"}]" : "";
351 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
355 foreach my $file (sort @_)
357 my %make = %{$makefiles{$file}};
358 my $rules = $make{"=rules"};
360 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
361 if ($rules eq $makerules{"MAKE_DLL_RULES"})
363 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
364 my $implib = $make{"IMPORTLIB"} || "";
365 my $implib_srcs = defined($make{"IMPLIB_SRCS"}) && join( " ", @
{$make{"IMPLIB_SRCS"}} );
366 $args .= "," if $implib || $is_win16;
367 $args .= "enable_win16" if $is_win16;
368 $args .= ",[$implib]" if $implib;
369 $args .= ",[$implib_srcs]" if $implib_srcs;
370 push @lines, "WINE_CONFIG_DLL($name$args)\n";
372 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
374 (my $name = $file) =~ s/^programs\/(.*)\/Makefile
/$1/;
375 $args = ",[ALL_PROGRAM_DIRS";
376 $args .= ",ALL_INSTALL_DIRS" unless $dont_install{$name};
377 $args .= ",ALL_PROGRAM_BIN_INSTALL_DIRS" if $bin_install{$name};
379 $args .= ",enable_win16" if $is_win16;
380 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
382 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
384 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
385 push @lines, "WINE_CONFIG_TEST($dir)\n";
387 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
389 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
390 push @lines, "WINE_CONFIG_LIB($name)\n";
392 elsif ($file =~ /^tools.*\/Makefile
$/)
394 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules],[ALL_TOOL_DIRS],enable_tools)\n";
396 elsif ($file =~ /^[^\/]*\
/Makefile$/)
398 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules],[ALL_TOP_DIRS])\n";
402 push @lines, "WINE_CONFIG_MAKEFILE([$file],[$rules])\n";
406 # update the source variables in all the makefiles
408 foreach my $file (sort @_)
410 my %make = %{$makefiles{$file}};
412 replace_makefile_variable
( $file, "LEX_SRCS" );
413 replace_makefile_variable
( $file, "BISON_SRCS" );
414 replace_makefile_variable
( $file, "MC_SRCS" );
415 replace_makefile_variable
( $file, "SVG_SRCS" );
416 replace_makefile_variable
( $file, "C_SRCS" );
417 replace_makefile_variable
( $file, "RC_SRCS" );
420 push @lines, "dnl End of auto-generated output commands\n";
421 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
425 ################################################################
426 # process ignore targets for generic source files
428 sub update_ignores
(@
)
432 foreach my $file (sort @_)
434 my %makefile = %{$makefiles{$file}};
437 foreach my $src (@ignore_srcs)
439 my @pattern = @
{$src};
440 next unless defined $makefile{$pattern[0]};
441 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
443 foreach my $f (@list)
445 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
448 if (defined $makefile{"IMPORTLIB"})
450 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
452 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
456 die "invalid importlib name $makefile{IMPORTLIB} in $file";
464 ################################################################
465 # update include/Makefile.in
467 sub update_includes
()
469 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
470 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\
//, @all_files;
471 foreach my $incl (@includes)
473 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
474 next if ($incl =~ /\.in$/);
475 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
477 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
480 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
481 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
482 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
483 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
484 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
485 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
486 else { die "unknown file $incl in include dir"; }
488 replace_in_file
( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
489 "PRIVATE_IDL_H_SRCS = \\\n\t",
490 join( " \\\n\t", sort @private_idl_srcs ),
491 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
492 join( " \\\n\t", sort @public_idl_srcs ),
493 "\n\nIDL_TLB_SRCS = \\\n\t",
494 join( " \\\n\t", sort @tlb_srcs ),
495 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
496 join( " \\\n\t", sort @h_srcs ),
497 "\n\nEXTRASUBDIRS = ",
498 join( " ", sort keys %subdirs ),
499 "\n\nINSTALLDIRS = \\\n" );
500 return map { s/(.*)\.idl$/include\/$1.h
/; $_; } @public_idl_srcs, @private_idl_srcs;
504 ################################################################
505 # update the main .gitignore
507 sub update_gitignore
(@
)
509 my @ignores = values %makerules;
511 foreach my $make (@makefiles)
513 my %makefile = %{$makefiles{$make}};
514 my $dir = $makefile{"=dir"};
515 if (defined $makefile{"MANPAGES"})
517 push @ignores, map { $dir . $_; } @
{$makefile{"MANPAGES"}};
519 if (defined $makefile{"PROGRAMS"})
521 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
525 # prepend a slash to paths that don't have one
526 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
528 # get rid of duplicates
530 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
532 replace_in_file
( ".gitignore", undef, undef,
533 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
534 join("\n", sort keys %ignores), "\n" );
538 die "needs to be run from a git checkout" unless -d
".git";
540 @all_files = split /\0/, `git ls-files -c -z`;
541 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
543 foreach my $file (sort values %makerules, @makefiles)
545 my %make = parse_makefile
( $file );
546 $makefiles{$file} = \
%make;
549 assign_sources_to_makefiles
();
550 update_makefiles
( @makefiles );
551 push @ignores, update_includes
();
552 push @ignores, update_ignores
( @makefiles );
553 update_gitignore
( @ignores );