#-------------------------------------------------------------------------
## Setup file detection function.
#-------------------------------------------------------------------------
function detect_setup_file() {
  if [ -r Setup.hs ] ; then
    echo Setup.hs
  elif [ -r Setup.lhs ] ; then
    echo Setup.lhs
  else
    message "${PROBLEM_COLOR}Cannot detect setup file!${DEFAULT_COLOR}"
    return 1
  fi
}

#-------------------------------------------------------------------------
## Section-default build script.
#-------------------------------------------------------------------------
function default_build_haskell() {
  local setup_file

  setup_file=$(detect_setup_file)
  runhaskell $setup_file configure --prefix=${INSTALL_ROOT}/usr $OPTS
  runhaskell $setup_file build
}

#-------------------------------------------------------------------------
## Section-default install script.
#-------------------------------------------------------------------------
function default_install_haskell() {
  local setup_file
  local cabal_file
  local share_dir

  setup_file=$(detect_setup_file)
  runhaskell $setup_file install
  cabal_file=$(ls *.cabal)
  share_dir=${INSTALL_ROOT}/usr/share/${SPELL}
  mkdir -vp $share_dir
  cp -v $cabal_file $share_dir
}

function default_build() {
   default_build_haskell
}
function default_install() {
   default_install_haskell
}
