=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.1 retrieving revision 1.8 diff -u -r1.1 -r1.8 --- openbsd/fill_chroot/find_depends 2005/12/21 18:04:06 1.1 +++ openbsd/fill_chroot/find_depends 2008/05/05 19:58:18 1.8 @@ -1,33 +1,29 @@ #!/usr/bin/perl -# $RedRiver$ +# $RedRiver: find_depends,v 1.7 2008/04/22 20:08:41 andrew Exp $ use strict; use warnings; -# find www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{} +my %opts; +my @Files; +foreach (@ARGV) { + if (/^-+(\w+)$/) { + $opts{$1} = 1; + } else { + push @Files, $_; + } +} -#use OpenBSD::PackageInfo; -#use OpenBSD::PackingList; -#use OpenBSD::SharedLibs; -#use Data::Dumper; +Help() if $opts{h} || $opts{help}; +Usage() unless @Files; -#my $dir = '/var/db/pkg'; -#my $pkg = 'p5-DBD-mysql-3.0002'; -#my $pkg = 'p5-DBD-mysql'; +my %libs; +foreach my $file (@Files) { + my $l = find_libs($file); - -#my $file = shift || '/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/DBD/mysql/mysql.so'; - - -die unless @ARGV; - -my %libs; -foreach my $file (@ARGV) { - my $libs = find_libs($file); - #print Dumper $libs; - foreach (keys %{ $libs }) { - $libs{ $_ } = $libs->{$_}; + foreach (keys %{ $l }) { + $libs{$_} = $l->{$_}; } } @@ -37,56 +33,41 @@ exit; -#OpenBSD::SharedLibs::add_system_libs('/'); +sub Usage +{ + print "Usage: $0 [-v] file [file2 [file3 [...]]]\n"; + exit; +} -#print installed_packages(); -#print installed_name($pkg); -#print info_names(); -#exit; +sub Help +{ + print <from_installation($pkg) || die $!; +Usage: + $0 [-v] file [file2 [file3 [...]]] -#print Dumper $plist->{wantlib}; +Example: + find /var/www/ -name *.so* | xargs find_depends | \\ + sort -u | xargs -I {} cp {} /var/www{} +EOL -#print Dumper $OpenBSD::SharedLibs::registered_libs; + exit; +} -#foreach (@{ $plist->{wantlib} }) { -# print Dumper $_->{name}, find_library($_->{name}); -#} - -#sub find_library -#{ -# my $spec = shift; -# my @r; -# OpenBSD::SharedLibs::add_system_libs('/'); -# -# my $lib = '/usr'; -# @r = OpenBSD::SharedLibs::lookup_libspec('/usr', $spec); -# unless (@r) { -# $lib = '/usr/X11R6'; -# @r = OpenBSD::SharedLibs::lookup_libspec('/usr/X11R6', $spec); -# } -# unless (@r) { -# for my $pkg (installed_packages()) { -# OpenBSD::SharedLibs::add_package_libs($pkg, 1); -# } -# $lib = '/usr/local'; -# @r = OpenBSD::SharedLibs::lookup_libspec('/usr/local', $spec); -# } -# return $lib, @r; -#} - sub find_libs { my $file = shift; my $ld = shift || get_ldconfig(); my $locs = shift || {}; - print STDERR "Finding libs for '$file'\n"; + print STDERR "Finding libs for '$file'\n" if $opts{v}; my @libs = search_file($file); foreach (@libs) { - my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/; + my ($name, $maj, $min) = $_ =~ /lib([^\/]+)\.so\.(\d+)\.(\d+)$/; + next if ! $name; my $spec = 'l' . $name . '.' . $maj . '.' . $min; if (exists $ld->{$spec}) { @@ -97,7 +78,7 @@ $locs = find_libs($locs->{$spec}, $ld, $locs); } else { - warn "Couldn't find location for lib '$_'"; + warn "Couldn't find location for lib '$_' (file '$file')"; } } @@ -108,18 +89,14 @@ { my $file = shift; my @libs; - - open my $libs, '<', $file or die; - local $/ = chr(0); + + open my $libs, '-|', '/usr/bin/ldd', $file or die "Couldn't open ldd '$file': $!"; while (<$libs>) { - if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) { - my ($path, $name, $major, $minor) = ($1, $2, $3, $4); - my $spec="$name.$major.$minor"; - if (defined $path && $path ne '/usr/local/lib') { - $spec="$path/$spec"; - } - push @libs, $spec; - } + next if length($_) < 56; + chomp; + my $spec = substr $_, 56; + next if $spec !~ m{^/}xms; + push @libs, $spec; } close $libs; @@ -131,7 +108,8 @@ my $ldconfig = '/sbin/ldconfig'; my (%paths, %libs); - open my $ld, '-|', $ldconfig, '-r' or die; + open my $ld, '-|', $ldconfig, '-r' + or die "Couldn't open pipe to ldconfig: $!"; while (<$ld>) { chomp; if (/search directories:\s+(.*)/) {