| 1 | #!/bin/sh |
| 2 | # Copyright 2007-2008 David Johnson |
| 3 | # The author grants unlimited permission to |
| 4 | # copy, distribute and modify this script |
| 5 | |
| 6 | # APPNAME=MyApp |
| 7 | |
| 8 | ### get system configuration ######################################## |
| 9 | |
| 10 | # as long as we can find qmake, we don't need QTDIR |
| 11 | FWPATH=`qmake -query QT_INSTALL_LIBS` |
| 12 | if [ ! -d $FWPATH/QtGui.framework ] ; then |
| 13 | echo "ERROR: cannot find the Qt frameworks. Make sure Qt is installed" |
| 14 | echo "and qmake is in your environment path." |
| 15 | exit |
| 16 | fi |
| 17 | |
| 18 | ### get required user input ######################################### |
| 19 | |
| 20 | if [ -z $APPNAME ] ; then |
| 21 | echo |
| 22 | echo "This script prepares a Qt application bundle for deployment. It will" |
| 23 | echo "copy over the required Qt frameworks and sets the installation" |
| 24 | echo "identifications. Please see the \"Deploying an Application on Qt/Mac\"" |
| 25 | echo "page in the Qt documentation for more information." |
| 26 | echo |
| 27 | echo "This script assumes you have already built the application bundle." |
| 28 | echo |
| 29 | echo -n "What is the name of the application? " |
| 30 | read userinput |
| 31 | APPNAME=$userinput |
| 32 | fi |
| 33 | |
| 34 | BUNDLE=$APPNAME.app |
| 35 | APPBIN="$BUNDLE/Contents/MacOS/$APPNAME" |
| 36 | |
| 37 | if [ ! -d $BUNDLE ] ; then |
| 38 | echo "ERROR: cannot find application bundle \"$BUNDLE\" in current directory" |
| 39 | exit |
| 40 | fi |
| 41 | |
| 42 | if [ ! -x $APPBIN ] ; then |
| 43 | echo "ERROR: cannot find application in bundle. Did you forget to run make?" |
| 44 | exit |
| 45 | fi |
| 46 | |
| 47 | echo "application: $APPNAME" |
| 48 | echo "bundle: $BUNDLE" |
| 49 | |
| 50 | ### query binary for frameworks ##################################### |
| 51 | |
| 52 | echo -n "Using frameworks" |
| 53 | for n in `otool -L $APPBIN | grep Qt` ; do |
| 54 | path=`echo $n | grep Qt` |
| 55 | if [ $path ] ; then |
| 56 | name=`basename $path` |
| 57 | FRAMEWORKS="$FRAMEWORKS $path" |
| 58 | echo -n " $name" |
| 59 | fi |
| 60 | done |
| 61 | echo |
| 62 | |
| 63 | ### make install #################################################### |
| 64 | |
| 65 | echo "Running make install" |
| 66 | if [ -e Makefile.Release ] ; then |
| 67 | make -f Makefile.Release install |
| 68 | elif [ -e Makefile ] ; then |
| 69 | make install |
| 70 | else |
| 71 | echo "ERROR: Makefile not found. This script requires the macx-g++ makespec" |
| 72 | fi |
| 73 | strip $APPBIN |
| 74 | |
| 75 | ### copy over frameworks ############################################ |
| 76 | |
| 77 | mkdir -p $BUNDLE/Contents/Frameworks |
| 78 | for path in $FRAMEWORKS ; do |
| 79 | name=`basename $path` |
| 80 | if [ ! -d "$FWPATH/$name.framework" ] ; then |
| 81 | echo "ERROR: cannot find $FWPATH/$name.framework" |
| 82 | exit |
| 83 | fi |
| 84 | echo "Copying $name framework" |
| 85 | cp -fR $FWPATH/$name.framework $BUNDLE/Contents/Frameworks |
| 86 | # strip libs (-x is max allowable for shared libs) |
| 87 | strip -x $BUNDLE/Contents/Frameworks/$name.framework/Versions/4/$name |
| 88 | done |
| 89 | |
| 90 | # remove unwanted parts |
| 91 | find $BUNDLE/Contents/Frameworks | egrep "debug|Headers" | xargs rm -rf |
| 92 | |
| 93 | ### set the identification names for frameworks ##################### |
| 94 | |
| 95 | echo -n "Setting framework IDs..." |
| 96 | |
| 97 | echo -n "Setting framework IDs..." |
| 98 | |
| 99 | for path in $FRAMEWORKS ; do |
| 100 | name=`basename $path` |
| 101 | echo -n " $name" |
| 102 | install_name_tool \ |
| 103 | -id @executable_path/../Frameworks/$name.framework/Versions/4/$name \ |
| 104 | $BUNDLE/Contents/Frameworks/$name.framework/Versions/4/$name |
| 105 | done |
| 106 | echo |
| 107 | |
| 108 | ### change framework paths ########################################## |
| 109 | |
| 110 | echo -n "Changing framework paths for $APPNAME..." |
| 111 | for path in $FRAMEWORKS ; do |
| 112 | name=`basename $path` |
| 113 | echo -n " $name" |
| 114 | install_name_tool \ |
| 115 | -change $path \ |
| 116 | @executable_path/../Frameworks/$name.framework/Versions/4/$name \ |
| 117 | $APPBIN |
| 118 | done |
| 119 | echo |
| 120 | |
| 121 | ### change location for bundled frameworks ######################### |
| 122 | |
| 123 | echo -n "Fixing bundled frameworks..." |
| 124 | for fwpath in $FRAMEWORKS ; do |
| 125 | fwname=`basename $fwpath` |
| 126 | echo -n " $fwname" |
| 127 | framework="$BUNDLE/Contents/Frameworks/$fwname.framework/Versions/4/$fwname" |
| 128 | # get framework dependencies |
| 129 | deps="" |
| 130 | for n in `otool -LX $framework | grep Qt` ; do |
| 131 | dep=`echo $n | grep Qt` |
| 132 | if [ $dep ] ; then |
| 133 | deps="$deps $dep" |
| 134 | fi |
| 135 | done |
| 136 | # fix dependency path |
| 137 | for path in $deps ; do |
| 138 | name=`basename $path` |
| 139 | if [ "$name" != "$fwname" ] ; then |
| 140 | install_name_tool \ |
| 141 | -change $path \ |
| 142 | @executable_path/../Frameworks/$name.framework/Versions/4/$name \ |
| 143 | $framework |
| 144 | fi |
| 145 | done |
| 146 | done |
| 147 | echo |
| 148 | |
| 149 | ### misc cleanup ############################################### |
| 150 | |
| 151 | find $BUNDLE/Contents | egrep "CVS" | xargs rm -rf |
| 152 | |
| 153 | ### create disk image ############################################### |
| 154 | |
| 155 | echo "Creating disk image" |
| 156 | imagedir="/tmp/$APPNAME.$$" |
| 157 | mkdir $imagedir |
| 158 | cp -R $BUNDLE $imagedir |
| 159 | |
| 160 | # TODO: copy over additional files, if any |
| 161 | hdiutil create -ov -srcfolder $imagedir -format UDBZ -volname "$APPNAME" "$APPNAME.dmg" |
| 162 | hdiutil internet-enable -yes "$APPNAME.dmg" |
| 163 | rm -rf $imagedir |
| 164 | |
| 165 | echo "Done" |