%hs_pkgconfdir %_ghclibdir/package.conf.d
%hs_setup      runghc Setup

# This is a sad story. GHC 6.8 has a deficient ghc-pkg that
# lists too many package DBs when given the --global option.
# For that reason, Cabal clips the --global output to
# just the first file.
# To avoid the clipping, we use --user (we can do it
# because we build packages in a controlled environment
# and can guarantee that the user's DB is empty).
#
# This hack will break with GHC 6.9; we'll have to
# remove --user for those later versions of GHC.
%hs_configure  configure --user

# hs_package_register <NAME.pkg> <BUILDROOT/PKGCONFDIR/NAME.conf>
%hs_package_register() \
ghc-pkg --package-conf="%2" --force register "%1"; \
%nil


# internal macro, cloned from rpm-build-python's py_package_deps_internal
%__hs_package_deps_internal() \
args="%{*}"; \
set $args ''; \
while test $# -gt 1; do \
  mod=${1%%,}; shift; \
  if test $# -gt 1; then \
    if test "x$1" = "x<" -o "x$1" = "x<=" -o "x$1" = "x=" -o "x$1" = "x>=" -o "x$1" = "x>"; then \
      verstr="$1 $2"; shift; shift; \
    fi; \
  fi; \
  echo -n "ghc%ghc_version(${mod}) $verstr "; \
  unset mod; unset verstr; \
done; \
%nil


# hs_package_dependencies <hspackage1> [[>= <hspackage1_version>] [<hspackage2> ...]]

%hs_package_dependencies() %(%{expand: %%__hs_package_deps_internal %{*}})
