=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.3 retrieving revision 1.8 diff -u -r1.3 -r1.8 --- openbsd/fill_chroot/find_depends 2005/12/21 18:22:32 1.3 +++ openbsd/fill_chroot/find_depends 2008/05/05 19:58:18 1.8 @@ -1,23 +1,21 @@ #!/usr/bin/perl -# $RedRiver: find_depends,v 1.2 2005/12/21 18:16:03 andrew Exp $ +# $RedRiver: find_depends,v 1.7 2008/04/22 20:08:41 andrew Exp $ use strict; use warnings; -# find /home/andrew/www/ -name *.so* | xargs find_depends \ -# | sort -u | xargs -I {} cp {} /home/andrew/www{} - -my @Files; my %opts; +my @Files; foreach (@ARGV) { - if (/^-(\w+)$/) { + if (/^-+(\w+)$/) { $opts{$1} = 1; } else { push @Files, $_; } } -die unless @Files; +Help() if $opts{h} || $opts{help}; +Usage() unless @Files; my %libs; @@ -35,17 +33,41 @@ exit; +sub Usage +{ + print "Usage: $0 [-v] file [file2 [file3 [...]]]\n"; + exit; +} + +sub Help +{ + print <{$spec}) { @@ -56,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')"; } } @@ -67,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; @@ -90,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+(.*)/) {