forked from linuxboot/heads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate-lib
executable file
·85 lines (70 loc) · 1.37 KB
/
populate-lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/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;
my %deps;
for my $file (@ARGV)
{
my @libs = `ldd "$file"`;
for (@libs)
{
if (/ not found/)
{
# check to see if it is already installed
my ($lib) = /^\s*(.*?)\s*=>/;
warn "$file: '$lib' $_"
unless -r "$dest/$lib";
next;
}
if (/ => ([^ ]+)/)
{
# Normal library
$libraries{$1}++;
push @{$deps{$file}}, $1;
}
elsif (/^\s+([^ ]+) \(/)
{
# Dynamic linker
$libraries{$1}++;
}
}
}
#print Dumper(\%libraries);
print "$_: ", join(" ", @{$deps{$_}}), "\n"
for keys %deps;
print "\n";
unless( -d $dest )
{
system("mkdir", "-p", $dest)
and die "$dest: Unable to make directory: $!\n";
}
my $size = 0;
for my $lib (keys %libraries)
{
# skip vdso
next if $lib =~ /vdso/;
warn "$lib\n";
$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";
# }
my $dest_lib = "$dest/$libname";
copy $lib, $dest_lib
or die "$lib: Unable to copy: $!\n";
# make them executable because otherwise chroot barfs
system("chmod", "+x", $dest_lib);
}
print "Total size $size\n";
__END__