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,
46 "wine/svcctl.idl" => 1,
49 my %ignored_source_files = (
50 "dlls/wineps.drv/afm2c.c" => 1,
51 "dlls/wineps.drv/mkagl.c" => 1,
52 "include/config.h.in" => 1,
53 "include/stamp-h.in" => 1,
54 "programs/winetest/dist.rc" => 1,
55 "tools/makedep.c" => 1,
76 my (@makefiles, %makefiles);
81 return "" unless $ret =~ /\//;
86 # update a file if changed
92 open FILE
, ">$file.new" or die "cannot create $file.new";
95 rename "$file.new", "$file";
96 print "$file updated\n";
97 if ($file eq "configure.ac")
100 print "configure updated\n";
104 # replace some lines in a file between two markers
105 sub replace_in_file
($$$@
)
112 open OLD_FILE
, "$file" or die "cannot open $file";
126 $new .= $_ unless $skip;
131 update_file
($file, $new) if $old ne $new;
134 # replace all source variables in a makefile
135 sub replace_makefile_variables
($)
138 my $make = $makefiles{$file};
139 my $source_vars_regexp = join "|", @source_vars;
144 open OLD_FILE
, "$file.in" or die "cannot open $file.in";
148 if (/^\s*($source_vars_regexp)(\s*)=/)
150 # try to preserve formatting
156 if (defined ${$make}{"=$var"})
158 @values = @
{${$make}{"=$var"}};
159 ${$make}{$var} = \
@values;
163 undef ${$make}{$var};
165 my $multiline = /\\$/ || (@values > 1);
181 $new_str = "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
186 $new_str = "$var$spaces= @values\n";
194 # if we are using SOURCES, ignore the other variables
195 unless ($replaced{"SOURCES"})
197 foreach my $var (@source_vars)
199 next if defined $replaced{$var};
200 next if $var eq "SOURCES";
201 next unless defined ${$make}{"=$var"};
202 my @values = @
{${$make}{"=$var"}};
204 $new .= "\n$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
208 update_file
("$file.in", $new) if $old ne $new;
211 # parse the specified makefile and load the variables
212 sub parse_makefile
($)
217 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
219 open MAKE
, "$file.in" or die "cannot open $file.in\n";
225 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
228 if (/\@[A-Z_]+\@/) # config.status substitution variable
230 die "Configure substitution is not allowed in $file" unless $file eq "Makefile";
232 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|PARENTSRC|APPMODE|EXTRADLLFLAGS)\s*=\s*(.*)/)
238 my $source_vars_regexp = join "|", @source_vars;
239 if (/^\s*($source_vars_regexp|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
242 my @list = split(/\s+/, $2);
243 $make{$var} = \
@list;
246 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
248 die "Variable $1 in $file.in is obsolete";
255 # read pragma makedep flags from a source file
256 sub get_makedep_flags
($)
261 open FILE
, $file or die "cannot open $file";
262 if ($file =~ /\.sfd$/)
266 next unless /^UComments:\s*\"(.*)\"$/;
267 foreach my $pragma (split /\+AAoA/, $1)
269 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
270 foreach my $flag (split /\s+/, $1)
273 last if $flag eq "font";
282 next unless /^#\s*pragma\s+makedep\s+(.*)/;
283 foreach my $flag (split /\s+/, $1)
285 last if $flag eq "depend";
294 sub get_parent_makefile
($)
297 my %make = %{$makefiles{$file}};
298 my $reldir = $make{"PARENTSRC"} || "";
299 return "" unless $reldir;
300 (my $path = $file) =~ s/\/Makefile$/\
//;
301 while ($reldir =~ /^\.\.\//)
303 $reldir =~ s/^\.\.\///;
304 $path =~ s/[^\/]+\/$//;
306 return "$path$reldir/Makefile";
309 # preserve shared source files that are listed in the existing makefile
310 sub preserve_shared_source_files
($$$)
312 my ($make, $parent, $var) = @_;
315 return unless defined ${$parent}{"=$var"};
316 foreach my $file (@
{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
317 foreach my $file (@
{${$make}{"=$var"}}) { $srcs{$file} = 0; }
319 foreach my $file (@
{${$make}{$var}})
321 next unless defined $srcs{$file} && $srcs{$file} == 1;
322 push @
{${$make}{"=$var"}}, $file;
326 # assign source files to their respective makefile
327 sub assign_sources_to_makefiles
(@
)
329 foreach my $file (@_)
331 next if defined $ignored_source_files{$file};
332 next if $file =~ /Makefile\.in$/;
333 my $dir = dirname
( $file );
336 while ($dir && !defined $makefiles{"$dir/Makefile"}) { $dir = dirname
( $dir ); }
337 $subdir =~ s/^$dir\/?//;
340 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile"};
342 my $make = $makefiles{"$dir/Makefile"};
343 my $name = substr( $file, length($dir) + 1 );
345 next if $file =~ /^include\/wine\
// && !get_makedep_flags
($file) && !$exported_wine_headers{$name};
347 if ($name =~ /\.m$/) { push @
{${$make}{"=OBJC_SRCS"}}, $name; }
348 elsif ($name =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $name; }
349 elsif ($name =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $name; }
350 elsif ($name =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $name; }
351 elsif ($name =~ /\.sfd$/)
353 push @
{${$make}{"=FONT_SRCS"}}, $name;
355 elsif ($name =~ /\.c$/)
357 push @
{${$make}{"=C_SRCS"}}, $name;
359 elsif ($name =~ /\.h$/ || $name =~ /\.rh$/ || $name =~ /\.inl$/ || $name =~ /\.x$/)
361 next if $dir ne "include";
363 elsif ($name =~ /\.rc$/)
365 push @
{${$make}{"=RC_SRCS"}}, $name;
367 elsif ($name =~ /\.mc$/)
369 push @
{${$make}{"=MC_SRCS"}}, $name;
371 elsif ($name =~ /\.po$/)
373 push @
{${$make}{"=PO_SRCS"}}, $name;
375 elsif ($name =~ /\.idl$/)
377 die "no makedep flags specified in $file" unless $dir eq "include" || get_makedep_flags
($file);
378 push @
{${$make}{"=IDL_SRCS"}}, $name;
380 elsif ($name =~ /\.man\.in$/)
382 push @
{${$make}{"=MANPAGES"}}, $name;
384 elsif ($name =~ /\.in$/)
386 push @
{${$make}{"=IN_SRCS"}}, $name;
388 elsif ($name =~ /\.spec$/)
390 next unless defined ${$make}{"TESTDLL"};
392 elsif ($dir ne "loader") # loader dir contains misc files
396 push @
{${$make}{"=SOURCES"}}, $name;
399 # preserve shared source files from the parent makefile
400 foreach my $file (@makefiles)
402 my $make = $makefiles{$file};
403 my $parent = get_parent_makefile
( $file );
405 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
406 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "RC_SRCS" );
407 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
408 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
409 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
413 ################################################################
414 # update the makefile list in configure.ac
416 sub update_makefiles
(@
)
420 foreach my $file (sort @_)
422 next if $file eq "Makefile";
423 my %make = %{$makefiles{$file}};
424 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
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"};
432 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
434 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
435 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
436 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
438 elsif (defined($make{"MODULE"})) # dll or program
440 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile
/$2/;
441 my $dllflags = $make{"EXTRADLLFLAGS"} || "";
442 if (defined $make{"APPMODE"}) { $dllflags .= " " . $make{"APPMODE"}; }
443 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
444 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
445 die "Invalid MODULE in $file" if $name =~ /\./ && $make{"MODULE"} ne $name;
446 if ($file =~ /^programs\//)
448 die "EXTRADLLFLAGS should be defined in $file" unless $dllflags;
449 die "EXTRADLLFLAGS should contain -mconsole or -mwindows in $file" unless $dllflags =~ /-m(console|windows)/;
450 die "Invalid MODULE in $file" unless $name =~ /\./ || $make{"MODULE"} eq "$name.exe";
454 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"} ;
455 die "EXTRADLLFLAGS should not contain -mconsole or -mwindows in $file" if $dllflags =~ /-m(console|windows)/;
456 die "Invalid MODULE in $file" unless $name =~ /\./ || $make{"MODULE"} eq "$name.dll";
458 if (defined $make{"IMPORTLIB"})
460 die "IMPORTLIB not allowed in programs\n" if $file =~ /^programs\//;
461 die "Invalid IMPORTLIB name in $file" if $make{"IMPORTLIB"} =~ /\./;
463 $args = ",enable_win16" if $make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}};
465 elsif ($file =~ /^tools.*\/Makefile
$/)
467 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
468 die "EXTRADLLFLAGS should not be defined in $file" if defined $make{"EXTRADLLFLAGS"};
469 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
470 $args = ",,[test \"x\$enable_tools\" = xno]";
472 push @lines, "WINE_CONFIG_MAKEFILE($dir$args)\n";
475 # update the source variables in all the makefiles
477 foreach my $file (sort @_) { replace_makefile_variables
( $file ); }
479 push @lines, "dnl End of auto-generated output commands\n";
480 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKEFILE', '^dnl End of auto-generated output commands\n$', @lines);
484 my $git_dir = $ENV{GIT_DIR
} || ".git";
485 die "needs to be run from a git checkout" unless -d
$git_dir;
487 my @all_files = split /\0/, `git ls-files -c -z`;
488 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
489 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
491 foreach my $file (sort @makefiles)
493 my %make = parse_makefile
( $file );
494 $makefiles{$file} = \
%make;
497 assign_sources_to_makefiles
( @all_files );
498 update_makefiles
( @makefiles );