#!/bin/sh # $Id: ghc-version.in 6904 2012-06-21 12:22:32Z cher $ # Copyright (c) 2011-2012 Alexander Chernov # compiler script interface is as follows # -version [OPTION] # OPTION is: # -r P fully check the availability of the compiler (like configure # script does). P is a proposed path to the compiler (like in # --with- configure option). # returns failure (exit code 1), if the compiler is not available # or is not functional. # in case of success exit code is 0, and the necessary configuration # variables are written to stdout. # -v verbose operation (configure mode) # -l output the compiler name to the stdout (list mode) # -p write to the stdout the command line of the compiler # -f write the compiler full name and the compiler version LANG_CONFIG_DIR="/home/judges/compile/conf/lang.d" common_config() { echo 'long_name="The Glasgow Haskell Compiler"' echo 'src_sfx=".hs"' echo 'arch="linux-shared"' # echo 'insecure=1' } failure() { rm -f conftest* echo 'version=' echo 'arg="'"${arg}"'"' common_config echo 'GHCRUN=false' echo 'GHCDIR=' [ "${verbose}" = 1 ] && echo "no" >&2 exit 1 } unset LANG unset LC_ALL unset LC_MESSAGES unset LANGUAGE if [ x"$1" = x-v ] then verbose=1 shift fi # recheck the language if [ x"$1" = x-r ] then arg="$2" [ x"$2" != x ] && GHCRUN="$2" [ "${GHCRUN}" = "" ] && GHCRUN="ghc" [ "${verbose}" = 1 ] && echo -n "checking whether GHC is available... " >&2 "${GHCRUN}" --version >/dev/null 2>&1 || failure version=`"${GHCRUN}" --version 2>&1 | grep "version" | gawk '{ print $8; }'`|| failure cat > conftest.hs </dev/null 2>&1 || failure [ -x conftest ] || failure ./conftest >/dev/null 2>&1 || failure rm -f ./conftest* GHCDIR=`dirname "${GHCRUN}"` [ "${GHCDIR}" = . ] && GHCDIR="" echo 'version="'"${version}"'"' echo 'arg="'"${arg}"'"' common_config echo 'GHCRUN="'"${GHCRUN}"'"' echo 'GHCDIR="'"${GHCDIR}"'"' [ "${verbose}" = 1 ] && echo "yes, ${GHCRUN}, ${version}" >&2 exit 0 fi if [ x"$1" = x-l ] then echo "The Glasgow Haskell [http://haskell.org/ghc]" exit 0 fi [ "${EJUDGE_LANG_CONFIG}" = "" ] && EJUDGE_LANG_CONFIG="${LANG_CONFIG_DIR}/ghc.cfg" if [ -f "${EJUDGE_LANG_CONFIG}" ] then . "${EJUDGE_LANG_CONFIG}" else GHCRUN="ghc" GHCDIR= fi if [ x"${GHCRUN}" = x -o x"${GHCRUN}" = xfalse ] then echo "This language is not supported." >&2 exit 1 fi if [ x"${GHCDIR}" != x ] then PATH="${GHCDIR}:${PATH}" fi if [ x"$1" = x-p ] then echo "${GHCRUN}" exit 0 fi "${GHCRUN}" --version >/dev/null 2>&1 || exit 1 [ x"$1" = x-f ] && echo -n "The Glasgow Haskell Compiler " "${GHCRUN}" --version 2>&1 | grep "version" | gawk '{ print $8; }'