diff options
author | Simon Howard | 2010-02-05 23:08:12 +0000 |
---|---|---|
committer | Simon Howard | 2010-02-05 23:08:12 +0000 |
commit | 677729c658b39f075e563fbc9f5a898641f7de54 (patch) | |
tree | 109bae4ac22fbc6f8a34ba34a4e9fc6a33e75c48 /pkg/osx/cp-with-libs | |
parent | 8a77b34e936a3fd752db3bc1113e3d7bd0555440 (diff) | |
parent | b4f2d75b34b6e2b9bbb2fa6449125d3446a93a73 (diff) | |
download | chocolate-doom-677729c658b39f075e563fbc9f5a898641f7de54.tar.gz chocolate-doom-677729c658b39f075e563fbc9f5a898641f7de54.tar.bz2 chocolate-doom-677729c658b39f075e563fbc9f5a898641f7de54.zip |
Merge from trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1845
Diffstat (limited to 'pkg/osx/cp-with-libs')
-rwxr-xr-x | pkg/osx/cp-with-libs | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/pkg/osx/cp-with-libs b/pkg/osx/cp-with-libs new file mode 100755 index 00000000..04fb5bc6 --- /dev/null +++ b/pkg/osx/cp-with-libs @@ -0,0 +1,100 @@ +#!/bin/bash +# +# Copy a program to the specified destination, along +# with libraries it depends upon. + +src_bin=$1 +dest_dir=$2 + +# Returns true if the specified file is a dylib. + +is_dylib() { + case "$1" in + *.dylib) + true + ;; + *) + false + ;; + esac +} + +# Returns true if the specified file is in a system location +# (/System or /usr): + +is_sys_lib() { + case "$1" in + /System/*) + true + ;; + /usr/*) + true + ;; + *) + false + ;; + esac +} + +# Install the specified file to the location in dest_dir, along with +# any libraries it depends upon (recursively): + +install_with_deps() { + local src_file + local bin_name + local dest_file + local lib_name + + src_file=$1 + bin_name=$(basename "$src_file") + dest_file="$dest_dir/$bin_name" + + # Already copied into the package? Don't copy again. + # Prevents endless recursion. + + if [ -e "$dest_file" ]; then + return + fi + + echo "Installing $bin_name..." + + # Copy file into package. + + cp "$src_file" "$dest_file" + + # Copy libraries that this file depends on: + + otool -L "$src_file" | tail -n +2 | sed 's/^.//; s/ (.*//' | while read; do + + # Don't copy system libraries + + if is_sys_lib "$REPLY"; then + continue + fi + + #echo " - $bin_name depends on $REPLY" + + # Copy this library into the package, and: + # recursively install any libraries that _this_ library depends on: + + install_with_deps "$REPLY" + + # Change destination binary to depend on the + # copy inside the package: + + lib_name=$(basename "$REPLY") + install_name_tool -change "$REPLY" "@executable_path/$lib_name" \ + "$dest_file" + done + + # If this is a library that we have installed, change its id: + + if is_dylib "$dest_file"; then + install_name_tool -id "@executable_path/$bin_name" "$dest_file" + fi +} + +# Install the file, and recursively install any libraries: + +install_with_deps "$src_bin" + |