#!/bin/bash

# compile.sh
# Andrew Davison, ad@fivedots.coe.psu.ac.th, Feb. 2023

if [ "$1" = "" ]
then
  echo "No file name supplied"
  exit 1
fi

# echo "${1#*.}"
if [ "${1#*.}" != "java" ] 
then
  echo "Not a Java file"
  exit 1
fi

# assume the Jars are in libs folder
libs="libs/"
if ! [ -e $libs ]
then
  echo "No libs folder found"
  exit 1
fi

path="$(pwd)"
# echo "$path"
# useful with java's -Djava.library.path

echo "Using:"
for f in $(ls $libs) 
do
  echo "  $f"
done

echo "Compiling $@..."
# echo -e "\n"

javac --release 11 -Xlint:unchecked -Xlint:deprecation  \
 -implicit:class  \
 -cp "$libs/*:." "$@"

echo "Finished."


