#!/bin/sh
# $Id: fpc.in 6701 2012-03-30 07:20:13Z cher $
# Copyright (c) 2002-2012 Alexander Chernov <cher@ejudge.ru>

# using EJUDGE_FLAGS we may pass additional flags

LANG_CONFIG_DIR="/home/judges/compile/conf/lang.d"
[ "${EJUDGE_LANG_CONFIG}" = "" ] && EJUDGE_LANG_CONFIG="${LANG_CONFIG_DIR}/fpc.cfg"

if [ -f "${EJUDGE_LANG_CONFIG}" ]
then
  . "${EJUDGE_LANG_CONFIG}"
else
  version="unknown"
  FPCRUN="fpc"
  FPCDIR=
fi

if [ x"${version}" = x ]
then
  echo "This language is not supported." >&2
  exit 1
fi

if [ x"${FPCDIR}" != x ]
then
    PATH="${FPCDIR}:${PATH}"
fi

unset LANG
unset LC_ALL
unset LC_MESSAGES
unset LANGUAGE

"${FPCRUN}" ${EJUDGE_FLAGS} -XS "$1" "-o$2"

#if the output file is not created - compile error
[ -f "$2" ] || exit 1
exit 0