Three scripts, subtle modifications to m0n0's mklibs.pl:
used_libs.pl: same as mklibs.pl but smaller
#!/usr/bin/perl
$dir = 'freesbie-fs';
use File::Find;
# check_libs(path)
sub check_libs {
$mode = stat[2];
@libs{`/usr/bin/ldd -f "%p\n" $_ 2>/dev/null`} = () if (-f $_);
}
# walk the directory tree
find(\&check_libs, $dir);
print sort keys %libs;
#alternative: strip leading slash
#print map { substr($_, 1); } sort keys %libs;
blame_libs.pl: which binaries require each library
#!/usr/bin/perl
$dir = 'freesbie-fs';
use File::Find;
# check_libs(path)
sub check_libs {
$mode = stat[2];
if (-f $_) {
foreach $lib (`/usr/bin/ldd -f "%p\n" $_ 2>/dev/null`) {
chop($lib);
$libs{$lib} = [] unless (exists $libs{$lib});
push @{ $libs{$lib} }, $_;
}
}
}
# walk the directory tree
find(\&check_libs, $dir);
foreach $lib (sort keys %libs) {
print "$lib:\n";
foreach (sort @{ $libs{$lib} }) {
print "\t$_\n";
}
print "\n";
}
[/code]
[b]unused_libs.pl[/b]: opposite of used_libs.pl attempting iterative recursion on dependencies.
[code]
#!/usr/bin/perl
$dir = 'freesbie-fs';
use File::Find;
# check_libs(path)
sub check_libs {
$mode = stat[2];
if (-f $_ && ! -l $_) {
$fname = substr($File::Find::name, length($dir));
if (/\.so(\.|$)/) {
$liblist{$fname} = ();
} else {
$nonlist{$fname} = ();
}
foreach $lib (`/usr/bin/ldd -f "%p\n" $_ 2>/dev/null`) {
chop($lib);
$lib = readlink($lib) if (-l $lib);
$libs{$lib}{$fname} = ();
}
}
}
# walk the directory tree
find(\&check_libs, $dir);
$pass = 0;
do {
$pass++;
$pending = 0;
# print "pass $pass\n";
foreach $lib (sort keys %liblist) {
$count = (exists $libs{$lib}) ? scalar keys %{ $libs{$lib} } : 0;
if ($count == 0) {
# print "\t$lib\n";
delete $liblist{$lib};
$unusedlist{$lib} = ();
foreach $lib2 (sort keys %liblist) {
if (exists $libs{$lib2}{$lib}) {
# print "\t\t$lib2\n";
delete $libs{$lib2}{$lib};
$pending++;
}
}
next;
}
}
} while ($pending > 0);
#print "unused libraries:\n\n";
foreach (sort keys %unusedlist) {
print "$_\n";
}
[/code]