#!/bin/sh
#
# Copyright (c) 2003-2012 Pixware SARL. All rights reserved.
#
# This file is part of the XMLmind XML Editor project.
# For conditions of distribution and use, see the accompanying legal.txt file.

appName="XMLEditor"
creator="XMXE"

# Comes from MacOSX 10.5/Java 1.5. 
# Tested on MacOSX 10.5, 10.6, 10.7, 10.8 with Java 1.6.
stub=./JavaApplicationStub

if [ ! -f "$stub" ]; then
    echo "$0: Do not find $stub. Cannot create application bundle."
    exit 2
fi

xxeIcons=../icon/xxe.icns
if [ ! -f "$xxeIcons" ]; then
    echo "$0: Do not find $xxeIcons. Cannot create application bundle."
    exit 3
fi

bbit=/Developer/Tools/SetFile
if [ ! -f "$bbit" ]; then
    bbit=/Applications/Xcode.app/Contents/Developer/Tools/SetFile
    if [ ! -f "$bbit" ]; then
        echo "$0: Do not find $bbit. Cannot create application bundle."
        exit 4
    fi
fi

app="../../$appName.app"
echo "$0: Creating $app (next to bin/)..."
rm -rf "$app"
mkdir "$app"
mkdir "$app/Contents"
mkdir "$app/Contents/MacOS"
mkdir "$app/Contents/Resources"
mkdir "$app/Contents/Resources/Java"

cp Info.plist "$app/Contents"
echo "APPL$creator" > "$app/Contents/PkgInfo"

cp "$stub" "$app/Contents/MacOS"

cp "$xxeIcons" "$app/Contents/Resources/xxe.icns"

mkdir "$app/Contents/Resources/cs.lproj"
mkdir "$app/Contents/Resources/de.lproj"
mkdir "$app/Contents/Resources/en.lproj"
mkdir "$app/Contents/Resources/es.lproj"
mkdir "$app/Contents/Resources/fi.lproj"
mkdir "$app/Contents/Resources/fr.lproj"
###mkdir "$app/Contents/Resources/it.lproj"
mkdir "$app/Contents/Resources/pl.lproj"
mkdir "$app/Contents/Resources/pt.lproj"
mkdir "$app/Contents/Resources/ru.lproj"

echo "$0: Copying all bin/ files to $app/Contents/Resources/Java..."
cp -r ../* "$app/Contents/Resources/Java"
rm -rf "$app/Contents/Resources/Java/mac"

"$bbit" -a B "$app"

echo "$0: Application bundle has been created in $app."
echo "$0: You can now remove bin/ because its content has been copied to"
echo "$0: $app/Contents/Resources/Java/."
echo "$0: Then create disk image xxe-xxx-NNN.dmg out of xxe-xxx-NNN/"
echo "$0: (containing addon/, demo/, doc/, legal/, legal.txt, $appName.app/)."
exit 0
