Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if test "$1" = "" -o "$1" = "-h" -o "$1" = "--help" ; then
- echo "usage: $0 [-h] path/to/naoqi-bin"
- exit 1
- fi
- naoqipath=$1
- bin_folder=""
- top_folder=""
- function detectSDK {
- bin_folder=$(dirname "$naoqipath")
- bin_folder=$(cd "$bin_folder";pwd)
- naoqi_file="$bin_folder/naoqi-bin"
- if [ ! -x "$naoqi_file" ] ; then
- echo "Error: file not found: $naoqi_file"
- exit 1
- fi
- echo "Found naoqi-bin: $naoqi_file"
- lib_folder=$(cd "$bin_folder/../lib";pwd)
- if [ ! -x "$lib_folder/libinaoqi.dylib" ] ; then
- echo "Error: lib folder not found: $lib_folder"
- exit 1
- fi
- echo "Found lib folder: $lib_folder"
- top_folder=$(cd "$bin_folder/..";pwd)
- if [ ! -e "$top_folder/QtXml.framework" ] ; then
- echo "Error: framework folder not found: $top_folder"
- exit 1
- fi
- echo "Found frameworks folder: $top_folder"
- }
- strindex() {
- awk -v a="$1" -v b="$2" 'BEGIN{print index(a,b)}'
- }
- function correctLink {
- link="$1"
- file="$2"
- # 3 cases:
- # /Users/dmerejkowsky/Qt5.4.1/5.4/clang_64/lib/QtXml.framework/Versions/5/QtXml : replace /Users/dmerejkowsky/Qt5.4.1/5.4/clang_64/lib/ by $top_folder
- size=${#link}
- if [ $size > 45 ] ; then
- cleanDmerej="${link:45}"
- if [ -f "$top_folder"/$cleanDmerej ] ; then
- # echo "$top_folder/$cleanDmerej exists!"
- install_name_tool -change $link @rpath/$cleanDmerej "$file"
- # echo "$link cleaned"
- return
- fi
- fi
- # /Users/opennao/wget-1.15/tinyxml/build/libtinyxml.dylib : replace /Users/opennao/wget-1.15/tinyxml/build/ by $lib_folder
- if [ $size > 39 ] ; then
- cleanOpennao="${link:39}"
- if [ -f "$lib_folder"/$cleanOpennao ] ; then
- # echo "$lib_folder/$cleanOpennao exists!"
- install_name_tool -change $link @rpath/lib/$cleanOpennao "$file"
- # echo "$link cleaned"
- return
- fi
- fi
- # libboost_python.dylib : add $lib_folder
- if [ -f "$lib_folder"/$link ] ; then
- # echo "$lib_folder/$link exists!"
- install_name_tool -change $link @rpath/lib/$link "$file"
- # echo "$link cleaned"
- return
- fi
- # echo "Could not clean $link"
- }
- detectSDK
- echo ""
- echo "going through $top_folder"
- file_list=$(find "$top_folder" ! \( -name "*.py" -o -name "*.h" -o -name "*.hpp" \) -type f -perm +111 -print)
- count=0
- total=$(find "$top_folder" ! \( -name "*.py" -o -name "*.h" -o -name "*.hpp" \) -type f -perm +111 -print | wc -l)
- echo $total
- pstr="[=======================================================================]"
- echo "$file_list" | while read current_file; do
- count=$(( $count + 1 ))
- pd=$(( $count * 73 / $total ))
- # valid when no fatal error
- # echo "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 /
- #$total) % 10 )) $pstr
- printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr
- if [ -d "$current_file" ] ; then
- continue
- fi
- if [ ! -f "$current_file" ] ; then
- continue
- fi
- if [ ! -x "$current_file" ] ; then
- continue
- fi
- file_links=$(otool -LX "$current_file" 2> /dev/null)
- echo "$file_links" | while read a; do
- end_index=$(strindex "$a" " (compatibility")
- original_path="${a:0:$end_index}"
- actual_path="$original_path"
- relative=false
- if [[ $actual_path == "@rpath"* ]] ; then
- actual_path="$top_folder/${actual_path:7}"
- relative=true
- fi
- if [ -e "$actual_path" ] ; then
- continue
- fi
- if $relative ; then
- #echo "$original_path is not correct but it is relative: cannot fix."
- continue
- fi
- correctLink "$original_path" "$current_file"
- done
- install_name_tool -change /usr/local/lib/libsndfile.1.dylib @rpath/lib/libsndfile.1.dylib "$bin_folder"/../lib/naoqi/libmodularityperception.dylib
- install_name_tool -change /usr/local/lib/libsndfile.1.dylib @rpath/lib/libsndfile.1.dylib "$bin_folder"/../lib/libaudiodevicemanager.dylib
- install_name_tool -change /usr/local/lib/libsndfile.1.dylib @rpath/lib/libsndfile.1.dylib "$bin_folder"/../lib/libalmodularity_audio.dylib
- done
Advertisement
Add Comment
Please, Sign In to add comment