#!/usr/bin/perl -w # # Update the dll dependencies in the dlls main Makefile.in. # # Copyright 2001 Alexandre Julliard # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # use strict; my %directories = (); my %testdirs = (); my %importlibs = (); my %static_implibs = (); my %staticlib_dirs = (); my %altnames = (); # list of special dlls that can be switched on or off by configure my %special_dlls = ( "glu32" => "GLU32FILES", "glut32" => "GLUT32FILES", "opengl32" => "OPENGLFILES", "wined3d" => "OPENGLFILES", "winex11.drv" => "XFILES" ); sub needs_symlink($) { (my $mod = $_[0]) =~ s/\.dll$//; return $mod ne $directories{$_[0]}; } sub update_file($) { my $file = shift; if (!system "cmp $file $file.new >/dev/null") { unlink "$file.new"; print "$file is unchanged\n"; } else { rename "$file.new", "$file"; print "$file updated\n"; if (-x "./config.status" && $file =~ /(.*Makefile)\.in$/) { system "./config.status", $1; } } } # if we are inside the dlls dir, go up one level if (! -f "configure.ac" && -f "../configure.ac") { chdir(".."); } my @args = @ARGV; if (!@args) { @args = map { s/^(.*)\.in/$1/; $_; } split(/\s/,`find dlls -name Makefile.in -print`); } foreach my $i (@args) { if ($i =~ /dlls\/(.*)\/tests\/Makefile/) { $testdirs{$1} = "$1/tests"; next; } open MAKE, "$i.in" or die "cannot open $i.in\n"; my $module = undef; my $dir = $i; while () { chop; # EPP hack to disable this DLL... the MKDLL_SKIP comment must appear # at the very top of the Makefile.in last if (/^\#\s*MKDLL_SKIP/); if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/) { $module = $1; if ($module =~ /^lib.*\.a$/) { ($staticlib_dirs{$module} = $i) =~ s/^dlls\/(.*)\/[^\/]+$/$1/; die "invalid module $module in dir $staticlib_dirs{$module}\n" if "lib$staticlib_dirs{$module}.a" ne $module; } else { ($directories{$module} = $i) =~ s/^dlls\/(.*)\/[^\/]+$/$1/; } next; } if (/^IMPORTLIB\s*=\s*([a-zA-Z0-9_.]+)\.\$\(IMPLIBEXT\)/) { $importlibs{$module} = $1; next; } if (/^IMPLIB_SRCS\s*=/) { $static_implibs{$module} = 1; next; } if (/^SPEC_SRCS16\s*=\s*(.*)/) { my $specs = $1; while ($specs =~ /\s*(.*)\\$/) { $specs = $1 . ; } my @list = split(/\s+/,$specs); @list = map { $_ =~ s/\.spec$//; $_ .= ".dll" unless $_ =~ /\./; $_; } @list; $altnames{$module} = \@list; next; } } close MAKE; } open NEWMAKE,">dlls/Makefile.in.new" or die "cannot create dlls/Makefile.in.new"; ################################################################ # makefile header print NEWMAKE < directory rules print NEWMAKE "# Map symlink name to the corresponding library\n\n"; foreach my $mod (sort keys %directories) { next unless needs_symlink($mod); printf NEWMAKE "%s.so: %s/%s.so\n", $mod, $directories{$mod}, $mod; printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s.so \$@\n\n", $directories{$mod}, $mod; } print NEWMAKE "# Placeholders for 16-bit libraries\n\n"; foreach my $mod (sort keys %directories) { next unless defined $altnames{$mod}; printf NEWMAKE "%s:\n", join(" ", map { $_ . "16"; } sort @{$altnames{$mod}}); printf NEWMAKE "\techo \"%s\" >\$\@\n\n", $mod; } ################################################################ # output the import libraries rules print NEWMAKE "# Import libraries\n\n"; print NEWMAKE "STATIC_IMPLIBEXT = \$(IMPLIBEXT:def=def.a)\n\n"; my @lib_symlinks = (); foreach my $mod (sort keys %importlibs) { my $dir = $directories{$mod}; my $lib = $importlibs{$mod}; if ($lib ne "lib" . $dir) { push @lib_symlinks, $mod; } } print NEWMAKE "IMPORT_SYMLINKS ="; foreach my $mod (sort @lib_symlinks) { printf NEWMAKE " \\\n\t%s.\$(IMPLIBEXT)", $importlibs{$mod}; } print NEWMAKE "\n\nIMPORT_LIBS = \\\n\t\$(IMPORT_SYMLINKS)"; foreach my $mod (sort keys %staticlib_dirs) { printf NEWMAKE " \\\n\t%s/%s", $staticlib_dirs{$mod}, $mod; } foreach my $mod (sort keys %importlibs) { my $dir = $directories{$mod}; my $def = $mod; $def =~ s/\.(dll|drv)$//; printf NEWMAKE " \\\n\t%s/lib%s.\$(IMPLIBEXT)", $dir, $def; printf NEWMAKE " \\\n\t%s/lib%s.\$(STATIC_IMPLIBEXT)", $dir, $def if $static_implibs{$mod}; } print NEWMAKE "\n\n"; print NEWMAKE "implib: \$(IMPORT_LIBS)\n\n"; foreach my $mod (sort keys %importlibs) { my $dir = $directories{$mod}; my $lib = $importlibs{$mod}; my $spec = $mod; $spec =~ s/\.dll$//; printf NEWMAKE "%s/%s.\$(IMPLIBEXT): %s/%s.spec \$(WINEBUILD)\n", $dir, $lib, $dir, $spec; printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(IMPLIBEXT)\n\n", $dir, $lib; next unless $static_implibs{$mod}; printf NEWMAKE "%s/%s.\$(STATIC_IMPLIBEXT): dummy\n", $dir, $lib, $dir, $spec; printf NEWMAKE "\t\@cd %s && \$(MAKE) %s.\$(STATIC_IMPLIBEXT)\n\n", $dir, $lib; } foreach my $mod (sort @lib_symlinks) { my $dir = $directories{$mod}; my $lib = $importlibs{$mod} . ".\$(IMPLIBEXT)"; printf NEWMAKE "%s: %s/%s\n", $lib, $dir, $lib; printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s \$@\n\n", $dir, $lib; } print NEWMAKE <dlls/.gitignore.new" or die "cannot create dlls/.gitignore.new"; print GITIGNORE "# Automatically generated by make_dlls; DO NOT EDIT!!\n"; my @ignores = ( "/Makedll.rules", "/Makeimplib.rules", "/Maketest.rules", "*/tests/testlist.c", "*/tests/*.ok", ); foreach my $mod (sort @lib_symlinks) { push @ignores, "/$importlibs{$mod}.def"; } foreach my $mod (sort keys %directories) { next unless defined $altnames{$mod}; push @ignores, map { "/" . $_ . "16"; } @{$altnames{$mod}}; } foreach my $mod (sort keys %importlibs) { my $dir = $directories{$mod}; my $def = $mod; $def =~ s/\.(dll|drv)$//; push @ignores, "$dir/lib$def.def"; } print GITIGNORE join("\n", sort @ignores) . "\n"; close GITIGNORE; update_file("dlls/.gitignore");