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
24 # Dlls and programs that are 16-bit specific
41 my %exported_wine_headers = (
43 "wine/exception.h" => 1,
44 "wine/library.h" => 1,
45 "wine/unicode.h" => 1,
47 "wine/svcctl.idl" => 1,
50 my %ignored_source_files = (
51 "dlls/wineps.drv/afm2c.c" => 1,
52 "dlls/wineps.drv/mkagl.c" => 1,
53 "include/config.h.in" => 1,
54 "include/stamp-h.in" => 1,
55 "programs/winetest/dist.rc" => 1,
56 "tools/makedep.c" => 1,
77 my (@makefiles, %makefiles);
82 return "" unless $ret =~ /\//;
87 # update a file if changed
93 open FILE
, ">$file.new" or die "cannot create $file.new";
96 rename "$file.new", "$file";
97 print "$file updated\n";
98 if ($file eq "configure.ac")
101 print "configure updated\n";
105 # replace some lines in a file between two markers
106 sub replace_in_file
($$$@
)
113 open OLD_FILE
, "$file" or die "cannot open $file";
127 $new .= $_ unless $skip;
132 update_file
($file, $new) if $old ne $new;
135 # replace all source variables in a makefile
136 sub replace_makefile_variables
($)
139 my $make = $makefiles{$file};
140 my $source_vars_regexp = join "|", @source_vars;
145 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
149 if (/^\s*($source_vars_regexp)(\s*)=/)
151 # try to preserve formatting
157 if (defined ${$make}{"=$var"})
159 @values = @
{${$make}{"=$var"}};
160 ${$make}{$var} = \
@values;
164 undef ${$make}{$var};
166 my $multiline = /\\$/ || (@values > 1);
182 $new_str = "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
187 $new_str = "$var$spaces= @values\n";
195 # if we are using SOURCES, ignore the other variables
196 unless ($replaced{"SOURCES"})
198 foreach my $var (@source_vars)
200 next if defined $replaced{$var};
201 next if $var eq "SOURCES";
202 next unless defined ${$make}{"=$var"};
203 my @values = @
{${$make}{"=$var"}};
205 $new .= "\n$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
209 update_file
("$file.in", $new) if $old ne $new;
212 # parse the specified makefile and load the variables
213 sub parse_makefile
($)
218 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
220 open MAKE
, "$file.in" or die "cannot open $file.in\n";
226 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
229 if (/\@[A-Z_]+\@/) # config.status substitution variable
231 die "Configure substitution is not allowed in $file" unless $file eq "Makefile";
233 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE)\s*=\s*(.*)/)
239 my $source_vars_regexp = join "|", @source_vars;
240 if (/^\s*($source_vars_regexp|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
243 my @list = split(/\s+/, $2);
244 $make{$var} = \
@list;
247 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
249 die "Variable $1 in $file.in is obsolete";
256 # read pragma makedep flags from a source file
257 sub get_makedep_flags
($)
262 open FILE
, $file or die "cannot open $file";
263 if ($file =~ /\.sfd$/)
267 next unless /^UComments:\s*\"(.*)\"$/;
268 foreach my $pragma (split /\+AAoA/, $1)
270 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
271 foreach my $flag (split /\s+/, $1)
274 last if $flag eq "font";
283 next unless /^#\s*pragma\s+makedep\s+(.*)/;
284 foreach my $flag (split /\s+/, $1)
286 last if $flag eq "depend";
295 sub get_parent_makefile
($)
298 my %make = %{$makefiles{$file}};
299 my $reldir = $make{"PARENTSRC"} || "";
300 return "" unless $reldir;
301 (my $path = $file) =~ s/\/Makefile$/\
//;
302 while ($reldir =~ /^\.\.\//)
304 $reldir =~ s/^\.\.\///;
305 $path =~ s/[^\/]+\/$//;
307 return "$path$reldir/Makefile";
310 # preserve shared source files that are listed in the existing makefile
311 sub preserve_shared_source_files
($$$)
313 my ($make, $parent, $var) = @_;
316 return unless defined ${$parent}{"=$var"};
317 foreach my $file (@
{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
318 foreach my $file (@
{${$make}{"=$var"}}) { $srcs{$file} = 0; }
320 foreach my $file (@
{${$make}{$var}})
322 next unless defined $srcs{$file} && $srcs{$file} == 1;
323 push @
{${$make}{"=$var"}}, $file;
327 # assign source files to their respective makefile
328 sub assign_sources_to_makefiles
(@
)
330 foreach my $file (@_)
332 next if defined $ignored_source_files{$file};
333 next if $file =~ /Makefile\.in$/;
334 my $dir = dirname
( $file );
337 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
338 $subdir =~ s/^$dir\/?//;
341 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
343 my $make = $makefiles{"$dir/Makefile"};
344 my $name = substr( $file, length($dir) + 1 );
345 my %flags = get_makedep_flags
( $file );
347 next if $file =~ /^include\/wine\
// && !%flags && !$exported_wine_headers{$name};
349 if ($name =~ /\.m$/) { push @
{${$make}{"=OBJC_SRCS"}}, $name; }
350 elsif ($name =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $name; }
351 elsif ($name =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $name; }
352 elsif ($name =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $name; }
353 elsif ($name =~ /\.sfd$/)
355 push @
{${$make}{"=FONT_SRCS"}}, $name;
357 elsif ($name =~ /\.c$/)
359 push @
{${$make}{"=C_SRCS"}}, $name;
361 elsif ($name =~ /\.h$/ || $name =~ /\.rh$/ || $name =~ /\.inl$/ || $name =~ /\.x$/)
363 next if $dir ne "include";
365 elsif ($name =~ /\.rc$/)
367 push @
{${$make}{"=RC_SRCS"}}, $name;
369 elsif ($name =~ /\.mc$/)
371 push @
{${$make}{"=MC_SRCS"}}, $name;
373 elsif ($name =~ /\.po$/)
375 push @
{${$make}{"=PO_SRCS"}}, $name;
377 elsif ($name =~ /\.idl$/)
379 die "no makedep flags specified in $file" unless %flags || $dir eq "include";
380 push @
{${$make}{"=IDL_SRCS"}}, $name;
382 elsif ($name =~ /\.man\.in$/)
384 push @
{${$make}{"=MANPAGES"}}, $name;
386 elsif ($name =~ /\.in$/)
388 push @
{${$make}{"=IN_SRCS"}}, $name;
390 elsif ($name =~ /\.spec$/)
392 next unless defined ${$make}{"TESTDLL"};
394 elsif ($dir ne "loader") # loader dir contains misc files
398 push @
{${$make}{"=SOURCES"}}, $name;
401 # preserve shared source files from the parent makefile
402 foreach my $file (@makefiles)
404 my $make = $makefiles{$file};
405 my $parent = get_parent_makefile
( $file );
407 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
408 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
409 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
410 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
414 ################################################################
415 # update the makefile list in configure.ac
417 sub update_makefiles
(@
)
421 foreach my $file (sort @_)
423 my %make = %{$makefiles{$file}};
425 my $is_win16 = $make{"MODULE"} && ($make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}});
426 if (defined($make{"TESTDLL"})) # test
428 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\
/Makefile$/;
429 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
430 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
431 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
432 push @lines, "WINE_CONFIG_TEST($dir)\n";
434 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
436 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
437 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
438 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
439 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
440 push @lines, "WINE_CONFIG_LIB($name)\n";
442 elsif (defined($make{"MODULE"}) && defined($make{"APPMODE"})) # program
444 die "APPMODE should not be defined in $file" unless $file =~ /^programs\//;
445 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
446 (my $name = $file) =~ s/^programs\/(.*)\/Makefile
/$1/;
449 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
453 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.exe";
455 $args .= ",enable_win16" if $is_win16;
456 push @lines, "WINE_CONFIG_PROGRAM($name$args)\n";
458 elsif (defined($make{"MODULE"})) # dll
460 die "APPMODE should be defined in $file" if $file =~ /^programs\//;
461 die "MODULE should not be defined in $file" unless $file =~ /^dlls\//;
462 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
463 (my $name = $file) =~ s/^dlls\/(.*)\/Makefile
/$1/;
466 die "Invalid MODULE in $file" unless $make{"MODULE"} eq $name;
470 die "Invalid MODULE in $file" unless $make{"MODULE"} eq "$name.dll";
472 my $implib = $make{"IMPORTLIB"} || "";
473 die "Invalid IMPORTLIB name in $file" if $implib =~ /\./;
474 $args .= ",enable_win16" if $is_win16;
475 push @lines, "WINE_CONFIG_DLL($name$args)\n";
477 elsif ($file =~ /^tools.*\/Makefile
$/)
479 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
480 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
481 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
482 push @lines, "WINE_CONFIG_TOOL($name)\n";
484 elsif ($file =~ /\/Makefile
$/)
486 (my $name = $file) =~ s/^(.*)\/Makefile/$1/;
487 push @lines, "WINE_CONFIG_MAKEFILE($name)\n";
491 # update the source variables in all the makefiles
493 foreach my $file (sort @_) { replace_makefile_variables
( $file ); }
495 push @lines, "dnl End of auto-generated output commands\n";
496 replace_in_file
( "configure.ac", '^WINE_CONFIG_DLL', '^dnl End of auto-generated output commands\n$', @lines);
500 my $git_dir = $ENV{GIT_DIR
} || ".git";
501 die "needs to be run from a git checkout" unless -d
$git_dir;
503 my @all_files = split /\0/, `git ls-files -c -z`;
504 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
505 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
507 foreach my $file (sort @makefiles)
509 my %make = parse_makefile
( $file );
510 $makefiles{$file} = \
%make;
513 assign_sources_to_makefiles
( @all_files );
514 update_makefiles
( @makefiles );