release.macx.sh 7.65 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
#!/bin/bash
Claudio Valerio's avatar
Claudio Valerio committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# --------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------

17

18
APPLICATION_NAME="OpenBoard"
19
BASE_TROLLTECH_DIRECTORY=/usr/local/Trolltech/Qt-4.8.0
Claudio Valerio's avatar
Claudio Valerio committed
20
# Executables
21 22
QMAKE=$BASE_TROLLTECH_DIRECTORY/bin/qmake
MACDEPLOYQT=$BASE_TROLLTECH_DIRECTORY/bin/macdeployqt
23
DMGUTIL="`pwd`/../Sankore-ThirdParty/refnum/dmgutil/dmgutil.pl"
Claudio Valerio's avatar
Claudio Valerio committed
24 25 26
DSYMUTIL=/usr/bin/dsymutil
STRIP=/usr/bin/strip
PLISTBUDDY=/usr/libexec/PlistBuddy
Claudio Valerio's avatar
Claudio Valerio committed
27
ICEBERG=/usr/local/bin/freeze
28
LRELEASE=$BASE_TROLLTECH_DIRECTORY/bin/lrelease
Claudio Valerio's avatar
Claudio Valerio committed
29 30 31 32

# Directories
BUILD_DIR="build/macx/release"
PRODUCT_DIR="$BUILD_DIR/product"
33
BASE_QT_TRANSLATIONS_DIRECTORY=../Qt4.8/translations
Claudio Valerio's avatar
Claudio Valerio committed
34 35 36 37

function notify {
    GROWLNOTIFY=`which growlnotify`
    if [ -x "$GROWLNOTIFY" ]; then
38
        $GROWLNOTIFY --name OpenBoard-build --iconpath /Developer/Applications/Xcode.app --message "$1" "OpenBoard"
Claudio Valerio's avatar
Claudio Valerio committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    fi
    printf "\033[32m--->\033[0m $1\n"
}

function abort {
    printf "\033[31merror:\033[0m $1\n"
    exit 1
}

function warn {
    abort "$1"
}

function checkExecutable {
    if [ ! -x "$1" ]; then
        abort "$1 not found"
    fi
}

58 59 60 61 62
function addQtTranslations {
for eachTranslation in `ls $BASE_QT_TRANSLATIONS_DIRECTORY/qt_??.qm`
do
    # looking fo the language code for each qt translation file
    languageCode=`echo $eachTranslation | sed 's/.*qt_\(.*\).qm/\1/'`
63
    basicDir=$PRODUCT_DIR/$APPLICATION_NAME.app/Contents/Resources/
64 65
    for eachDirectory in `ls $basicDir`
    do
66
        # looping through the OpenBoard availables languages
67 68 69
        directoryLanguageCode=`echo $eachDirectory | sed 's/\(.*\)\.lproj/\1/'`
        if [ ! -z $directoryLanguageCode ]; then
            if [[ $eachDirectory == *".lproj"* && $eachDirectory != "empty.lproj" && $directoryLanguageCode == *$languageCode* ]]; then
70
                # OpenBoard translation found for qt translation file
71 72 73 74 75 76 77 78 79 80 81 82
                cp $eachTranslation $basicDir/$eachDirectory
                if [ $directoryLanguageCode != $languageCode ]; then
                    # handling fr and fr_CH code.
                    mv $basicDir/$eachDirectory/qt_$languageCode.qm $basicDir/$eachDirectory/qt_$directoryLanguageCode.qm
                fi
            fi
        fi
    done
done

}

83 84 85 86 87 88 89 90 91 92

function addImporter {
    importerDir="`pwd`/../OpenSankoreToOpenBoard"
    importerName="OpenBoardImporter"

    if [ ! -e ${importerDir} ]; then
        abort "${importerDir} not found"
    fi

    cd ${importerDir}
93 94 95 96
    git reset --hard
    git pull
    rm -rf ${importerName}.app
    rm MakeFile*
97 98
    rm -rf release
    rm -rf debug
99
    $QMAKE ${importerName}.pro
100
    make -j4 release
101 102 103 104
    $MACDEPLOYQT ${importerName}.app 
    cd -
}

105
trap "defaults write org.oe-f.OpenBoard.release Running -bool NO" EXIT
Claudio Valerio's avatar
Claudio Valerio committed
106

107
notify "Running OpenBoard release script (`date`)"
Claudio Valerio's avatar
Claudio Valerio committed
108

109
script_is_running=`defaults read org.oe-f.OpenBoard.release Running 2>/dev/null`
Claudio Valerio's avatar
Claudio Valerio committed
110 111 112 113
if [[ $? -eq 0 ]] && [[ "$script_is_running" = "1" ]]; then
    trap EXIT
    abort "another release script already running"
fi
114
defaults write org.oe-f.OpenBoard.release Running -bool YES
Claudio Valerio's avatar
Claudio Valerio committed
115 116 117 118 119 120 121 122

# Check for executables
checkExecutable "$QMAKE"
checkExecutable "$MACDEPLOYQT"
checkExecutable "$DMGUTIL"
checkExecutable "$DSYMUTIL"
checkExecutable "$STRIP"
checkExecutable "$PLISTBUDDY"
Claudio Valerio's avatar
Claudio Valerio committed
123
checkExecutable "$ICEBERG"
124
checkExecutable "$LRELEASE"
Claudio Valerio's avatar
Claudio Valerio committed
125

126 127
addImporter

Claudio Valerio's avatar
Claudio Valerio committed
128 129 130 131
# delete the build directory
notify "Cleaning ..."
rm -rf "$BUILD_DIR"

132 133
# application translations
notify "Generating applications translatons"
134
$LRELEASE "$APPLICATION_NAME.pro"
135

Claudio Valerio's avatar
Claudio Valerio committed
136 137 138
# generate Makefiles
notify "Generating Makefile ..."

139
QMAKE_CMD="$QMAKE $APPLICATION_NAME.pro -spec macx-g++"
Claudio Valerio's avatar
Claudio Valerio committed
140 141 142

$QMAKE_CMD

shibakaneki's avatar
shibakaneki committed
143 144 145 146
# build
notify "Compiling ..."
make -j4 release

147
notify "Qt Translations ..."
148
$LRELEASE $BASE_QT_TRANSLATIONS_DIRECTORY/translations.pro 
149 150
addQtTranslations

151
cp -R resources/customizations $PRODUCT_DIR/$APPLICATION_NAME.app/Contents/Resources
152
cp -R $importerDir/$importerName.app $PRODUCT_DIR/$APPLICATION_NAME.app/Contents/Resources
153

Claudio Valerio's avatar
Claudio Valerio committed
154
VERSION=`cat "$BUILD_DIR/version"`
shibakaneki's avatar
shibakaneki committed
155
if [ ! -f "$BUILD_DIR/version" ]; then
156 157 158
    echo "version not found"
    exit 1
else
Claudio Valerio's avatar
Claudio Valerio committed
159
    notify "Tagging ..."
160 161 162
    LAST_COMMITED_VERSION="`git describe $(git rev-list --tags --max-count=1)`"
    if [ "v$VERSION" != "$LAST_COMMITED_VERSION" ]; then
	echo creating a tag with the version $VERSION
163 164
#	git tag -a "v$VERSION" -m "Generated setup for v$VERSION"
#	git push origin --tags
165
    fi
Claudio Valerio's avatar
Claudio Valerio committed
166
fi
167
  
168 169 170
if [ $? != 0 ]; then
    abort "compilation failed"
fi
Claudio Valerio's avatar
Claudio Valerio committed
171 172


173 174 175 176
DMG="$APPLICATION_NAME.dmg"
VOLUME="/Volumes/$APPLICATION_NAME"
APP="$PRODUCT_DIR/$APPLICATION_NAME.app"
DSYM_NAME="$APPLICATION_NAME (r$SVN_REVISION).dSYM"
Claudio Valerio's avatar
Claudio Valerio committed
177
DSYM="$PRODUCT_DIR/$DSYM_NAME"
178
GSYM_i386="$PRODUCT_DIR/$APPLICATION_NAME i386.sym"
Claudio Valerio's avatar
Claudio Valerio committed
179 180 181 182 183
INFO_PLIST="$APP/Contents/Info.plist"

rm -f "$APP/Contents/Resources/empty.lproj"

# set various version infomration in Info.plist
Claudio Valerio's avatar
Claudio Valerio committed
184
$PLISTBUDDY -c "Set :CFBundleVersion $VERSION" "$INFO_PLIST"
Claudio Valerio's avatar
Claudio Valerio committed
185
$PLISTBUDDY -c "Set :CFBundleShortVersionString $VERSION" "$INFO_PLIST"
186
$PLISTBUDDY -c "Set :CFBundleGetInfoString $APPLICATION_NAME" "$INFO_PLIST"
Claudio Valerio's avatar
Claudio Valerio committed
187 188 189

# bundle Qt Frameworks into the app bundle
notify "Bulding frameworks ..."
Claudio Valerio's avatar
Claudio Valerio committed
190
cd "`pwd`/build/macx/release/product/"
191
$MACDEPLOYQT "`pwd`/$APPLICATION_NAME.app"
Claudio Valerio's avatar
Claudio Valerio committed
192
cd -
Claudio Valerio's avatar
Claudio Valerio committed
193 194

notify "Extracting debug information ..."
195 196
$DSYMUTIL "$APP/Contents/MacOS/$APPLICATION_NAME" -o "$DSYM"
$STRIP -S "$APP/Contents/MacOS/$APPLICATION_NAME"
Claudio Valerio's avatar
Claudio Valerio committed
197

Claudio Valerio's avatar
Claudio Valerio committed
198
if [ "$1" == "pkg" ]; then
199
    BASE_ICEBERG_CONFIG_FILE="$APPLICATION_NAME.packproj"
200
    #copy the standard file for working with
201
    ICEBERG_CONFIG_FILE="$APPLICATION_NAME-working.packproj"
202
    cp -r $BASE_ICEBERG_CONFIG_FILE $ICEBERG_CONFIG_FILE
Claudio Valerio's avatar
Claudio Valerio committed
203 204 205 206 207 208 209 210 211 212 213 214 215
    # set version information
    $PLISTBUDDY -c "Set :Hierarchy:Attributes:Settings:Description:International:IFPkgDescriptionVersion $VERSION" "$ICEBERG_CONFIG_FILE"
    $PLISTBUDDY -c "Set :Hierarchy:Attributes:Settings:Display\ Information:CFBundleShortVersionString $VERSION" "$ICEBERG_CONFIG_FILE"
    $PLISTBUDDY -c "Set :Hierarchy:Attributes:Settings:Version:IFMajorVersion `echo $VERSION | awk 'BEGIN { FS = "." }; { print $1 }'`" "$ICEBERG_CONFIG_FILE"
    $PLISTBUDDY -c "Set :Hierarchy:Attributes:Settings:Version:IFMinorVersion `echo $VERSION | awk 'BEGIN { FS = "." }; { print $2 }'`" "$ICEBERG_CONFIG_FILE"


    PRODUCT_DIR="install/mac/"

    if [ ! -d "${PRODUCT_DIR}" ]; then
	mkdir -p "${PRODUCT_DIR}"
    fi
    $ICEBERG $ICEBERG_CONFIG_FILE 
216 217 218 219

    #clean up mess
    rm -rf $ICEBERG_CONFIG_FILE

Claudio Valerio's avatar
Claudio Valerio committed
220 221 222
    exit 0
fi

Claudio Valerio's avatar
Claudio Valerio committed
223 224
notify "Creating dmg ..."
umount "$VOLUME" 2> /dev/null
225
$DMGUTIL --open --volume="$APPLICATION_NAME" "$DMG"
Claudio Valerio's avatar
Claudio Valerio committed
226

227
#cp *.pdf "$VOLUME"
Claudio Valerio's avatar
Claudio Valerio committed
228 229 230
cp -R "$APP" "$VOLUME"
ln -s /Applications "$VOLUME"

231
$DMGUTIL --set --iconsize=96 --toolbar=false --icon=resources/macx/OpenBoard.icns "$VOLUME"
Claudio Valerio's avatar
Claudio Valerio committed
232 233 234
$DMGUTIL --set --x=20 --y=60 --width=580 --height=440 "$VOLUME"
$DMGUTIL --set --x=180 --y=120 "$VOLUME/`basename \"$APP\"`"
$DMGUTIL --set --x=400 --y=120 "$VOLUME/Applications"
235
#$DMGUTIL --set --x=180 --y=280 "$VOLUME/ReleaseNotes.pdf"
Claudio Valerio's avatar
Claudio Valerio committed
236

237
$DMGUTIL --close --volume="$APPLICATION_NAME" "$DMG"
Claudio Valerio's avatar
Claudio Valerio committed
238

239
notify "$APPLICATION_NAME is built"
Claudio Valerio's avatar
Claudio Valerio committed
240 241 242 243 244 245 246 247 248 249 250

PRODUCT_DIR="install/mac/"

if [ ! -d "${PRODUCT_DIR}" ]; then
    mkdir -p "${PRODUCT_DIR}"
fi

mv "$DMG" "${PRODUCT_DIR}"

exit 0