dnl
dnl Helium configure script
dnl

# Is it there?
AC_INIT(src/Makefile.in)

# check for C compiler
AC_PROG_CC

# check for binary extension
AC_EXEEXT
AC_SUBST(EXEEXT)

SLASH="/"
if test -n "$EXEEXT"; then
  AC_MSG_WARN([Assuming Windows platform with \\ as path separator.])
  SLASH="\\\\"
fi
AC_SUBST(SLASH)

# check for GHC
AC_PATH_PROG(GHC,ghc)

# allow a different Haskell compiler to be specified
AC_ARG_WITH(ghc,
[  --with-ghc=<haskell compiler>
       Use a command different from 'ghc' to compile Haskell code.
],
[WithHc="$withval"],
[WithHc=$GHC]
)
AC_SUBST(WithHc)

if test "$WithHc" = "" -o "$WithHc" = "no"; then
  AC_MSG_ERROR([Cannot continue without Haskell compiler.])
fi

if test "$WithHc" != "$GHC"; then
  AC_MSG_WARN([Using $WithHc as Haskell compiler.])
fi

# check for AG system
AC_PATH_PROG(AG,ag)

# allow a different AG compiler to be specified
AC_ARG_WITH(ag,
[  --with-ag=<AG compiler>
       Use a command different from 'ag' to compile attribute grammar code.
],
[WithAG="$withval"],
[WithAG=$AG]
)
AC_SUBST(WithAG)

if test "$WithAG" = "no" -o "$WithAG" = ""; then
  AC_MSG_WARN([Will use the generated Haskell files directly.])
  WithAG=""
elif test "$WithAG" != "$AG"; then
  AC_MSG_WARN([Using $WithAG as AG system.])
fi

# strip utility; can be disabled
AC_ARG_WITH(strip,
[  --without-strip
       Do not strip binary.
],
[WithStrip="$withval"],
[WithStrip="yes"]
)

if test "$WithStrip" = "yes"; then
  AC_PATH_PROG(STRIP,strip)
fi

AC_SUBST(STRIP)

# UPX binary compressor; can be disabled
AC_ARG_WITH(upx,
[  --without-upx
       Do not compress binary with upx.
],
[WithUpx="$withval"],
[WithUpx="yes"]
)

if test "$WithUpx" = "yes"; then
  AC_PATH_PROG(UPX,upx)
fi

AC_SUBST(UPX)

# install command
AC_PROG_INSTALL

# symbolic links
AC_PROG_LN_S()

# logger on or off?
AC_ARG_ENABLE(logger,
[  --enable-logger
       Enable logging of error messages.
],
[log="$enableval"],
[log="no"]
)
if test "$log" = "no"; then
  cp src/utils/LoggerDisabled.hs src/utils/Logger.hs;
  logger="";
else
  cp src/utils/LoggerEnabled.hs src/utils/Logger.hs;
  logger="yes";
fi
AC_SUBST(logger)
AC_MSG_WARN([Logger set to $logger])

PWD=`pwd`
HELIUM=${PWD}/bin/helium${EXEEXT}
COREASM=${PWD}/../lvm/src/lib/coreasm
LVMPATH=${PWD}/lib
AC_SUBST(HELIUM)
AC_SUBST(COREASM)
AC_SUBST(LVMPATH)
# HBINDIR=${bindir}
# HLIBDIR=${prefix}/helium/lib
# HDEMODIR=${prefix}/helium/demo
# AC_SUBST(HBINDIR)
# AC_SUBST(HLIBDIR)
# AC_SUBST(HDEMODIR)

# write output file
AC_OUTPUT(src/Makefile lib/simple/Makefile lib/Makefile src/utils/OSSpecific.hs)

echo "****************************************************"
echo "Configuration done."
echo "Type \"cd src\", then \"make depend\", then \"make\""
echo "****************************************************"
