Skip to content

Instantly share code, notes, and snippets.

@jcfr
Created March 22, 2022 21:58
Show Gist options
  • Save jcfr/7e2aaae1b7a9dad94640e7cba5da47be to your computer and use it in GitHub Desktop.
Save jcfr/7e2aaae1b7a9dad94640e7cba5da47be to your computer and use it in GitHub Desktop.
Script to patch the Boost libraries changing the occurences of `@rpath` back to a full path
#/bin/env bash
# This script allows to patch the Boost libraries changing the occurences of `@rpath`
# back to a full path specific to this dashboard.
#
# This is currently required by Slicer macOS packaging infrastructure.
set -euo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BOOST_INSTALL_DIR=${SCRIPT_DIR}/boost_1_78_0-install
cd ${BOOST_INSTALL_DIR}/lib
# Collect list of boost library filenames
boost_library_filenames=()
for filename in $(ls *.dylib); do
boost_library_filenames+=( ${filename} )
done
# Fix library id
for filename in ${boost_library_filenames[@]}; do
echo "Fixing ${filename}"
filepath=${BOOST_INSTALL_DIR}/lib/${filename}
if [[ ! -e ${filepath} ]]; then
echo "Filepath [${filepath}] does not exist"
exit 1
fi
install_name_tool -id ${filepath} ${filepath}
# Given lines of the form
# @rpath/libboost_<name>.dylib (compatibility version 0.0.0, ...)
# Extract
# @rpath/libboost_<name>.dylib
rpaths=$(otool -L ${filepath} | grep "@rpath/libboost" | cut -d"(" -f1 | xargs) || true
for rpath in $rpaths; do
# Replace "@rpath" with "${BOOST_INSTALL_DIR}/lib"
updated_rpath=${rpath/@rpath/${BOOST_INSTALL_DIR}/lib}
install_name_tool -change ${rpath} ${updated_rpath} ${filepath}
echo " $rpath -> $updated_rpath"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment