#!/bin/sh

# Haskell compile wrapper-script for 'compile.sh'.
# See that script for syntax and more info.

DEST="$1" ; shift
MEMLIMIT="$1" ; shift
MAINSOURCE="$1"

# Set non-existing HOME variable to make GHC program happy, see:
# https://ghc.haskell.org/trac/ghc/ticket/11678
export HOME=/does/not/exist
# Allow temporary files during compilation, this directory is not
# available during the submission run.
export TMPDIR="$PWD"

# Add -DONLINE_JUDGE or -DDOMJUDGE below if you want it make easier for teams
# to do local debugging.

# -x hs:    Explicitly only allow Haskell source (no object files or
#           other intermediate files autodetected by extension, also
#           disables literate Haskell (.lhs) files)
# -Wall:    Report all warnings
# -O:       Optimize
# -static:  Static link Haskell libraries
# -optl-static:  Pass '-static' option to the linker
# -optl-pthread: Pass '-pthread' option to the linker (see Debian bug #593402)
ghc -x hs -Wall -Wwarn -O -static -optl-static -optl-pthread -o "$DEST" "$@"
exitcode=$?

# clean created files:
rm -f "$DEST.o" Main.hi

exit $exitcode
