From e9b87274400ff939b8d8860ece5df86fa730e13f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Thu, 13 Oct 2016 17:51:44 -0500 Subject: [PATCH] ... --- install/macos/clean_libs.sh | 13 ++++++++++ install/macos/prepare_libs.sh | 46 +++++++++++++++++++++++++++++++++++ install/macos/relink_lib.sh | 36 +++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100755 install/macos/clean_libs.sh create mode 100755 install/macos/prepare_libs.sh create mode 100755 install/macos/relink_lib.sh diff --git a/install/macos/clean_libs.sh b/install/macos/clean_libs.sh new file mode 100755 index 0000000..14613ce --- /dev/null +++ b/install/macos/clean_libs.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +lib_dir=$1 + +for i in $lib_dir/* + do + lnk_i=`readlink $i` + if ! [[ $lnk_i = *[!\ ]* ]]; then + echo $lnk_i + fi +done + +## eof diff --git a/install/macos/prepare_libs.sh b/install/macos/prepare_libs.sh new file mode 100755 index 0000000..e8cb78d --- /dev/null +++ b/install/macos/prepare_libs.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +lib_dir=$1 + +for i in $lib_dir/* + do + lnk_i=`readlink $i` + if ! [[ $lnk_i = *[!\ ]* ]]; then + equal_lib="" + for j in $lib_dir/* + do + lnk_j=`readlink $j` + if ! [[ $lnk_j = *[!\ ]* ]]; then + difference=`diff -q $i $j` + if ! [[ $difference = *[!\ ]* ]]; then + equal_lib+=$j + equal_lib+=" " + fi + fi + done + if [[ $equal_lib = *[!\ ]* ]]; then + max_len=0 + max_str="" + for k in $equal_lib + do + if [ ${#k} -ge $max_len ]; then + max_len=${#k} + max_str=$k + fi + done + echo $max_str + for k in $equal_lib + do + if ! [ $k == $max_str ]; then + rm -rf $k + ln -fs $max_str $k + fi + done + unset max_len + unset max_str + fi + unset equal_lib + fi +done + +## eof diff --git a/install/macos/relink_lib.sh b/install/macos/relink_lib.sh new file mode 100755 index 0000000..f2172c2 --- /dev/null +++ b/install/macos/relink_lib.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +file=$1 +lib_dir=$2 +exec_dir=$3 + +strindex( ) +{ + x="${1%%$2*}" + [[ $x = $1 ]] && echo -1 || echo ${#x} + } + +file_link=`readlink $file` +if ! [[ $file_link = *[!\ ]* ]]; then + for lib in $lib_dir/* + do + lib_name=`basename $lib` + linked_lib=`otool -L $file | grep $lib_name | tail -1` + if [[ $linked_lib = *[!\ ]* ]]; then + index=`strindex "$linked_lib" " ("` + real_lib=`echo $linked_lib | cut -c 1-$index` + lib_link=`readlink $lib` + if [[ $lib_link = *[!\ ]* ]]; then + lib_link=`basename $lib_link` + else + lib_link=$lib_name + fi + if [[ $lib_link = *[!\ ]* ]]; then + echo $real_lib $lib_link + install_name_tool -change $real_lib $exec_dir/$lib_link $file + fi + fi + done +fi + +## eof \ No newline at end of file -- 2.47.1