=================================================================== RCS file: /cvs/openbsd/fill_chroot/find_depends,v retrieving revision 1.2 retrieving revision 1.10 diff -u -r1.2 -r1.10 --- openbsd/fill_chroot/find_depends 2005/12/21 18:16:03 1.2 +++ openbsd/fill_chroot/find_depends 2008/09/16 23:15:03 1.10 @@ -1,15 +1,25 @@ #!/usr/bin/perl -# $RedRiver: find_depends,v 1.1 2005/12/21 18:04:06 andrew Exp $ +# $RedRiver: find_depends,v 1.9 2008/05/05 19:02:57 andrew Exp $ use strict; use warnings; -# find /home/andrew/www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{} +my %opts; +my @Files; -die unless @ARGV; +foreach (@ARGV) { + if (/^-+(\w+)$/) { + $opts{$1} = 1; + } else { + push @Files, $_; + } +} +Help() if $opts{h} || $opts{help}; +Usage() unless @Files; + my %libs; -foreach my $file (@ARGV) { +foreach my $file (@Files) { my $l = find_libs($file); foreach (keys %{ $l }) { @@ -23,28 +33,52 @@ exit; +sub Usage +{ + print "Usage: $0 [-v] file [file2 [file3 [...]]]\n"; + exit; +} + +sub Help +{ + print <{$spec}) { next if exists $locs->{$spec}; $locs->{$spec} = $ld->{$spec}; - - $locs = find_libs($locs->{$spec}, $ld, $locs); + $locs = find_libs($ld->{$spec}, $ld, $locs); } else { - warn "Couldn't find location for lib '$_'"; + warn "Couldn't find location for lib '$_' (file '$file')"; } } @@ -55,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; - } + chomp; + my ($spec) = (split(/\s+/, $_))[7]; + next if ! $spec; + next if $spec !~ m{^/}xms; + push @libs, $spec; } close $libs; @@ -78,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+(.*)/) {