version 1.5, 2005/12/21 19:14:12 |
version 1.11, 2008/09/16 23:28:53 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: find_depends,v 1.4 2005/12/21 18:37:38 andrew Exp $ |
# $RedRiver: find_depends,v 1.10 2008/09/16 22:15:03 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
|
|
|
|
|
|
my @libs = search_file($file); |
my @libs = search_file($file); |
foreach (@libs) { |
foreach (@libs) { |
my ($name, $maj, $min) = $_ =~ /^([^\.]+)\.so\.(\d+)\.(\d+)$/; |
my $spec; |
my $spec = 'l' . $name . '.' . $maj . '.' . $min; |
|
|
if (/\/ld\.so$/) { |
|
$spec = $_; |
|
} |
|
else { |
|
if ( my ($name, $maj, $min) = $_ =~ /lib([^\/]+)\.so\.(\d+)\.(\d+)$/ ) { |
|
$spec = 'l' . $name . '.' . $maj . '.' . $min; |
|
} |
|
} |
|
|
if (exists $ld->{$spec}) { |
next if ! $spec; |
next if exists $locs->{$spec}; |
next if exists $locs->{$spec}; |
|
|
$locs->{$spec} = $ld->{$spec}; |
print " Found spec '$spec'\n" if $opts{v}; |
|
|
$locs = find_libs($locs->{$spec}, $ld, $locs); |
if (-e $spec) { |
|
$locs->{$spec} = $spec; |
} else { |
|
warn "Couldn't find location for lib '$_'"; |
|
} |
} |
|
else { |
|
$locs->{$spec} = $ld->{$spec}; |
|
} |
|
|
|
if (! $locs->{$spec}) { |
|
print STDERR "Couldn't find location for '$_' (file '$file')\n"; |
|
next; |
|
} |
|
|
|
$locs = find_libs($locs->{$spec}, $ld, $locs); |
|
|
} |
} |
|
|
return $locs; |
return $locs; |
|
|
{ |
{ |
my $file = shift; |
my $file = shift; |
my @libs; |
my @libs; |
|
|
open my $libs, '<', $file or die "Couldn't open lib '$file': $!"; |
open my $libs, '-|', '/usr/bin/ldd', $file or die "Couldn't open ldd '$file': $!"; |
local $/ = chr(0); |
|
while (<$libs>) { |
while (<$libs>) { |
if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) { |
chomp; |
my ($path, $name, $major, $minor) = ($1, $2, $3, $4); |
my ($spec) = (split(/\s+/, $_))[7]; |
my $spec="$name.$major.$minor"; |
next if ! $spec; |
if (defined $path && $path ne '/usr/local/lib') { |
next if $spec !~ m{^/}xms; |
$spec="$path/$spec"; |
push @libs, $spec; |
} |
|
push @libs, $spec; |
|
} |
|
} |
} |
close $libs; |
close $libs; |
|
|