# # # add_file "osx_bundle.sh" # content [bd844169d6760460baa53fad78a0e185aa114f4e] # # set "osx_bundle.sh" # attr "mtn:execute" # value "true" # ============================================================ --- osx_bundle.sh bd844169d6760460baa53fad78a0e185aa114f4e +++ osx_bundle.sh bd844169d6760460baa53fad78a0e185aa114f4e @@ -0,0 +1,119 @@ +#!/bin/bash +# +# Create a distributable application package which already +# contains the needed Qt4 libraries in order to run the application. +# In the end a disk image is created for easy distribution which is put +# into the $BIN_DIR. +# +# This script is provided "as-is" with no guarantees or whatsoever; if it +# damages your hd, its not my fault =) +# +# The most recent version of this script should be found in the monotone +# repository on http://venge.net in the branch "net.venge.monotone.guitone", +# as guitone (http://guitone.berlios.de) was the software for what I originally +# hacked it together. +# +# Questions, Comments, Donations can go to +# +# Thomas Keller (me AT thomaskeller DOT biz) +# +# Release History: +# +# 1.0 (2006-11-08) - Initial release +# + +# +# Configuration start +# + +# relative path to the directory which contains the created app bundle +BIN_DIR="guitone/bin" +# name of the binary +BINARY_NAME="guitone" +# Qt libraries you've linked against +declare -a NEEDED_LIBS=( "QtCore" "QtGui" ) +# additional files you'd like to get copied to the final dmg +declare -a ADD_FILES=( "README" "COPYING" "NEWS") + +# +# Configuration end, nothing should be edited from here on +# + +bundle_dir="$BIN_DIR/$BINARY_NAME.app" +bundle_bin="$bundle_dir/Contents/MacOS/$BINARY_NAME" +framework_dir="$bundle_dir/Contents/Frameworks" + +if [ -z $QTDIR ]; then + echo "\$QTDIR environment variable not found... exiting." + exit 1 +fi + +# canonicalize QtDir, unfortunately this bash has no realpath() implementation +# so we need to use perl for this +QTDIR=`perl -e "use Cwd 'realpath'; print realpath('$QTDIR');"` + +if [ ! -d "$bundle_dir" ]; then + echo "Application bundle not found in bin... exiting." + exit 1 +fi + +echo "Creating Frameworks directory in application bundle..." +mkdir -p "$framework_dir" + address@hidden +for (( i = 0 ; i < libcount ; i++ )) +do + lib=${NEEDED_LIBS[$i]} + echo "Processing $lib..." + + if [ ! -d "$QTDIR/lib/$lib.framework" ]; then + echo "Couldn't find $lib.framework in $QTDIR." + exit 1 + fi + + rm -rf "$framework_dir/$lib.framework" + cp -fR "$QTDIR/lib/$lib.framework" "$framework_dir" + echo "...$lib copied." + + install_name_tool \ + -id "@executable_path/../Frameworks/$lib.framework/Versions/4/$lib" \ + "$framework_dir/$lib.framework/Versions/4/$lib" + + # other Qt libs depend at least on QtCore + if [ "$lib" != "QtCore" ]; then + install_name_tool -change "$QTDIR/lib/QtCore.framework/Versions/4/QtCore" \ + "@executable_path/../Frameworks/QtCore.framework/Versions/4/QtCore" \ + "$framework_dir/$lib.framework/Versions/Current/$lib" + fi + + install_name_tool -change "$QTDIR/lib/$lib.framework/Versions/4/$lib" \ + "@executable_path/../Frameworks/$lib.framework/Versions/4/$lib" \ + "$bundle_bin" + + echo "...$lib done." +done + + +echo "Removing any debug libraries and headers..." +find "$framework_dir" | egrep "debug|Headers" | xargs rm -rf + +echo "Preparing image directory..." +tempdir="/tmp/`basename $0`.$$" +mkdir $tempdir +cp -R $bundle_dir $tempdir +echo "...Bundle copied" address@hidden +for (( i = 0 ; i < fcount ; i++ )) do + file=${ADD_FILES[$i]} + if [ ! -f "$file" ]; then + echo "WARNING: $file not found!" + else + cp "$file" $tempdir + echo "...$file copied" + fi +done +echo "Creating disk image..." +rm -f "$BIN_DIR/$BINARY_NAME.dmg" +# format UDBZ: bzip2 compressed (10.4+), UDZ0: zlib compressed (default) +hdiutil create -srcfolder $tempdir -format UDBZ -volname "$BINARY_NAME" "$BIN_DIR/$BINARY_NAME.dmg" +rm -rf $tempdir