#!/bin/sh
# Copyright 2009 Jeremy Thurgood <firxen+rinkhals@gmail.com>
# GPL - see COPYING for details
#
# Usage: darwin-py2app

GAME_NAME="nine-tales"

NT_VERSION=`sed -ne 's/VERSION_STR = "\(.*\)"/\1/p' setup.py`
BUILD_NAME="${GAME_NAME}-${NT_VERSION}"
BUILD_FOLDER="build/${GAME_NAME}"
DMG_NAME="${BUILD_NAME}.dmg"
PY2APP_LOG="py2app.log"

BASEDIR=`pwd`

echo "=== Setting up build environment ==="

./scripts/build_unix.sh
cp run_game.py ${BUILD_FOLDER}

cd ${BUILD_FOLDER}

# find data -name '*.svg' -delete

echo ""
echo "=== Running python setup.py ==="
echo "  Nine Tales version: ${NT_VERSION}"
echo "  Writing log to ${PY2APP_LOG}"

python setup.py py2app >${PY2APP_LOG} 2>&1

echo ""
echo "=== Removing useless cruft that just takes up space ==="
echo ""

for dir in docs examples tests; do
    find "dist/" -path "*/Resources/lib/*/pygame/${dir}/*" -delete
done

echo "=== Building DMG ==="
echo ""

cd ${BASEDIR}

pwd
rm dist/${DMG_NAME} > /dev/null
hdiutil create -srcfolder ${BUILD_FOLDER}/dist/*.app/ dist/${DMG_NAME}

echo ""
echo "=== Done ==="
echo ""
du -sh dist/* | sed 's/^/   /'
echo ""

