From 24d23714af18d9a21dc94ac0ec193915aacc9947 Mon Sep 17 00:00:00 2001 From: AlexandraTrifan Date: Tue, 22 Oct 2024 16:48:54 +0300 Subject: [PATCH] ci: add fixup_tar to handle rpath and depdendencies Signed-off-by: AlexandraTrifan --- CI/macOS/fixup_tar | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 CI/macOS/fixup_tar diff --git a/CI/macOS/fixup_tar b/CI/macOS/fixup_tar new file mode 100644 index 00000000..3589a174 --- /dev/null +++ b/CI/macOS/fixup_tar @@ -0,0 +1,55 @@ +#!/bin/bash + +#!/bin/bash -xe +WORKDIR=$(pwd) +cd $WORKDIR/build_tar +# Extract tar.gz to temp folder +tarname=$(find . -maxdepth 1 -name '*.tar.gz') +if [ -z "${tarname}" ]; then + echo "tar.gz not found" + exit 1 +fi +# Remove .tar.gz from filename +subfoldername=$(echo "${tarname}" | rev | cut -b 8- | rev) + +mkdir -p temp_tar +tar -xzf "${tarname}" -C temp_tar +mv "temp_tar/${subfoldername}" temp +cd temp + +deps_dir=Library/Frameworks/libm2k.framework/Versions/Current/Dependencies +libm2k_loc=Library/Frameworks/libm2k.framework/Versions/Current/libm2k +libm2kheaders_loc=Library/Frameworks/libm2k.framework/Versions/Current/Headers/* + +mkdir -p "${deps_dir}" + +# Create links to framework files +mkdir -p usr/local/{lib,include} +ln -fs "../../../${libm2k_loc}" usr/local/lib/libm2k.dylib +# ln -fs "../../../${libm2kheaders_loc}" usr/local/include/iio.h + +# Update rpath of library +install_name_tool -add_rpath @loader_path/. "${libm2k_loc}" + +# Copy dependent libs to local libs, and update rpath of dependencies +for each in $(otool -L "${libm2k_loc}" |grep '\/usr\/local\|homebrew' |cut -f2 | cut -d' ' -f1) ; do + name=$(basename "${each}") + cp "${each}" "${deps_dir}" + chmod +w "${deps_dir}/${name}" + install_name_tool -id "@rpath/Dependencies/${name}" "${deps_dir}/${name}" + install_name_tool -change "${each}" "@rpath/Dependencies/${name}" "${libm2k_loc}" + codesign --force -s - "${deps_dir}/${name}" +done + +# Update tools +for tool in Library/Frameworks/libm2k.framework/Tools/*; +do + install_name_tool -add_rpath @loader_path/../.. "${tool}" +done + +# Remove old tar and create new one +rm "../${tarname}" +tar -czf "../${tarname}" . +cd .. +rm -rf temp +