| 1 | #!/bin/shscip-shell filesystem . . `/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 [scip-shell system . . `[`. ! -d $FWPATH/QtGui.framework ] ; then |
| 13 | echoscip-shell system . . echo. "ERROR: cannot find the Qt frameworks. Make sure Qt is installed" |
| 14 | echoscip-shell system . . echo. "and qmake is in your environment path." |
| 15 | exit |
| 16 | fi |
| 17 | |
| 18 | ### get required user input ######################################### |
| 19 | |
| 20 | if [scip-shell system . . `[`. -z $APPNAME ] ; then |
| 21 | echoscip-shell system . . echo. |
| 22 | echoscip-shell system . . echo. "This script prepares a Qt application bundle for deployment. It will" |
| 23 | echoscip-shell system . . echo. "copy over the required Qt frameworks and sets the installation" |
| 24 | echoscip-shell system . . echo. "identifications. Please see the \"Deploying an Application on Qt/Mac\"" |
| 25 | echoscip-shell system . . echo. "page in the Qt documentation for more information." |
| 26 | echoscip-shell system . . echo. |
| 27 | echoscip-shell system . . echo. "This script assumes you have already built the application bundle." |
| 28 | echoscip-shell system . . echo. |
| 29 | echoscip-shell system . . 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 [scip-shell system . . `[`. ! -d $BUNDLE ] ; then |
| 38 | echoscip-shell system . . echo. "ERROR: cannot find application bundle \"$BUNDLE\" in current directory" |
| 39 | exit |
| 40 | fi |
| 41 | |
| 42 | if [scip-shell system . . `[`. ! -x $APPBIN ] ; then |
| 43 | echoscip-shell system . . echo. "ERROR: cannot find application in bundle. Did you forget to run make?" |
| 44 | exit |
| 45 | fi |
| 46 | |
| 47 | echoscip-shell system . . echo. "application: $APPNAME" |
| 48 | echoscip-shell system . . echo. "bundle: $BUNDLE" |
| 49 | |
| 50 | ### query binary for frameworks ##################################### |
| 51 | |
| 52 | echoscip-shell system . . echo. -n "Using frameworks" |
| 53 | for n in `otool -L $APPBIN | grepscip-shell system . . grep. Qt` ; do |
| 54 | path=`echoscip-shell system . . echo. $n | grepscip-shell system . . grep. Qt` |
| 55 | if [scip-shell system . . `[`. $path ] ; then |
| 56 | name=`basenamescip-shell system . . basename. $path` |
| 57 | FRAMEWORKS="$FRAMEWORKS $path" |
| 58 | echoscip-shell system . . echo. -n " $name" |
| 59 | fi |
| 60 | done |
| 61 | echoscip-shell system . . echo. |
| 62 | |
| 63 | ### make install #################################################### |
| 64 | |
| 65 | echoscip-shell system . . echo. "Running make install" |
| 66 | if [scip-shell system . . `[`. -e Makefile.Release ] ; then |
| 67 | makescip-shell system . . make. -f Makefile.Release install |
| 68 | elif [scip-shell system . . `[`. -e Makefile ] ; then |
| 69 | makescip-shell system . . make. install |
| 70 | else |
| 71 | echoscip-shell system . . echo. "ERROR: Makefile not found. This script requires the macx-g++ makespec" |
| 72 | fi |
| 73 | stripscip-shell system . . strip. $APPBIN |
| 74 | |
| 75 | ### copy over frameworks ############################################ |
| 76 | |
| 77 | mkdirscip-shell system . . mkdir. -p $BUNDLE/Contents/Frameworks |
| 78 | for path in $FRAMEWORKS ; do |
| 79 | name=`basenamescip-shell system . . basename. $path` |
| 80 | if [scip-shell system . . `[`. ! -d "$FWPATH/$name.framework" ] ; then |
| 81 | echoscip-shell system . . echo. "ERROR: cannot find $FWPATH/$name.framework" |
| 82 | exit |
| 83 | fi |
| 84 | echoscip-shell system . . echo. "Copying $name framework" |
| 85 | cpscip-shell system . . cp. -fR $FWPATH/$name.framework $BUNDLE/Contents/Frameworks |
| 86 | # strip libs (-x is max allowable for shared libs) |
| 87 | stripscip-shell system . . strip. -x $BUNDLE/Contents/Frameworks/$name.framework/Versions/4/$name |
| 88 | done |
| 89 | |
| 90 | # remove unwanted parts |
| 91 | findscip-shell system . . find. $BUNDLE/Contents/Frameworks | egrepscip-shell system . . egrep. "debug|Headers" | xargsscip-shell system . . xargs. rm -rf |
| 92 | |
| 93 | ### set the identification names for frameworks ##################### |
| 94 | |
| 95 | echoscip-shell system . . echo. -n "Setting framework IDs..." |
| 96 | |
| 97 | echoscip-shell system . . echo. -n "Setting framework IDs..." |
| 98 | |
| 99 | for path in $FRAMEWORKS ; do |
| 100 | name=`basenamescip-shell system . . basename. $path` |
| 101 | echoscip-shell system . . 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 | echoscip-shell system . . echo. |
| 107 | |
| 108 | ### change framework paths ########################################## |
| 109 | |
| 110 | echoscip-shell system . . echo. -n "Changing framework paths for $APPNAME..." |
| 111 | for path in $FRAMEWORKS ; do |
| 112 | name=`basenamescip-shell system . . basename. $path` |
| 113 | echoscip-shell system . . echo. -n " $name" |
| 114 | install_name_tool \ |
| 115 | -change $path \ |
| 116 | @executable_path/../Frameworks/$name.framework/Versions/4/$name \ |
| 117 | $APPBIN |
| 118 | done |
| 119 | echoscip-shell system . . echo. |
| 120 | |
| 121 | ### change location for bundled frameworks ######################### |
| 122 | |
| 123 | echoscip-shell system . . echo. -n "Fixing bundled frameworks..." |
| 124 | for fwpath in $FRAMEWORKS ; do |
| 125 | fwname=`basenamescip-shell system . . basename. $fwpath` |
| 126 | echoscip-shell system . . 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 | grepscip-shell system . . grep. Qt` ; do |
| 131 | dep=`echoscip-shell system . . echo. $n | grepscip-shell system . . grep. Qt` |
| 132 | if [scip-shell system . . `[`. $dep ] ; then |
| 133 | deps="$deps $dep" |
| 134 | fi |
| 135 | done |
| 136 | # fix dependency path |
| 137 | for path in $deps ; do |
| 138 | name=`basenamescip-shell system . . basename. $path` |
| 139 | if [scip-shell system . . `[`. "$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 | echoscip-shell system . . echo. |
| 148 | |
| 149 | ### misc cleanup ############################################### |
| 150 | |
| 151 | findscip-shell system . . find. $BUNDLE/Contents | egrepscip-shell system . . egrep. "CVS" | xargsscip-shell system . . xargs. rm -rf |
| 152 | |
| 153 | ### create disk image ############################################### |
| 154 | |
| 155 | echoscip-shell system . . echo. "Creating disk image" |
| 156 | imagedir="/tmp/$APPNAME.$$" |
| 157 | mkdirscip-shell system . . mkdir. $imagedir |
| 158 | cpscip-shell system . . 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 | rmscip-shell system . . rm. -rf $imagedir |
| 164 | |
| 165 | echoscip-shell system . . echo. "Done" |