-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundlelibs.pl
executable file
·45 lines (38 loc) · 1.46 KB
/
bundlelibs.pl
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
#!/usr/bin/perl
# Script for OS X to copy all non-core library dependencies into the bundle, and fixup the lib naming
# Run after the executable is already in the bundle.
if( $#ARGV <= 0 ) {
die( "Usage: bundlelibs.pl <target-binary> <target-lib-path>\n" );
}
my $BINARY=shift();
my $TARGETDIR=shift();
my $OTOOL="otool";
my $NTOOL="install_name_tool";
mkdir $TARGETDIR;
my %done=();
my @worklist = ($BINARY);
while( $#worklist >= 0 ) {
my $target = shift @worklist;
$done{$target} = 2;
open FH, "$OTOOL -L $target|" || die "Unable to run otool";
$skip = <FH>;
while(<FH>){
$lib = $_;
$lib =~ s/^\s+([^\s]+)\s.*$/$1/s;
if( $lib !~ /^\/System\/Library/ && $lib !~ /^\/usr\/lib/ && $lib !~ /^\@executable_path\// ) {
$libname = $lib;
$libname =~ s#^.*/##;
$targetpath = "$TARGETDIR/$libname";
$libid = "\@executable_path/../Frameworks/$libname";
if( !$done{$libname} ) {
$done{$libname} = 1;
push @worklist, $targetpath;
system( ("cp", $lib, $targetpath) ) == 0 || die "Failed to copy $lib to $targetpath";
system( ($NTOOL, "-id", $libid, $targetpath) ) == 0 || die "Failed to set $lib ID to $libid";
print "Copied $lib => $targetpath\n";
}
system( ($NTOOL, "-change", $lib, $libid, $target ) ) == 0 || die "Failed to change $lib ID to $libid";
}
}
close FH;
}