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 %ignored_source_files = (
42 "dlls/wineps.drv/afm2c.c" => 1,
43 "dlls/wineps.drv/mkagl.c" => 1,
44 "tools/makedep.c" => 1,
65 my (@makefiles, %makefiles);
71 return "" unless $ret =~ /\//;
76 # update a file if changed
82 open FILE
, ">$file.new" or die "cannot create $file.new";
85 rename "$file.new", "$file";
86 print "$file updated\n";
87 if ($file eq "configure.ac")
90 print "configure updated\n";
94 # replace some lines in a file between two markers
95 sub replace_in_file
($$$@
)
102 open OLD_FILE
, "$file" or die "cannot open $file";
116 $new .= $_ unless $skip;
121 update_file
($file, $new) if $old ne $new;
124 # replace all source variables in a makefile
125 sub replace_makefile_variables
($)
128 my $make = $makefiles{$file};
129 my $source_vars_regexp = join "|", @source_vars;
135 open OLD_FILE
, $file or die "cannot open $file";
139 if (/^\s*($source_vars_regexp)(\s*)=/)
141 # try to preserve formatting
147 if (defined ${$make}{"=$var"})
149 @values = @
{${$make}{"=$var"}};
150 ${$make}{$var} = \
@values;
154 undef ${$make}{$var};
156 my $multiline = /\\$/ || (@values > 1);
172 $new_str = "$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
177 $new_str = "$var$spaces= @values\n";
181 foreach my $val (@values)
183 die "$file: duplicate file $val" if defined $files{$val};
190 # if we are using SOURCES, ignore the other variables
191 unless ($replaced{"SOURCES"})
193 foreach my $var (@source_vars)
195 next if defined $replaced{$var};
196 next if $var eq "SOURCES";
197 next unless defined ${$make}{"=$var"};
198 my @values = @
{${$make}{"=$var"}};
200 $new .= "\n$var = \\\n\t" . join(" \\\n\t", sort @values) . "\n";
204 update_file
($file, $new) if $old ne $new;
207 # parse the specified makefile and load the variables
208 sub parse_makefile
($)
213 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
215 open MAKE
, $file or die "cannot open $file\n";
221 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
224 if (/\@[A-Z_]+\@/) # config.status substitution variable
226 die "Configure substitution is not allowed in $file" unless $file eq "Makefile.in";
228 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|STATICLIB|PARENTSRC|EXTRADLLFLAGS)\s*=\s*(.*)/)
234 my $source_vars_regexp = join "|", @source_vars;
235 if (/^\s*($source_vars_regexp|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
238 my @list = split(/\s+/, $2);
239 $make{$var} = \
@list;
242 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
244 die "Variable $1 in $file is obsolete";
251 # read pragma makedep flags from a source file
252 sub get_makedep_flags
($)
257 open FILE
, $file or die "cannot open $file";
258 if ($file =~ /\.sfd$/)
262 next unless /^UComments:\s*\"(.*)\"$/;
263 foreach my $pragma (split /\+AAoA/, $1)
265 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
266 foreach my $flag (split /\s+/, $1)
269 last if $flag eq "font";
278 next unless /^#\s*pragma\s+makedep\s+(.*)/;
279 foreach my $flag (split /\s+/, $1)
281 last if $flag eq "depend";
290 sub get_parent_makefile
($)
293 my %make = %{$makefiles{$file}};
294 my $reldir = $make{"PARENTSRC"} || "";
295 return "" unless $reldir;
296 (my $path = $file) =~ s/\/Makefile\.in$/\
//;
297 while ($reldir =~ /^\.\.\//)
299 $reldir =~ s/^\.\.\///;
300 $path =~ s/[^\/]+\/$//;
302 return "$path$reldir/Makefile.in";
305 # preserve shared source files that are listed in the existing makefile
306 sub preserve_shared_source_files
($$$)
308 my ($make, $parent, $var) = @_;
311 return unless defined ${$parent}{"=$var"};
312 foreach my $file (@
{${$parent}{"=$var"}}) { $srcs{$file} = 1; }
313 foreach my $file (@
{${$make}{"=$var"}}) { $srcs{$file} = 0; }
315 foreach my $file (@
{${$make}{$var}})
317 next unless defined $srcs{$file} && $srcs{$file} == 1;
318 push @
{${$make}{"=$var"}}, $file;
322 # assign source files to their respective makefile
323 sub assign_sources_to_makefiles
(@
)
325 foreach my $file (@_)
327 next if defined $ignored_source_files{$file};
328 next if $file =~ /Makefile\.in$/;
329 my $dir = dirname
( $file );
332 while ($dir && !defined $makefiles{"$dir/Makefile.in"}) { $dir = dirname
( $dir ); }
333 $subdir =~ s/^$dir\/?//;
336 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile.in"};
338 my $make = $makefiles{"$dir/Makefile.in"};
339 my $name = substr( $file, length($dir) + 1 );
341 if ($name =~ /\.m$/) { push @
{${$make}{"=OBJC_SRCS"}}, $name; }
342 elsif ($name =~ /\.l$/) { push @
{${$make}{"=LEX_SRCS"}}, $name; }
343 elsif ($name =~ /\.y$/) { push @
{${$make}{"=BISON_SRCS"}}, $name; }
344 elsif ($name =~ /\.svg$/) { push @
{${$make}{"=SVG_SRCS"}}, $name; }
345 elsif ($name =~ /\.sfd$/)
347 push @
{${$make}{"=FONT_SRCS"}}, $name;
349 elsif ($name =~ /\.c$/)
351 push @
{${$make}{"=C_SRCS"}}, $name;
353 elsif ($name =~ /\.h$/ || $name =~ /\.rh$/ || $name =~ /\.inl$/ || $name =~ /\.x$/)
355 next if $dir ne "include";
357 elsif ($name =~ /\.rc$/)
359 push @
{${$make}{"=RC_SRCS"}}, $name;
361 elsif ($name =~ /\.mc$/)
363 push @
{${$make}{"=MC_SRCS"}}, $name;
365 elsif ($name =~ /\.po$/)
367 push @
{${$make}{"=PO_SRCS"}}, $name;
369 elsif ($name =~ /\.idl$/)
371 die "no makedep flags specified in $file" unless $dir eq "include" || get_makedep_flags
($file);
372 push @
{${$make}{"=IDL_SRCS"}}, $name;
374 elsif ($name =~ /\.man\.in$/)
376 push @
{${$make}{"=MANPAGES"}}, $name;
378 elsif ($name =~ /\.in$/)
380 push @
{${$make}{"=IN_SRCS"}}, $name;
382 elsif ($name =~ /\.spec$/)
384 next unless defined ${$make}{"TESTDLL"};
386 elsif ($name =~ /\.nls$/)
388 push @nls_files, $name if $dir eq "nls";
390 elsif ($name =~ /\.xml$/ && $dir eq "dlls/winewayland.drv")
392 push @
{${$make}{"=SOURCES"}}, $name;
395 elsif ($dir ne "loader") # loader dir contains misc files
399 push @
{${$make}{"=SOURCES"}}, $name;
402 # preserve shared source files from the parent makefile
403 foreach my $file (@makefiles)
405 my $make = $makefiles{$file};
406 my $parent = get_parent_makefile
( $file );
408 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "C_SRCS" );
409 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "RC_SRCS" );
410 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "IDL_SRCS" );
411 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "LEX_SRCS" );
412 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent}, "BISON_SRCS" );
416 ################################################################
417 # update the makefile list in configure.ac
419 sub update_makefiles
(@
)
423 foreach my $file (sort @_)
425 next if $file eq "Makefile.in";
426 my %make = %{$makefiles{$file}};
427 (my $dir = $file) =~ s/^(.*)\/Makefile\.in/$1/;
429 if (defined($make{"TESTDLL"})) # test
431 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\
/Makefile\.in$/;
432 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
433 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
435 elsif (defined($make{"STATICLIB"}))
437 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
438 die "invalid STATICLIB name" unless $make{"STATICLIB"} =~ /\.a$/;
440 elsif (defined($make{"MODULE"})) # dll or program
442 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile\
.in/$2/;
443 my $dllflags = $make{"EXTRADLLFLAGS"} || "";
444 die "invalid MODULE name" if $make{"MODULE"} =~ /\.a$/;
445 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
446 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
447 if ($file =~ /^programs\//)
449 die "EXTRADLLFLAGS should be defined in $file" unless $dllflags;
450 die "EXTRADLLFLAGS should contain -mconsole or -mwindows in $file" unless $dllflags =~ /-m(console|windows)/;
451 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.exe";
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) || $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\
.in$/)
467 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
468 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
469 die "EXTRADLLFLAGS should not be defined in $file" if defined $make{"EXTRADLLFLAGS"};
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);
483 sub update_wine_inf
()
486 push @lines, "[NlsFiles]", sort grep(!/^sort/, @nls_files);
487 push @lines, "\n[SortFiles]", sort grep(/^sort/, @nls_files);
488 push @lines, "\n[WineSourceDirs]\n";
489 replace_in_file
"loader/wine.inf.in", '^\[NlsFiles\]', '^\[WineSourceDirs\]', join( "\n", @lines );
492 my $git_dir = $ENV{GIT_DIR
} || ".git";
493 die "needs to be run from a git checkout" unless -e
$git_dir;
495 my @all_files = split /\0/, `git ls-files -c -z` or die "cannot get files list";
496 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
497 @makefiles = grep /Makefile.in$/, @all_files;
499 foreach my $file (sort @makefiles)
501 my %make = parse_makefile
( $file );
502 $makefiles{$file} = \
%make;
505 assign_sources_to_makefiles
( @all_files );
506 update_makefiles
( @makefiles );