ASP#!/bin/bash QTDIR=$1BUILDDIR=$2ROOTSOURCEDIR=$3PATH_2_BUNDLE=$4 echo QTDIR=$QTDIRecho BUILDDIR=$BUILDDIRecho ROOTSOURCEDIR=$ROOTSOURCEDIRecho PATH_2_BUNDLE=$PATH_2_BUNDLE readonly BUNDLE_NAME_MAINAPP="Application.app"readonly BUNDLE_NAME_UPDATER="Updater.app"readonly BUNDLE_NAME_DUMPLOADER="Dumploader.app"readonly OWN_PLUGIN_TAIL="Plugin.dylib"readonly LIBSTYLEPLUGIN="libstyleplugiln.dlib" readonly QT_MAJOR_V=4 readonly err_CreateFWSubdir=10readonly err_CopyFile=20readonly err_SetFrameworkID=30readonly err_ChangeFrameworkID=40 function cpR {#echo $FUNCNAME $@ if ! cp -R "$1" "$2" ; then echo "can't copy "$1" to "$2 exit $err_CopyFile fi} function setID {#echo $FUNCNAME $@ if ! install_name_tool -id $1 $2 ; then echo Settinf up id for framework $1 failed! exit $err_SetFrameworkIDfi} function changeID {#echo $FUNCNAME $@ if ! install_name_tool -change $1 $2 $3 ; then echo "Changing id from $1 to $2 for $3 failed!" exit $err_ChangeFrameworkID fi} function updateId_QtLib {#echo $FUNCNAME $@QTDIR_lib=$QTDIR/libqtDirLength=${#QTDIR_lib}MODULE=${2:qtDirLength}FRAMEWORKS="/Frameworks/"$MODULEID="@executable_path/.."$FRAMEWORKSFRAMEWORK=$PATH_2_BUNDLE"/"$3"/Contents"$FRAMEWORKS #echo FRAMEWORK=$FRAMEWORKif [ ! -e $FRAMEWORK ] ; then FIRST_DOT_INDEX=$(echo | awk ' { print index("'"${MODULE}"'", ".") } ' ) FW_NAME=${MODULE:0:$FIRST_DOT_INDEX}framework cpR $QTDIR"lib/"$FW_NAME $PATH_2_BUNDLE/$3/Contents/Frameworks"/"$FW_NAMEfi #setID $ID $FRAMEWORKchangeID $2 $ID $1} function updateId_OwnPlug {#echo $FUNCNAME $@ PLUGIN=$2 ID="@executable_path/plugins/"$PLUGIN #setID $ID $FRAMEWORK changeID $2 $ID $1} function updateId_OwnLib {#echo $FUNCNAME $@ OWN_LIB=$2 ID="@executable_path/../Frameworks/"$OWN_LIB LIBS_IN_BUNDLE=$PATH_2_BUNDLE"/"$3"/Contents/Frameworks" if [ ! -e $LIBS_IN_BUNDLE ] ; then mkdir $LIBS_IN_BUNDLE fi FRAMEWORK=$LIBS_IN_BUNDLE"/"$OWN_LIB echo FRAMEWORK=$FRAMEWORK if [ ! -e $FRAMEWORK ] ; then cpR $1 $FRAMEWORK echo library copied: $1 fi #setID $ID $FRAMEWORK echo calling changeID $2 $ID $1 changeID $2 $ID $1 } function updateDependency {#echo $FUNCNAME $@ if [ ${dependency:0:1} != "@" ]; then qtDirLength=${#QTDIR} libStylePlugLen=${#LIBSTYLEPLUGIN} isQtLib=${2:0:qtDirLength} if [ "$isQtLib" == "$QTDIR" ] ; then # Starts from QTDIR: updateId_QtLib $1 $2 $3 fi isOwnLib=${2:0:3} if [ "$isOwnLib" == "lib" ]; then # Starts from lib: PLUGIN=$2 plugTailLength=${#OWN_PLUGIN_TAIL} currPluginTail=${PLUGIN:(-$plugTailLength) } #if [ ${2:0:libStylePlugLen} == $LIBSTYLEPLUGIN ] ; then if [ $OWN_PLUGIN_TAIL == $currPluginTail ] ; then updateId_OwnPlug $1 $2 $3 else updateId_OwnLib $1 $2 $3 fi fi fi`}function updateDependencys {echo FUNCNAME=$FUNCNAME $@ DEPS="$(otool -L $1 | awk '{ print $1 }')" #otool -L $1 currentStep=0 for dependency in $DEPS do libNameLen=${#dependency} depName=${1:(-$libNameLen)} currentStep=$(( $currentStep + 1 )) if [ $currentStep -lt 3 ] || [ ${dependency:0:1} == "@" ] || [ "$depName" == "$dependency" ] || [ "${dependency:(-1)}" == ":" ] ; then continue fi updateDependency $1 $dependency $2 done#otool -L $1} function updateBinaries {#echo $FUNCNAME $@ for binary in $1 do #echo processing file: $binary if [ ! -d $binary ] ; then echo file is $binary updateDependencys $binary $2 fi done} function updateApp { #echo $FUNCNAME $@ path="$PATH_2_BUNDLE/$1/Contents" macdeployqt $PATH_2_BUNDLE/$1 updateBinaries "$path/MacOS/*" $1 if [ $1 == $BUNDLE_NAME_MAINAPP ] ; then updateBinaries "$path/Frameworks/*.dylib" $1 updateBinaries "$path/MacOS/plugins/*.dylib" $1 fi} libStylePlugins=$PATH_2_BUNDLE/libstyleplugin*.dylibfor libstyleplugin in $libStylePluginsdoecho moving $libstyleplugin $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOS/ mv $libstyleplugin $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOS/done ownPlugins=$PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOS/if [ ! -e $ownPlugins/plugins ] ; then cpR $PATH_2_BUNDLE/plugins $ownPluginsfi if [ ! -e "$PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/Frameworks" ] ; then mkdir "$PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/Frameworks"fi for f in $PATH_2_BUNDLE/*.dylibdoecho moving $f $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/Frameworks/ mv $f $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/Frameworks/done updateApp $BUNDLE_NAME_MAINAPPupdateApp $BUNDLE_NAME_UPDATERupdateApp $BUNDLE_NAME_DUMPLOADER cpR $PATH_2_BUNDLE/$BUNDLE_NAME_UPDATER/Contents/MacOS/Updater $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOScpR $PATH_2_BUNDLE/$BUNDLE_NAME_DUMPLOADER/Contents/MacOS/DumpLoader $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOScpR $PATH_2_BUNDLE/config.ini $PATH_2_BUNDLE/$BUNDLE_NAME_MAINAPP/Contents/MacOS