#! /bin/bash

# file: setup.sh

# This bash script performs any setup necessary in order to test your entry.
# It is run only once, before running any other code belonging to your entry.

# In this case, the code for the entry is a C program called 'gqrs.c', within
# the 'sources' subdirectory.  The command below compiles the C program into an
# executable binary named 'gqrs', linking it with the WFDB library.
set -e #this command means that as soon as any command fails, whole script fails
START_TIME=$SECONDS
echo "Running Setup script"
bin="bin"
echo "Checking for existence of 'bin' directory"
if [ -d $bin ]; then
  echo " * Removing existing 'bin' direcory"
  rm -rf $bin
fi

echo " * Creating empty 'bin' directory"
mkdir $bin

echo "Compiling math3"
javac -d "bin" -sourcepath "./sources/lib/commons-math3/" "sources/lib/commons-math3/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java"

echo "Compiling jcsv"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/CSVStrategy.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/reader/CSVReader.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/reader/internal/CSVReaderBuilder.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/reader/internal/DefaultCSVEntryParser.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/writer/CSVWriter.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/writer/internal/CSVWriterBuilder.java"
javac -d "$bin" -sourcepath "./sources/lib/jcsv/" "sources/lib/jcsv/com/googlecode/jcsv/writer/internal/DefaultCSVEntryConverter.java"


echo "Compiling Challenge2014"
javac -d "$bin" -sourcepath sources/src -cp "$bin" sources/src/cz/academyofscience/upt/challenge2014/Challenge2014.java



echo "Setup script done..."
echo " * Running time of setup.sh script: "$(($SECONDS - $START_TIME))"sec."
echo "------------------------------------------"

#cp ./sources/lib/ ./bin/lib/

# In your entry, you should replace the command above with one or more commands
# that compile your code if necessary, so that it can be run by 'next.sh'.  You
# may assume that the WFDB library is available and that it can be linked as in
# the example above.  Other standard libraries can be used similarly.  If your
# code requires any custom or non-standard libraries, include their sources in
# your entry, together with commands in this file to compile them.

# If your code is written in an interpreted language, it may not be necessary to
# perform any setup;  in this case, simply delete the command above.  Note,
# however, that 'setup.sh' must be included in your entry in any case;  if it
# is missing, or if running it causes an error, your entry will not be scored.
