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,
47 my (@makefiles, %makefiles);
53 return "" unless $ret =~ /\//;
58 # update a file if changed
64 open FILE
, ">$file.new" or die "cannot create $file.new";
67 rename "$file.new", "$file";
68 print "$file updated\n";
69 if ($file eq "configure.ac")
72 print "configure updated\n";
76 # replace some lines in a file between two markers
77 sub replace_in_file
($$$@
)
84 open OLD_FILE
, "$file" or die "cannot open $file";
98 $new .= $_ unless $skip;
103 update_file
($file, $new) if $old ne $new;
106 # replace all source variables in a makefile
107 sub replace_makefile_variables
($)
110 my $make = $makefiles{$file};
116 $value = "\\\n\t" . join(" \\\n\t", sort @
{${$make}{"=SOURCES"}}) if defined ${$make}{"=SOURCES"};
118 open OLD_FILE
, $file or die "cannot open $file";
122 if (/^\s*SOURCES\s*=/)
132 $new .= "SOURCES = $value\n" if $value;
140 $new .= "\nSOURCES = $value\n" if $value;
143 update_file
($file, $new) if $old ne $new;
146 # parse the specified makefile and load the variables
147 sub parse_makefile
($)
152 ($make{"=dir"} = $file) =~ s/[^\/]+$//;
154 open MAKE
, $file or die "cannot open $file\n";
160 while (/\\$/) { chop; $_ .= <MAKE
>; chomp; } # merge continued lines
163 if (/\@[A-Z_]+\@/) # config.status substitution variable
165 die "Configure substitution is not allowed in $file" unless $file eq "Makefile.in";
167 if (/^\s*(MODULE|IMPORTLIB|TESTDLL|STATICLIB|PARENTSRC|EXTRADLLFLAGS)\s*=\s*(.*)/)
173 if (/^\s*(SOURCES|PROGRAMS|EXTRA_TARGETS|EXTRA_OBJS|INSTALL_LIB|INSTALL_DEV)\s*=\s*(.*)/)
176 my @list = split(/\s+/, $2);
177 $make{$var} = \
@list;
180 if (/^\s*(TOPSRCDIR|TOPOBJDIR|SRCDIR|VPATH)\s*=\s*(.*)/)
182 die "Variable $1 in $file is obsolete";
189 # read pragma makedep flags from a source file
190 sub get_makedep_flags
($)
195 open FILE
, $file or die "cannot open $file";
196 if ($file =~ /\.sfd$/)
200 next unless /^UComments:\s*\"(.*)\"$/;
201 foreach my $pragma (split /\+AAoA/, $1)
203 next unless $pragma =~ /^#\s*pragma\s+makedep\s+(.*)/;
204 foreach my $flag (split /\s+/, $1)
207 last if $flag eq "font";
216 next unless /^#\s*pragma\s+makedep\s+(.*)/;
217 foreach my $flag (split /\s+/, $1)
219 last if $flag eq "depend";
228 sub get_parent_makefile
($)
231 my %make = %{$makefiles{$file}};
232 my $reldir = $make{"PARENTSRC"} || "";
233 return "" unless $reldir;
234 (my $path = $file) =~ s/\/Makefile\.in$/\
//;
235 while ($reldir =~ /^\.\.\//)
237 $reldir =~ s/^\.\.\///;
238 $path =~ s/[^\/]+\/$//;
240 return "$path$reldir/Makefile.in";
243 # preserve shared source files that are listed in the existing makefile
244 sub preserve_shared_source_files
($$)
246 my ($make, $parent) = @_;
249 return unless defined ${$parent}{"=SOURCES"};
250 foreach my $file (@
{${$parent}{"=SOURCES"}}) { $srcs{$file} = 1; }
251 foreach my $file (@
{${$make}{"=SOURCES"}}) { $srcs{$file} = 0; }
253 foreach my $file (@
{${$make}{SOURCES
}})
255 next unless defined $srcs{$file} && $srcs{$file} == 1;
256 push @
{${$make}{"=SOURCES"}}, $file;
260 # assign source files to their respective makefile
261 sub assign_sources_to_makefiles
(@
)
263 foreach my $file (@_)
265 next if defined $ignored_source_files{$file};
266 next if $file =~ /Makefile\.in$/;
267 my $dir = dirname
( $file );
270 while ($dir && !defined $makefiles{"$dir/Makefile.in"}) { $dir = dirname
( $dir ); }
271 $subdir =~ s/^$dir\/?//;
274 die "no makefile found for $file\n" unless defined $makefiles{"$dir/Makefile.in"};
276 my $make = $makefiles{"$dir/Makefile.in"};
277 my $name = substr( $file, length($dir) + 1 );
281 next if $dir ne "include";
283 elsif ($name =~ /\.idl$/)
285 die "no makedep flags specified in $file" unless $dir eq "include" || get_makedep_flags
($file);
287 elsif ($name =~ /\.spec$/)
289 my $dllflags = ${$make}{"EXTRADLLFLAGS"} || "";
290 next unless defined ${$make}{"TESTDLL"} ||
291 ($dllflags =~ /-Wb,--data-only/) ||
292 ($dllflags =~ /-Wl,--subsystem,native/);
294 elsif ($name =~ /\.nls$/)
296 push @nls_files, $name if $dir eq "nls";
298 elsif ($name =~ /\.xml$/)
300 next unless $dir eq "dlls/winewayland.drv";
302 elsif ($name !~ /\.(c|in|inl|l|m|mc|po|rc|rh|sfd|svg|x|y)$/)
304 next unless $dir eq "loader"; # loader dir contains misc files
306 push @
{${$make}{"=SOURCES"}}, $name;
309 # preserve shared source files from the parent makefile
310 foreach my $file (@makefiles)
312 my $make = $makefiles{$file};
313 my $parent = get_parent_makefile
( $file );
315 preserve_shared_source_files
( $makefiles{$file}, $makefiles{$parent} );
319 ################################################################
320 # update the makefile list in configure.ac
322 sub update_makefiles
(@
)
326 foreach my $file (sort @_)
328 next if $file eq "Makefile.in";
329 my %make = %{$makefiles{$file}};
330 (my $dir = $file) =~ s/^(.*)\/Makefile\.in/$1/;
332 if (defined($make{"TESTDLL"})) # test
334 die "TESTDLL should not be defined in $file" unless $file =~ /\/tests\
/Makefile\.in$/;
335 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
336 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
338 elsif (defined($make{"STATICLIB"}))
340 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
341 die "invalid STATICLIB name" unless $make{"STATICLIB"} =~ /\.a$/;
343 elsif (defined($make{"MODULE"})) # dll or program
345 (my $name = $file) =~ s/^(dlls|programs)\/(.*)\/Makefile\
.in/$2/;
346 my $dllflags = $make{"EXTRADLLFLAGS"} || "";
347 die "invalid MODULE name" if $make{"MODULE"} =~ /\.a$/;
348 die "MODULE should not be defined in $file" unless $file =~ /^(dlls|programs)\//;
349 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
350 if ($file =~ /^programs\//)
352 die "EXTRADLLFLAGS should be defined in $file" unless $dllflags;
353 die "EXTRADLLFLAGS should contain -mconsole or -mwindows in $file" unless $dllflags =~ /-m(console|windows)/;
354 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.exe";
358 die "EXTRADLLFLAGS should not contain -mconsole or -mwindows in $file" if $dllflags =~ /-m(console|windows)/;
359 die "Invalid MODULE in $file" unless ($name =~ /\./ && $make{"MODULE"} eq $name) || $make{"MODULE"} eq "$name.dll";
361 if (defined $make{"IMPORTLIB"})
363 die "IMPORTLIB not allowed in programs\n" if $file =~ /^programs\//;
364 die "Invalid IMPORTLIB name in $file" if $make{"IMPORTLIB"} =~ /\./;
366 $args = ",enable_win16" if $make{"MODULE"} =~ /16$/ || $modules16{$make{"MODULE"}};
368 elsif ($file =~ /^tools.*\/Makefile\
.in$/)
370 die "MODULE should not be defined in $file" if defined $make{"MODULE"};
371 die "STATICLIB should not be defined in $file" if defined $make{"STATICLIB"};
372 die "EXTRADLLFLAGS should not be defined in $file" if defined $make{"EXTRADLLFLAGS"};
373 $args = ",,[test \"x\$enable_tools\" = xno]";
375 push @lines, "WINE_CONFIG_MAKEFILE($dir$args)\n";
378 # update the source variables in all the makefiles
380 foreach my $file (sort @_) { replace_makefile_variables
( $file ); }
382 push @lines, "dnl End of auto-generated output commands\n";
383 replace_in_file
( "configure.ac", '^WINE_CONFIG_MAKEFILE', '^dnl End of auto-generated output commands\n$', @lines);
386 sub update_wine_inf
()
389 push @lines, "[NlsFiles]", sort grep(!/^sort/, @nls_files);
390 push @lines, "\n[SortFiles]", sort grep(/^sort/, @nls_files);
391 push @lines, "\n[WineSourceDirs]\n";
392 replace_in_file
"loader/wine.inf.in", '^\[NlsFiles\]', '^\[WineSourceDirs\]', join( "\n", @lines );
395 my $git_dir = $ENV{GIT_DIR
} || ".git";
396 die "needs to be run from a git checkout" unless -e
$git_dir;
398 my @all_files = split /\0/, `git ls-files -c -z` or die "cannot get files list";
399 map { $ignored_source_files{$_} = 1; } split /\0/, `git ls-files -d -z`;
400 @makefiles = grep /Makefile.in$/, @all_files;
402 foreach my $file (sort @makefiles)
404 my %make = parse_makefile
( $file );
405 $makefiles{$file} = \
%make;
408 assign_sources_to_makefiles
( @all_files );
409 update_makefiles
( @makefiles );