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
94 "dlls/shell32/AUTHORS",
95 "*/*/tests/*crosstest.exe",
96 "*/*/tests/testlist.c",
99 "programs/winetest/*_test.exe",
100 "programs/winetest/*_test.rc",
101 "programs/winetest/build.nfo",
102 "programs/winetest/build.rc",
106 # Source files and their resulting target to ignore
108 [ 'BISON_SRCS', '\.y', '.tab.c' ],
109 [ 'BISON_SRCS', '\.y', '.tab.h' ],
110 [ 'LEX_SRCS', '\.l', '.yy.c' ],
111 [ 'MC_SRCS', '\.mc', '.mc.rc' ],
112 [ 'IDL_TLB_SRCS', '\.idl', '.tlb' ],
113 [ 'IDL_H_SRCS', '\.idl', '.h' ],
114 [ 'IDL_C_SRCS', '\.idl', '.h' ],
115 [ 'IDL_I_SRCS', '\.idl', '.h' ],
116 [ 'IDL_P_SRCS', '\.idl', '.h' ],
117 [ 'IDL_S_SRCS', '\.idl', '.h' ],
118 [ 'IDL_C_SRCS', '\.idl', '_c.c' ],
119 [ 'IDL_I_SRCS', '\.idl', '_i.c' ],
120 [ 'IDL_P_SRCS', '\.idl', '_p.c' ],
121 [ 'IDL_S_SRCS', '\.idl', '_s.c' ],
124 my %exported_wine_headers = (
126 "wine/exception.h" => 1,
127 "wine/library.h" => 1,
128 "wine/unicode.h" => 1,
129 "wine/itss.idl" => 1,
130 "wine/svcctl.idl" => 1,
133 my %private_idl_headers = (
161 "wine/wined3d.idl" => 1,
162 "wine/winedxgi.idl" => 1,
165 my %ignored_source_files = (
166 "dlls/wineps.drv/afm2c.c" => 1,
167 "dlls/wineps.drv/mkagl.c" => 1,
168 "programs/winetest/dist.rc" => 1,
171 my (@all_files, @makefiles, %makefiles);
176 return "" unless $ret =~ /\//;
181 # update a file if changed
185 my $ret = !(-f
$file) || system "cmp $file $file.new >/dev/null";
192 rename "$file.new", "$file";
193 print "$file updated\n";
194 if ($file eq "configure.ac")
197 print "configure updated\n";
203 # replace some lines in a file between two markers
204 sub replace_in_file
($$$@
)
210 open NEW_FILE
, ">$file.new" or die "cannot create $file.new";
214 open OLD_FILE
, "$file" or die "cannot open $file";
229 print NEW_FILE
$_ unless $skip;
234 close OLD_FILE
if defined($start);
236 return update_file
($file);
239 # replace a variable in a makefile
240 sub replace_makefile_variable
($$)
242 my ($file, $var) = @_;
243 my $make = $makefiles{$file};
245 return unless defined ${$make}{"=$var"};
247 my @values = @
{${$make}{"=$var"}};
248 ${$make}{$var} = \
@values;
250 open NEW_FILE
, ">$file.in.new" or die "cannot create $file.in.new";
252 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
255 if (/^\s*($var\s+)=/)
257 # try to preserve formatting
259 my $multiline = /\\$/ || (@values > 1);
267 print NEW_FILE
"$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
271 print NEW_FILE
"$prefix= @values\n";
279 return update_file
("$file.in");
282 # parse the specified makefile to identify the rules file
283 sub parse_makefile
($)
288 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
290 open MAKE
, "$file.in" or die "cannot open $file.in\n";
296 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
299 if (/^\@(MAKE.*RULES)\@/)
302 $make{"=rules"} = $makerules{$var};
305 if (/^\s*(MODULE|IMPORTLIB|TESTDLL)\s*=\s*(.*)/)
310 if (/^\s*(BISON_SRCS|LEX_SRCS|IDL_[CHIPRS]_SRCS|IDL_TLB_SRCS|IMPLIB_SRCS|C_SRCS|MC_SRCS|RC_SRCS|SVG_SRCS|PROGRAMS)\s*=\s*(.*)/)
312 my @list = split(/\s+/, $2);
316 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
318 die "Variable $1 in $file.in is obsolete";
324 # assign source files to their respective makefile
325 sub assign_sources_to_makefiles
()
327 foreach my $file (@all_files)
329 next if defined $ignored_source_files{$file};
330 my $dir = dirname
( $file );
332 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
335 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
337 my $make = $makefiles{"$dir/Makefile"};
338 my $basename = substr( $file, length($dir) + 1 );
340 if ($basename =~ /\.c$/) { push @
{${$make}{"=C_SRCS"}}, $basename; }
341 elsif ($basename =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $basename; }
342 elsif ($basename =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $basename; }
343 elsif ($basename =~ /\.rc$/) { push @
{${$make}{"=RC_SRCS"}}, $basename; }
344 elsif ($basename =~ /\.mc$/) { push @
{${$make}{"=MC_SRCS"}}, $basename; }
345 elsif ($basename =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $basename; }
349 ################################################################
350 # update the makefile list in configure.ac
352 sub update_makefiles
(@
)
356 foreach my $var (sort { $makerules{$a} cmp $makerules{$b}; } keys %makerules)
358 my $file = $makerules{$var};
359 my %make = %{$makefiles{$file}};
360 my $rules = $make{"=rules"} ?
",[$make{\"=rules\"}]" : "";
361 push @lines, "WINE_CONFIG_MAKERULES([$file],[$var]$rules)\n";
365 foreach my $file (sort @_)
367 my %make = %{$makefiles{$file}};
368 my $rules = $make{"=rules"};
371 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
372 if ($rules eq $makerules{"MAKE_DLL_RULES"})
374 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
377 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
381 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
383 my $implib = $make{"IMPORTLIB"} || "";
384 push @flags, "implib" if $implib;
385 push @flags, "staticimplib" if defined($make{"IMPLIB_SRCS"});
386 $args .= "," if $is_win16 || @flags;
387 $args .= "enable_win16" if $is_win16;
388 $args .= ",[" . join(",",@flags) ."]" if @flags;
389 $args .= ",[$implib]" if $implib;
390 push @lines, "WINE_CONFIG_DLL($name$args)\n";
392 elsif ($rules eq $makerules{"MAKE_PROG_RULES"})
394 (my $name = $file) =~ s/^programs\/(.*)\/Makefile
/$1/;
397 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
401 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
403 push @flags, "install" unless $dont_install{$name};
404 push @flags, "installbin" if $bin_install{$name};
405 $args .= "," if $is_win16 || @flags;
406 $args .= "enable_win16" if $is_win16;
407 $args .= ",[" . join(",",@flags) ."]" if @flags;
408 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
410 elsif ($rules eq $makerules{"MAKE_TEST_RULES"})
412 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
413 push @lines, "WINE_CONFIG_TEST($dir)\n";
415 elsif ($rules eq $makerules{"MAKE_IMPLIB_RULES"})
417 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
418 push @lines, "WINE_CONFIG_LIB($name)\n";
420 elsif ($file =~ /^tools.*\/Makefile
$/)
422 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
423 push @lines, "WINE_CONFIG_TOOL($name)\n";
425 elsif ($file =~ /\/Makefile
$/)
427 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
428 push @lines, "WINE_CONFIG_MAKEFILE([$name])\n";
432 # update the source variables in all the makefiles
434 foreach my $file (sort @_)
436 my %make = %{$makefiles{$file}};
438 replace_makefile_variable
( $file, "LEX_SRCS" );
439 replace_makefile_variable
( $file, "BISON_SRCS" );
440 replace_makefile_variable
( $file, "MC_SRCS" );
441 replace_makefile_variable
( $file, "SVG_SRCS" );
442 replace_makefile_variable
( $file, "C_SRCS" );
443 replace_makefile_variable
( $file, "RC_SRCS" );
446 push @lines, "dnl End of auto-generated output commands\n";
447 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKERULES', '^dnl End of auto-generated output commands\n$', @lines);
451 ################################################################
452 # process ignore targets for generic source files
454 sub update_ignores
(@
)
458 foreach my $file (sort @_)
460 my %makefile = %{$makefiles{$file}};
463 foreach my $src (@ignore_srcs)
465 my @pattern = @
{$src};
466 next unless defined $makefile{$pattern[0]};
467 push @list, map { (my $ret = $_) =~ s/$pattern[1]$/$pattern[2]/; $ret; } @
{$makefile{$pattern[0]}};
469 foreach my $f (@list)
471 push @ignores, $makefile{"=dir"} . $f unless $f =~ /\$\(.*\)/; # skip make variables
474 if (defined $makefile{"IMPORTLIB"})
476 if ($makefile{"IMPORTLIB"} =~ /^([a-zA-Z0-9_.]+)/)
478 if ("dlls/$1/" ne $makefile{"=dir"}) { push @ignores, "dlls/lib$1.def"; }
482 die "invalid importlib name $makefile{IMPORTLIB} in $file";
490 ################################################################
491 # update include/Makefile.in
493 sub update_includes
()
495 my (@h_srcs, @private_idl_srcs, @public_idl_srcs, @tlb_srcs, %subdirs);
496 my @includes = map { (my $ret = $_) =~ s/^include\///; $ret; } grep /^include\
//, @all_files;
497 foreach my $incl (@includes)
499 if ($incl =~ /(.*)\//) { $subdirs{$1} = 1; }
500 next if ($incl =~ /\.in$/);
501 if ($incl =~ /^wine\// && !$exported_wine_headers{$incl})
503 if ($private_idl_headers{$incl}) { push @private_idl_srcs, $incl; }
506 if ($incl =~ /stdole2\.idl$/) { push @tlb_srcs, $incl; }
507 elsif ($private_idl_headers{$incl}) { push @h_srcs, $incl; }
508 elsif ($incl =~ /\.h$/) { push @h_srcs, $incl; }
509 elsif ($incl =~ /\.rh$/) { push @h_srcs, $incl; }
510 elsif ($incl =~ /\.inl$/) { push @h_srcs, $incl; }
511 elsif ($incl =~ /\.idl$/) { push @public_idl_srcs, $incl; }
512 else { die "unknown file $incl in include dir"; }
514 replace_in_file
( "include/Makefile.in", '^PRIVATE_IDL_H_SRCS\s*=', '^INSTALLDIRS',
515 "PRIVATE_IDL_H_SRCS = \\\n\t",
516 join( " \\\n\t", sort @private_idl_srcs ),
517 "\n\nPUBLIC_IDL_H_SRCS = \\\n\t",
518 join( " \\\n\t", sort @public_idl_srcs ),
519 "\n\nIDL_TLB_SRCS = \\\n\t",
520 join( " \\\n\t", sort @tlb_srcs ),
521 "\n\nSRCDIR_INCLUDES = \\\n\t\$(IDL_TLB_SRCS) \\\n\t\$(PUBLIC_IDL_H_SRCS) \\\n\t",
522 join( " \\\n\t", sort @h_srcs ),
523 "\n\nEXTRASUBDIRS = ",
524 join( " ", sort keys %subdirs ),
525 "\n\nINSTALLDIRS = \\\n" );
526 return map { s/(.*)\.idl$/include\/$1.h
/; $_; } @public_idl_srcs, @private_idl_srcs;
530 ################################################################
531 # update the main .gitignore
533 sub update_gitignore
(@
)
535 my @ignores = values %makerules;
537 foreach my $make (@makefiles)
539 my %makefile = %{$makefiles{$make}};
540 my $dir = $makefile{"=dir"};
541 if (defined $makefile{"PROGRAMS"})
543 push @ignores, map { s/\$\(EXEEXT\)//; $dir . $_; } @
{$makefile{"PROGRAMS"}};
547 # prepend a slash to paths that don't have one
548 @ignores = map { $_ =~ s/^([^\/]+)$/\
/$1/; $_; } @ignores;
550 # get rid of duplicates
552 foreach my $i (@ignores, @_) { $ignores{$i} = 1; }
554 replace_in_file
( ".gitignore", undef, undef,
555 "# Automatically generated by make_makefiles; DO NOT EDIT!!\n",
556 join("\n", sort keys %ignores), "\n" );
560 die "needs to be run from a git checkout" unless -d
".git";
562 @all_files = split /\0/, `git ls-files -c -z`;
563 @makefiles = map { my $ret = $_; $ret =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
565 foreach my $file (sort values %makerules, @makefiles)
567 my %make = parse_makefile
( $file );
568 $makefiles{$file} = \
%make;
571 assign_sources_to_makefiles
();
572 update_makefiles
( @makefiles );
573 push @ignores, update_includes
();
574 push @ignores, update_ignores
( @makefiles );
575 update_gitignore
( @ignores );