barrier/dist/macos/bundle/reref_dylibs.sh

50 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/sh
# $1 = binary (program or dylib)
B_TARGET=$1
if [ "x$B_TARGET" = "x" ]; then
# add warning for users running manually
2021-09-22 21:46:52 +00:00
warn() { tput bold; tput setaf 3; echo "$@"; tput sgr0 ; }
warn "The scripts build_installer.sh and reref_dylibs.sh have been deprecated."
warn "Please use build_dist.sh instead to deploy using macdeployqt"
2021-09-22 21:46:52 +00:00
echo "Which binary needs to be re-referenced?"
exit 1
fi
2021-09-22 21:46:52 +00:00
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
2021-09-22 21:46:52 +00:00
B_TARGET=$(basename "$B_TARGET")
# get a list of non-system libraries and make local copies
2021-09-22 21:46:52 +00:00
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
2021-09-22 21:46:52 +00:00
B_LIB_NAME=$(basename "$B_LIB")
2018-12-29 02:05:20 +00:00
# otool reports barrier as "barrier:" which fails self-reference test below
B_LIB_NAME=${B_LIB_NAME//:}
# ignore self-references
[ "$B_TARGET" = "$B_LIB_NAME" ] && continue
B_DST=${B_REL_PATH}${B_LIB_NAME}
2021-09-22 21:46:52 +00:00
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
2021-09-22 21:46:52 +00:00
$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
2021-09-22 21:46:52 +00:00
install_name_tool -change "$B_LIB" "@loader_path/$B_DST" "$B_TARGET" || exit 1
done