#!/bin/bash
#
# Configuration start
#
# relative path to the directory which contains the created app bundle
BIN_DIR="bin"
# name of the binary
BINARY_NAME="edithtml"
# Qt libraries you've linked against on apps remove not needed libs
declare -a NEEDED_LIBS=( "QtCore" "QtGui" "QtXml" "QtSql" "QtNetwork" "QtOpenGL" "QtSvg")
# additional files you'd like to get copied to the final dmg
declare -a ADD_FILES=("bin/ticket.pdf" "bin/copying.txt")
#
# Configuration end, nothing should be edited from here on
#
# on main.cpp
#if defined Q_WS_MAC
#QStringList path;
#path.append(QApplication::applicationDirPath());
#QDir dir(QApplication::applicationDirPath());
#dir.cdUp();
#path.append(dir.absolutePath());
#dir.cd("plugins");
#path.append(dir.absolutePath());
#dir.cdUp();
#path.append(dir.absolutePath());
#QApplication::setLibraryPaths(path);
#QDir::setCurrent(dir.absolutePath()); /* here down -> Frameworks */
#endif
qtbaselibpath="/Library/Frameworks"
bundle_dir="$BIN_DIR/$BINARY_NAME.app"
bundle_bin="$bundle_dir/Contents/MacOS/$BINARY_NAME"
framework_dir="$bundle_dir/Contents/Frameworks"
plugin_dir="$bundle_dir/Contents/plugins"
locale_dir="$bundle_dir/Contents/locale"
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"
mkdir -p $plugin_dir
mkdir -p $locale_dir
libcount=${#NEEDED_LIBS[@]}
for (( i = 0 ; i < libcount ; i++ ))
do
lib=${NEEDED_LIBS[$i]}
echo "Processing $lib..."
if [ ! -d "$qtbaselibpath/$lib.framework" ]; then
echo "Couldn't find $lib.framework in $qtbaselibpath."
exit 1
fi
rm -rf "$framework_dir/$lib.framework"
cp -fR "$qtbaselibpath/$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 "$qtbaselibpath/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 "$qtbaselibpath/$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"
fcount=${#ADD_FILES[@]}
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
Bookmarks