--- /dev/null
+#!/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
--- /dev/null
+#!/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