aboutsummaryrefslogtreecommitdiffstats
path: root/dist/macos/bundle/reref_dylibs.sh
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@ubuntu.com>2018-04-25 18:07:30 -0400
committerLibravatarUnit 193 <unit193@ubuntu.com>2018-04-25 18:07:30 -0400
commit9b1b081cfdb1c0fb6457278775e0823f8bc10f62 (patch)
treece8840148d8445055ba9e4f12263b2208f234c16 /dist/macos/bundle/reref_dylibs.sh
Import Upstream version 2.0.0+dfsgupstream/2.0.0+dfsg
Diffstat (limited to 'dist/macos/bundle/reref_dylibs.sh')
-rwxr-xr-xdist/macos/bundle/reref_dylibs.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/dist/macos/bundle/reref_dylibs.sh b/dist/macos/bundle/reref_dylibs.sh
new file mode 100755
index 0000000..15191bd
--- /dev/null
+++ b/dist/macos/bundle/reref_dylibs.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# $1 = binary (program or dylib)
+B_TARGET=$1
+if [ "x$B_TARGET" = "x" ]; then
+ echo Which binary needs to be re-referenced?
+ exit 1
+fi
+
+cd $(dirname $B_TARGET) || exit 1
+
+# where to find non-system libraries relative to target's directory.
+# the vast majority of the time this should be empty
+B_REL_PATH=$2
+
+# we're in target's directory now. trim off the path
+B_TARGET=$(basename $B_TARGET)
+
+# get a list of non-system libraries and make local copies
+B_LIBS=$(otool -XL $B_TARGET | awk '{ print $1 }' | grep -Ev '^(/usr/lib|/System)')
+[ $? -ne 0 ] && exit 1
+for B_LIB in $B_LIBS; do
+ B_LIB_NAME=$(basename $B_LIB)
+
+ # ignore self-references
+ [ "$B_TARGET" = "$B_LIB_NAME" ] && continue
+
+ B_DST=${B_REL_PATH}${B_LIB_NAME}
+ if [ ! -e $B_DST ]; then
+ cp $B_LIB $B_DST || exit 1
+ chmod u+rw $B_DST || exit 1
+ # recursively call this script on libraries purposefully not passing
+ # $B_REL_PATH so that it is only used explicitly
+ $0 $B_DST
+ fi
+
+ # adjust the target's metadata to point to the local copy
+ # rather than the system-wide copy which would only exist on
+ # a development machine
+ install_name_tool -change $B_LIB @loader_path/$B_DST $B_TARGET || exit 1
+done