#!/bin/sh
glilang=en

echo
if [ "$glilang" = "es" ]; then
    echo "Interfaz de la Biblioteca Digital Greenstone (Greenstone Librarian Interface - GLI)"
    echo "Copyright (C) 2008, New Zealand Digital Library Project, University Of Waikato"
    echo "La Interfaz de la Biblioteca Digital Greenstone NO INCLUYE ABSOLUTAMENTE NINGUNA GARANTÍA."
    echo "Para mayor información vea los términos de la licencia en LICENSE.txt"
    echo "Este es un software abierto, por lo que lo invitamos a que lo distribuya de forma gratuita"
elif [ "$glilang" = "fr" ]; then
    echo "Interface du Bibliothécaire Greenstone (Greenstone Librarian Interface - GLI)"
    echo "Copyright (C) 2008, New Zealand Digital Library Project, University Of Waikato"
    echo "GLI est fourni sans AUCUNE GARANTIE; pour des détails, voir LICENSE.txt"
    echo "Ceci est un logiciel libre, et vous êtes invité à le redistribuer"
elif [ "$glilang" = "ru" ]; then
    echo "âÉÂÌÉÏÔÅÞÎÙÊ ÉÎÔÅÒÆÅÊÓ Greenstone (Greenstone Librarian Interface - GLI)"
    echo "Copyright (C) 2008, New Zealand Digital Library Project, University Of Waikato"
    echo "âéç ÎÅ ÄÁÅÔ áâóïìàôîï îéëáëéè çáòáîôéê; ÄÅÔÁÌÉ ÓÍ. × ÔÅËÓÔÅ LICENSE.TXT"
    echo "üÔÏ - Ó×ÏÂÏÄÎÏ ÒÁÓÐÒÏÓÔÒÁÎÑÅÍÏÅ ÐÒÏÇÒÁÍÍÎÏÅ ÏÂÅÓÐÅÞÅÎÉÅ É ÷Ù ÍÏÖÅÔÅ ÒÁÓÐÒÏÓÔÒÁÎÑÔØ ÅÇÏ"
else
    echo "Greenstone Librarian Interface (GLI)"
    echo "Copyright (C) 2008, New Zealand Digital Library Project, University Of Waikato"
    echo "GLI comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt"
    echo "This is free software, and you are welcome to redistribute it"
fi
echo

##  -------- Compile the Greenstone Librarian Interface --------

## ---- Check Javac exists ----
javacpath=

# Some users may set the above line manually
if [ "x$javacpath" = "x" ]; then

    # If the JAVAC environment variable is set then use it
    if [ "x$JAVAC" != "x" ] ; then
	javacpath=$JAVAC
    # If it is set, use the JAVA_HOME environment variable
    elif [ "x$JAVA_HOME" != "x" ]; then
	javacpath="$JAVA_HOME/bin/javac"
    # Check if Javac is on the search path
    else
	javacpath=`which javac 2> /dev/null`
    fi
fi

if [ "xJAVACFLAGS" = "x" ] ; then
    JAVACFLAGS="-source 1.4 -target 1.4"
fi

# Check that a Javac executable has been found
if [ "$glilang" = "es" ]; then
    echo "Revisando Javac: $javacpath"
elif [ "$glilang" = "fr" ]; then
    echo "Vérification de Javac: $javacpath"
elif [ "$glilang" = "ru" ]; then
    echo "ðÒÏ×ÅÒËÁ Javac: $javacpath"
else
    echo "Checking Javac: $javacpath"
fi
if [ ! -x "$javacpath" ]; then
    echo
    if [ "$glilang" = "es" ]; then
	echo "No se pudo localizar una versión apropiada de Javac."
	echo "Por favor instale una nueva versión del Kit de Desarrollo de"
	echo "Software Java (versión 1.4 o posterior) y ejecute nuevamente"
	echo "este guión."
    elif [ "$glilang" = "fr" ]; then
	echo "Une version appropriée de Javac n'a pas pu être localisée."
	echo "Veuillez installer une nouvelle version de Java SDK (version 1.4 ou"
	echo "plus récente) et redémarrez ce script."
    elif [ "$glilang" = "ru" ]; then
	echo "îÅ ÕÄÁÌÏÓØ ÏÐÒÅÄÅÌÉÔØ ÍÅÓÔÏÎÁÈÏÖÄÅÎÉÅ ÓÏÏÔ×ÅÔÓÔ×ÕÀÝÅÊ ×ÅÒÓÉÉ Javac."
	echo "ðÏÖÁÌÕÊÓÔÁ, ÕÓÔÁÎÏ×ÉÔÅ ÎÏ×ÕÀ ×ÅÒÓÉÀ Java SDK (×ÅÒÓÉÀ 1.4 ÉÌÉ ÂÏÌÅÅ"
	echo "ÎÏ×ÕÀ) É ÐÅÒÅÕÓÔÁÎÏ×ÉÔÅ ÜÔÏÔ ÓËÒÉÐÔ."
    else
	echo "Failed to locate an appropriate version of Javac. You must install a"
	echo "Java Development Kit (version 1.4 or greater) before compiling the"
	echo "Greenstone Librarian Interface."
    fi
    exit 1
fi

## ---- Compile the GLI ----

# If a file has been specified at the command-line, just compile that file
if [ ! "x$*" = "x" ] ; then
    echo
    if [ "$glilang" = "es" ]; then
	echo "Compilando $* y clases dependientes..."
    elif [ "$glilang" = "fr" ]; then
	echo "Compilation de $* et des classes dépendantes,,,"
    elif [ "$glilang" = "ru" ]; then
	echo "ëÏÍÐÉÌÉÒÏ×ÁÎÉÅ $* É ÚÁ×ÉÓÉÍÙÅ ËÌÁÓÓÙ..."
    else
	echo "Compiling $* and dependent classes..."
    fi

    $javacpath $JAVACFLAGS -deprecation -d classes/ -sourcepath src/ -classpath classes/:lib/apache.jar:lib/qfslib.jar $*

    if [ "$glilang" = "es" ]; then
	echo "¡Hecho!"
    elif [ "$glilang" = "fr" ]; then
	echo "Terminé!"
    elif [ "$glilang" = "ru" ]; then
	echo "÷ÙÐÏÌÎÅÎÏ!"
    else
	echo "Done!"
    fi
    exit 0
fi

# Otherwise compile the lot...

# Remove any existing class files first
./clean.sh

if [ "$glilang" = "es" ]; then
    echo "Compilando la Interfaz de la Biblioteca Digital Greenstone..."
elif [ "$glilang" = "fr" ]; then
    echo "Compilation de Greenstone Librarian Interface,,,"
elif [ "$glilang" = "ru" ]; then
    echo "ëÏÍÐÉÌÉÒÏ×ÁÎÉÅ ÂÉÂÌÉÏÔÅÞÎÏÇÏ ÉÎÔÅÒÆÅÊÓÁ Greenstone..."
else
    echo "Compiling the Greenstone Librarian Interface..."
fi

# Compile the GLI
$javacpath $JAVACFLAGS -deprecation -d classes/ -sourcepath src/ -classpath classes/:lib/apache.jar:lib/qfslib.jar src/org/greenstone/gatherer/GathererProg.java
$javacpath $JAVACFLAGS -deprecation -d classes/ -sourcepath src/ -classpath classes/:lib/apache.jar:lib/qfslib.jar src/org/greenstone/gatherer/GathererApplet.java
#$javacpath -deprecation -d classes/ -sourcepath src/ -classpath classes/:lib/apache.jar:lib/qfslib.jar src/org/greenstone/gatherer/GathererApplet4gs3.java
# Compile the GEMS
$javacpath -deprecation -d classes/ -sourcepath src/ -classpath classes/:lib/apache.jar:lib/qfslib.jar src/org/greenstone/gatherer/gems/GEMS.java

# Compile the standalone programs needed on the server for remote building
$javacpath $JAVACFLAGS -deprecation -d classes/ -sourcepath src/ -classpath classes/ src/org/greenstone/gatherer/remote/Zip*.java
$javacpath $JAVACFLAGS -deprecation -d classes/ -sourcepath src/ -classpath classes/ src/org/greenstone/gatherer/remote/Unzip.java

if [ "$glilang" = "es" ]; then
    echo "¡Hecho!"
elif [ "$glilang" = "fr" ]; then
    echo "Terminé!"
elif [ "$glilang" = "ru" ]; then
    echo "÷ÙÐÏÌÎÅÎÏ!"
else
    echo "Done!"
fi
