#!/bin/bash
set -e

cd "$(dirname $0)/.."
LUANHOME="$(pwd)"

rm -rf build
mkdir -p build/luan/jars
cp lib/* build/luan/jars

find . -name *.class -delete

. $LUANHOME/classpath.sh

cd "$LUANHOME/src"
javac -classpath "$CLASSPATH" $(find . -name *.java)
jar cvf "$LUANHOME/build/luan/jars/luan.jar" $(find . -name *.class -o -name *.luan)

cd $LUANHOME/slf4j/src
javac -classpath "$CLASSPATH" $(find . -name *.java)
jar cvf "$LUANHOME/build/luan/jars/slf4j-goodjava.jar" $(find . -name *.class -o -name *.luan)

cd "$LUANHOME"
cp scripts/luan.sh build/luan
cp scripts/install.sh build/luan
cp scripts/uninstall.sh build/luan
hg identify >build/luan/hg_rev.txt

cd build
tar -cf "$LUANHOME/website/src/download/luan.tar" luan

luan/install.sh || sudo luan/install.sh

echo done
