2016-07-28 04:08:33 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Find all libraries for the executables
|
|
|
|
#
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Data::Dumper;
|
|
|
|
use File::Copy;
|
|
|
|
use File::Basename;
|
|
|
|
|
|
|
|
my $dest = shift
|
|
|
|
or die "Usage: $0 dest-dir [programs...]\n";
|
|
|
|
|
|
|
|
my %libraries;
|
2016-12-28 17:39:48 +00:00
|
|
|
my %deps;
|
2016-07-28 04:08:33 +00:00
|
|
|
|
|
|
|
for my $file (@ARGV)
|
|
|
|
{
|
|
|
|
my @libs = `ldd "$file"`;
|
|
|
|
for (@libs)
|
|
|
|
{
|
2016-08-06 21:14:07 +00:00
|
|
|
if (/ not found/)
|
|
|
|
{
|
2016-09-10 21:36:36 +00:00
|
|
|
# check to see if it is already installed
|
|
|
|
my ($lib) = /^\s*(.*?)\s*=>/;
|
|
|
|
|
|
|
|
warn "$file: '$lib' $_"
|
|
|
|
unless -r "$dest/$lib";
|
2016-08-06 21:14:07 +00:00
|
|
|
next;
|
|
|
|
}
|
2016-07-28 04:08:33 +00:00
|
|
|
if (/ => ([^ ]+)/)
|
|
|
|
{
|
|
|
|
# Normal library
|
|
|
|
$libraries{$1}++;
|
2016-12-28 17:39:48 +00:00
|
|
|
push @{$deps{$file}}, $1;
|
2016-07-28 04:08:33 +00:00
|
|
|
}
|
|
|
|
elsif (/^\s+([^ ]+) \(/)
|
|
|
|
{
|
|
|
|
# Dynamic linker
|
|
|
|
$libraries{$1}++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 21:36:36 +00:00
|
|
|
#print Dumper(\%libraries);
|
2017-02-28 23:02:10 +00:00
|
|
|
if(0)
|
|
|
|
{
|
2016-12-28 17:39:48 +00:00
|
|
|
print "$_: ", join(" ", @{$deps{$_}}), "\n"
|
|
|
|
for keys %deps;
|
|
|
|
|
|
|
|
print "\n";
|
2017-02-28 23:02:10 +00:00
|
|
|
}
|
2016-12-28 17:39:48 +00:00
|
|
|
|
2016-07-28 04:08:33 +00:00
|
|
|
|
|
|
|
unless( -d $dest )
|
|
|
|
{
|
|
|
|
system("mkdir", "-p", $dest)
|
|
|
|
and die "$dest: Unable to make directory: $!\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $size = 0;
|
|
|
|
|
|
|
|
for my $lib (keys %libraries)
|
|
|
|
{
|
2016-09-28 15:13:27 +00:00
|
|
|
# skip vdso
|
|
|
|
next if $lib =~ /vdso/;
|
|
|
|
|
|
|
|
warn "$lib\n";
|
2016-07-28 04:08:33 +00:00
|
|
|
$size += -s $lib;
|
|
|
|
my $libname = basename $lib;
|
|
|
|
# my $dirname = dirname "$dest/$lib";
|
|
|
|
#
|
|
|
|
# unless( -d $dirname )
|
|
|
|
# {
|
|
|
|
# system("mkdir", "-p", $dirname)
|
|
|
|
# and die "$dirname: Unable to make directory: $!\n";
|
|
|
|
# }
|
|
|
|
|
2016-08-03 01:21:56 +00:00
|
|
|
my $dest_lib = "$dest/$libname";
|
|
|
|
|
|
|
|
copy $lib, $dest_lib
|
2016-07-28 04:08:33 +00:00
|
|
|
or die "$lib: Unable to copy: $!\n";
|
|
|
|
|
|
|
|
# make them executable because otherwise chroot barfs
|
2016-08-03 01:21:56 +00:00
|
|
|
system("chmod", "+x", $dest_lib);
|
2016-07-28 04:08:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print "Total size $size\n";
|
|
|
|
__END__
|