version 1.2, 2005/12/21 18:16:03 |
version 1.4, 2005/12/21 18:37:38 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: find_depends,v 1.1 2005/12/21 18:04:06 andrew Exp $ |
# $RedRiver: find_depends,v 1.3 2005/12/21 18:22:32 andrew Exp $ |
use strict; |
use strict; |
use warnings; |
use warnings; |
|
|
# find /home/andrew/www/ -name *.so* | xargs find_depends | sort -u | xargs -I {} cp {} /home/andrew/www{} |
use Data::Dumper; |
|
|
die unless @ARGV; |
my %opts; |
|
my @Files; |
|
|
|
foreach (@ARGV) { |
|
if (/^-+(\w+)$/) { |
|
$opts{$1} = 1; |
|
} else { |
|
push @Files, $_; |
|
} |
|
} |
|
|
|
Help() if $opts{h} || $opts{help}; |
|
Usage() unless @Files; |
|
|
my %libs; |
my %libs; |
|
|
foreach my $file (@ARGV) { |
foreach my $file (@Files) { |
my $l = find_libs($file); |
my $l = find_libs($file); |
|
|
foreach (keys %{ $l }) { |
foreach (keys %{ $l }) { |
|
|
|
|
exit; |
exit; |
|
|
|
sub Usage |
|
{ |
|
print "Usage: $0 [-v] file [file2 [file3 [...]]]\n"; |
|
exit; |
|
} |
|
|
|
sub Help |
|
{ |
|
print <<EOL; |
|
Hopefully finds all libraries that are required by an executable |
|
or shared library. |
|
|
|
Usage: |
|
$0 [-v] file [file2 [file3 [...]]] |
|
|
|
Example: |
|
find /var/www/ -name *.so* | xargs find_depends | \\ |
|
sort -u | xargs -I {} cp {} /var/www{} |
|
EOL |
|
|
|
exit; |
|
} |
|
|
sub find_libs |
sub find_libs |
{ |
{ |
my $file = shift; |
my $file = shift; |
my $ld = shift || get_ldconfig(); |
my $ld = shift || get_ldconfig(); |
my $locs = shift || {}; |
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); |
my @libs = search_file($file); |
foreach (@libs) { |
foreach (@libs) { |
|
|
my $file = shift; |
my $file = shift; |
my @libs; |
my @libs; |
|
|
open my $libs, '<', $file or die; |
open my $libs, '<', $file or die "Couldn't open lib '$file': $!"; |
local $/ = chr(0); |
local $/ = chr(0); |
while (<$libs>) { |
while (<$libs>) { |
if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) { |
if (m|^(/[^\w\/]+/)?lib(\S+)\.(\d+)\.(\d+)|) { |
|
|
my $ldconfig = '/sbin/ldconfig'; |
my $ldconfig = '/sbin/ldconfig'; |
my (%paths, %libs); |
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>) { |
while (<$ld>) { |
chomp; |
chomp; |
if (/search directories:\s+(.*)/) { |
if (/search directories:\s+(.*)/) { |