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,
45 "wine/svcctl.idl" => 1,
48 my %ignored_source_files = (
49 "dlls/wineps.drv/afm2c.c" => 1,
50 "dlls/wineps.drv/mkagl.c" => 1,
51 "include/config.h.in" => 1,
52 "include/stamp-h.in" => 1,
53 "programs/winetest/dist.rc" => 1,
54 "tools/makedep.c" => 1,
75 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 ($name =~ /\.nls$/)
394 push @nls_files, $name if $dir eq "nls";
396 elsif ($dir ne "loader") # loader dir contains misc files
400 push @
{${$make}{"=SOURCES"}}, $name;
403 # preserve shared source files from the parent makefile
404 foreach my $file (@makefiles)
406 my $make = $makefiles{$file};
407 my $parent = get_parent_makefile
( $file );
409 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
410 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "RC_SRCS" );
411 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
412 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
413 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
417 ################################################################
418 # update the makefile list in configure.ac
420 sub update_makefiles
(@
)
424 foreach my $file (sort @_)
426 next if $file eq "Makefile";
427 my %make = %{$makefiles{$file}};
428 (my $dir = $file) =~ s/^(.*)\/Makefile/$1/;
430 if (defined($make{"TESTDLL"})) # test
432 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\
/Makefile$/;
433 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
434 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
436 elsif (defined($make{"MODULE"}) && $make{"MODULE"} =~ /\.a$/) # import lib
438 die "MODULE should not be defined as static lib in $file" unless $file =~ /^dlls\//;
439 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
440 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
442 elsif (defined($make{"MODULE"})) # dll or program
444 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile
/$2/;
445 my $dllflags = $make{"EXTRADLLFLAGS"} || "";
446 if (defined $make{"APPMODE"}) { $dllflags .= " " . $make{"APPMODE"}; }
447 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
448 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
449 if ($file =~ /^programs\//)
451 die "EXTRADLLFLAGS should be defined in $file" unless $dllflags;
452 die "EXTRADLLFLAGS should contain -mconsole or -mwindows in $file" unless $dllflags =~ /-m(console|windows)/;
453 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.exe";
457 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"} ;
458 die "EXTRADLLFLAGS should not contain -mconsole or -mwindows in $file" if $dllflags =~ /-m(console|windows)/;
459 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.dll";
461 if (defined $make{"IMPORTLIB"})
463 die "IMPORTLIB not allowed in programs\n" if $file =~ /^programs\//;
464 die "Invalid IMPORTLIB name in $file" if $make{"IMPORTLIB"} =~ /\./;
466 $args = ",enable_win16" if $make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}};
468 elsif ($file =~ /^tools.*\/Makefile
$/)
470 die "APPMODE should not be defined in $file" if defined $make{"APPMODE"};
471 die "EXTRADLLFLAGS should not be defined in $file" if defined $make{"EXTRADLLFLAGS"};
472 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
473 $args = ",,[test \"x\$enable_tools\" = xno]";
475 push @lines, "WINE_CONFIG_MAKEFILE($dir$args)\n";
478 # update the source variables in all the makefiles
480 foreach my $file (sort @_) { replace_makefile_variables
( $file ); }
482 push @lines, "dnl End of auto-generated output commands\n";
483 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKEFILE', '^dnl End of auto-generated output commands\n$', @lines);
486 sub update_wine_inf
()
489 push @lines, "[NlsFiles]", sort grep(!/^sort/, @nls_files);
490 push @lines, "\n[SortFiles]", sort grep(/^sort/, @nls_files);
491 push @lines, "\n[WineSourceDirs]\n";
492 replace_in_file
"loader/wine.inf.in", '^\[NlsFiles\]', '^\[WineSourceDirs\]', join( "\n", @lines );
495 my $git_dir = $ENV{GIT_DIR
} || ".git";
496 die "needs to be run from a git checkout" unless -e
$git_dir;
498 my @all_files = split /\0/, `git ls-files -c -z`;
499 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
500 @makefiles = map { (my $ret = $_) =~ s/\.in$//; $ret; } grep /Makefile.in$/, @all_files;
502 foreach my $file (sort @makefiles)
504 my %make = parse_makefile
( $file );
505 $makefiles{$file} = \
%make;
508 assign_sources_to_makefiles
( @all_files );
509 update_makefiles
( @makefiles );