Search
lxdream.org :: lxdream/bundlelibs.pl :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename bundlelibs.pl
changeset 713:e5256202cc9e
next716:f353e54a3a85
author nkeynes
date Sun Jun 29 03:51:33 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Add all non-core libraries to the OS X bundle
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/bundlelibs.pl Sun Jun 29 03:51:33 2008 +0000
1.3 @@ -0,0 +1,45 @@
1.4 +#!/usr/bin/perl
1.5 +# Script for OS X to copy all non-core library dependencies into the bundle, and fixup the lib naming
1.6 +# Run after the executable is already in the bundle.
1.7 +
1.8 +if( $#ARGV <= 0 ) {
1.9 + die( "Usage: bundlelibs.pl <target-binary> <target-lib-path>\n" );
1.10 +}
1.11 +
1.12 +my $BINARY=shift();
1.13 +my $TARGETDIR=shift();
1.14 +my $OTOOL="otool";
1.15 +my $NTOOL="install_name_tool";
1.16 +
1.17 +mkdir $TARGETDIR;
1.18 +
1.19 +my %done=();
1.20 +my @worklist = ($BINARY);
1.21 +
1.22 +while( $#worklist >= 0 ) {
1.23 + my $target = shift @worklist;
1.24 + $done{$target} = 2;
1.25 +
1.26 + open FH, "$OTOOL -L $target|" || die "Unable to run otool";
1.27 + $skip = <FH>;
1.28 +
1.29 + while(<FH>){
1.30 + $lib = $_;
1.31 + $lib =~ s/^\s+([^\s]+)\s.*$/$1/s;
1.32 + if( $lib !~ /^\/System\/Library/ && $lib !~ /^\/usr\/lib/ && $lib !~ /^\@executable_path\// ) {
1.33 + $libname = $lib;
1.34 + $libname =~ s#^.*/##;
1.35 + $targetpath = "$TARGETDIR/$libname";
1.36 + $libid = "\@executable_path/../Frameworks/$libname";
1.37 + if( !$done{$libname} ) {
1.38 + $done{libname} = 1;
1.39 + push @worklist, $targetpath;
1.40 + system( ("cp", $lib, $targetpath) ) == 0 || die "Failed to copy $lib to $targetpath";
1.41 + system( ($NTOOL, "-id", $libid, $targetpath) ) == 0 || die "Failed to set $lib ID to $libid";
1.42 + print "Copied $lib => $targetpath\n";
1.43 + }
1.44 + system( ($NTOOL, "-change", $lib, $libid, $target ) ) == 0 || die "Failed to change $lib ID to $libid";
1.45 + }
1.46 + }
1.47 + close FH;
1.48 +}
.