#!/bin/sh
#  This program should be in the Isight installation's examples/development/applications directory.
#compile application development examples

# ---------------------------------------------------------------------
# *** IMPORTANT *** 
# The Java compiler must be of correct version. Please refer
# "Application Development - Environment Setup" section of the 
# Development Guide, to know the required Java compiler version.
# ---------------------------------------------------------------------

if [ "$JAVA_JDK" = "" ]; then
	echo "JAVA_JDK is not defined"
	exit 1
fi


if [ $# = 0 ]
then
	echo 'Usage: compileExample [Example name]'
	exit 1
fi

#---------------------------------------------------------------------
# Confirm installation of JAVA compiler under JAVA_JDK
# and of Isight under FIPER_HOME
#---------------------------------------------------------------------
if [ ! -f "$JAVA_JDK/bin/javac" ]; then
    echo "The environment variable JAVA_JDK must point to a Java JDK with a java compiler in the bin directory"
    exit 1
fi


# set the logical directory as if we were run from FIPER_HOME/code/command prior to
# sourcing fiperenv.  if you are compiling or running the examples outside of the
# FIPER_HOME/examples directory you will need to modify the following line to point
# to where FIPER_HOME is installed 
# ---- OR ----
#
if [ "$FIPER_HOME" = "" ]; then
    # this assumes that this examples directory is within the FIPER_HOME/examples directory structure
	dir=`cd "../../../code/command"; /bin/pwd`
else 
    # this allows to user to copy the examples directory to a new location, provided they supply
    # the correct value for FIPER_HOME
	dir=`cd "$FIPER_HOME/code/command"; /bin/pwd`
fi

# sets FIPER_HOME (assuming $dir points to the FIPER_HOME/code/command directory)
. "$dir/fiperenv"

if [ ! -f $FIPER_HOME/docs/java/SMAFIPsdk.jar ]; then
    echo "The environment variable FIPER_HOME must point to an Isight installation"
    echo "Either unset the variable or set it to point to the correct directory"
    exit 1
fi


clspath="$FIPER_HOME/docs/java/SMAFIPsdk.jar:$FIPER_HOME/docs/java/SMAFIPdesktopSDK.jar:$FIPER_HOME"
pgm=../../../examples/development/applications/$1.java

$JAVA_JDK/bin/javac -classpath $clspath $pgm
