insilmaril@399: #!/bin/bash
insilmaril@399: #
insilmaril@399: # Link application bundle to QT as framework
insilmaril@399: #
insilmaril@399: # written by Uwe Drechsel (c) 2006
insilmaril@399: #
insilmaril@399: # License GPL 2
insilmaril@399: #
insilmaril@399: 
insilmaril@399: APPNAME=vym
insilmaril@399: BUNDLE=$APPNAME.app
insilmaril@399: FWORKS=$BUNDLE/Contents/Frameworks
insilmaril@399: QTDIR=/usr/local/Trolltech/Qt-4.2.0
insilmaril@399: QTLIB=$QTDIR/lib
insilmaril@399: 
insilmaril@399: declare -a FWLIST
insilmaril@399: 
insilmaril@399: function cleanup
insilmaril@399: {
insilmaril@399: 	echo ***Cleaning up...
insilmaril@399: 	rm -rf $BUNDLE
insilmaril@399: 	make clean
insilmaril@399: }
insilmaril@399: 
insilmaril@399: function compile
insilmaril@399: {
insilmaril@399: 	echo ***Compiling...
insilmaril@399: 	qmake -config release
insilmaril@399: 	make
insilmaril@399: }
insilmaril@399: 
insilmaril@399: function fixLinking 
insilmaril@399: {
insilmaril@399: 	echo  ***Setting identification names...
insilmaril@399: 	for i in ${FWLIST[@]}
insilmaril@399: 	do
insilmaril@399: 		COM="install_name_tool -id @executable_path/../Frameworks/$i.framework/Versions/4/$i $BUNDLE/Contents/Frameworks/$i.framework/Versions/4/$i"
insilmaril@399: 	done	
insilmaril@399: 		echo "   $COM"
insilmaril@399: 		`$COM`
insilmaril@399: 
insilmaril@399: 	echo ***Tell dynamic linker where to look for frameworks... 
insilmaril@399: 	for i in ${FWLIST[@]}
insilmaril@399: 	do
insilmaril@399: 		COM="install_name_tool -change $QTLIB/$i.framework/Versions/4/$i @executable_path/../Frameworks/$i.framework/Versions/4/$i $BUNDLE/Contents/MacOs/$APPNAME"
insilmaril@399: 		echo "   $COM"
insilmaril@399: 		`$COM`
insilmaril@399: 	done	
insilmaril@399: 
insilmaril@399: 
insilmaril@399: 	for fw in ${FWLIST[@]}
insilmaril@399: 	do
insilmaril@399: 	echo ***Adjust dynamic linking in $fw
insilmaril@399: 		for i in ` otool -L vym.app/Contents/Frameworks/$fw.framework/$fw | grep Trolltech | sed "s/^.*\///" | sed "s/ .*$//"` 
insilmaril@399: 		do
insilmaril@399: 			COM="install_name_tool -change $QTLIB/$i.framework/Versions/4/$i @executable_path/../Frameworks/$i.framework/Versions/4/$i $FWORKS/$fw.framework/$fw"
insilmaril@399: 			echo "   $COM"
insilmaril@399: 			`$COM`
insilmaril@399: 		done	
insilmaril@399: 	done
insilmaril@399: 
insilmaril@399: }
insilmaril@399: 
insilmaril@399: function copyFrameworks
insilmaril@399: {
insilmaril@399: 	# Copy found frameworks into bundle, preserve symbolic links with -R
insilmaril@399: 	mkdir -p  $FWORKS
insilmaril@399: 	for i in ${FWLIST[@]}
insilmaril@399: 	do
insilmaril@399: 		echo ***Copying $QTLIB/$i.framework
insilmaril@399: 		#cp -R $QTLIB/$i.framework $FWORKS
insilmaril@399: 		rsync -avz $QTLIB/$i.framework $FWORKS --exclude 'Qt*_debug'
insilmaril@399: 	done	
insilmaril@399: }
insilmaril@399: 
insilmaril@399: function copyRessources
insilmaril@399: {
insilmaril@399: 	echo ***Copying ressources
insilmaril@399: 	mkdir -p $BUNDLE/Contents/Resources
insilmaril@399: 	cp -r icons flags scripts styles vym.app/Contents/Resources/
insilmaril@399: 	cp icons/vym.icns $BUNDLE/Contents/Resources
insilmaril@399: }
insilmaril@399: 
insilmaril@399: function findFrameworks
insilmaril@399: {
insilmaril@399: 	FWLIST=`otool -L $BUNDLE/Contents/MacOS/$APPNAME  | grep Trolltech | sed "s/^.*\///" | sed "s/ .*$//"`
insilmaril@399: 	#FWLIST=( Qt3Support QtSql QtNetwork QtXml QtGui QtCore )
insilmaril@399: 
insilmaril@399: 	echo ***The following Qt frameworks are needed:
insilmaril@399: 	for i in ${FWLIST[@]}
insilmaril@399: 	do
insilmaril@399: 		echo $i
insilmaril@399: 	done	
insilmaril@399: }	
insilmaril@399: 
insilmaril@399: 
insilmaril@399: #cleanup
insilmaril@399: #compile
insilmaril@399: 
insilmaril@399: 
insilmaril@399: #findFrameworks
insilmaril@399: #copyFrameworks
insilmaril@399: #fixLinking
insilmaril@399: copyRessources
insilmaril@399: