#!/bin/bash

this_dir=`dirname "$0"`

# 1st arg is app subdir name
app=$1
shift
echo "Compiling application $app"

# Assume our current directory is the main I-X dir

sources=apps/$app/java
imports=apps/$app/imports

# Get source files enclosed in double quotes in case they contain spaces.

source_files=`find $sources -name \*.java  -exec echo \"{}\" \;`

echo sources files: $source_files
echo imports: $imports/*.jar

# Assume ix.jar will bring in all normal imports.

cpath=$sources:ix.jar
cpath=$cpath:`echo $imports/*.jar | tr " " ":"`

# Add some other popular imports

cpath=$cpath:apps/addon/map/imports/openmap.jar
cpath=$cpath:apps/addon/map/java

cpath=$cpath:comms/jabber/imports/jabberbeans.jar
cpath=$cpath:comms/jabber/java

# Define JAVA with suitable parameters

. $this_dir/javac-setvars

# /\/ I have no idea why we can't just execute the command.

echo ${JAVAC} -cp $cpath:$CLASSPATH $source_files > /tmp/compile
chmod +x /tmp/compile
/tmp/compile

