Search
lxdream.org :: lxdream/bundlelibs.pl
lxdream 0.9.1
released Jun 29
Download Now
filename bundlelibs.pl
changeset 716:f353e54a3a85
prev713:e5256202cc9e
author nkeynes
date Thu Dec 11 23:26:03 2008 +0000 (15 years ago)
permissions -rwxr-xr-x
last change Disable the generational translation cache - I've got no evidence that it
actually helps performance, and it simplifies things to get rid of it (in
particular, translated code doesn't have to worry about being moved now).
view annotate diff log raw
     1 #!/usr/bin/perl
     2 # Script for OS X to copy all non-core library dependencies into the bundle, and fixup the lib naming
     3 # Run after the executable is already in the bundle.
     5 if( $#ARGV <= 0 ) {
     6    die( "Usage: bundlelibs.pl <target-binary> <target-lib-path>\n" );
     7 }
     9 my $BINARY=shift();
    10 my $TARGETDIR=shift();
    11 my $OTOOL="otool";
    12 my $NTOOL="install_name_tool";
    14 mkdir $TARGETDIR;
    16 my %done=();
    17 my @worklist = ($BINARY);
    19 while( $#worklist >= 0 ) {
    20     my $target = shift @worklist;
    21     $done{$target} = 2;
    23     open FH, "$OTOOL -L $target|" || die "Unable to run otool";
    24     $skip = <FH>;
    26     while(<FH>){
    27         $lib = $_;
    28         $lib =~ s/^\s+([^\s]+)\s.*$/$1/s;
    29         if( $lib !~ /^\/System\/Library/ && $lib !~ /^\/usr\/lib/ && $lib !~ /^\@executable_path\// ) {
    30             $libname = $lib;
    31             $libname =~ s#^.*/##;
    32             $targetpath = "$TARGETDIR/$libname";
    33             $libid = "\@executable_path/../Frameworks/$libname";
    34             if( !$done{$libname} ) {
    35                 $done{$libname} = 1;
    36                 push @worklist, $targetpath;
    37                 system( ("cp", $lib, $targetpath) ) == 0 || die "Failed to copy $lib to $targetpath";
    38                 system( ($NTOOL, "-id", $libid, $targetpath) ) == 0 || die "Failed to set $lib ID to $libid";
    39                 print "Copied $lib => $targetpath\n";
    40             }
    41             system( ($NTOOL, "-change", $lib, $libid, $target ) ) == 0 || die "Failed to change $lib ID to $libid";
    42         }
    43     }
    44     close FH;
    45 }
.