# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

# ebuild generated by hackport 0.8.1.0.9999
# hackport: flags: selftest:test

CABAL_FEATURES=""
inherit haskell-cabal git-r3

DESCRIPTION="GHC build system"
HOMEPAGE="https://gitlab.haskell.org/ghc/ghc/-/tree/master/hadrian#readme"
EGIT_REPO_URI="https://gitlab.haskell.org/ghc/ghc.git/"

# Hadrian isn't in any submodule, so we don't need to download any of them
EGIT_SUBMODULES=()

EGIT_CHECKOUT_DIR="${WORKDIR}/ghc"
S="${EGIT_CHECKOUT_DIR}/${PN}"
CABAL_FILE="${S}/${PN}.cabal"

LICENSE="BSD"
SLOT="0"
#KEYWORDS="~amd64"
IUSE="static test +threaded"
RESTRICT="!test? ( test )"

CABAL_CHDEPS=(
	'version:             0.1.0.0' 'version:             9999'
)

RDEPEND="
	>=dev-haskell/cabal-3.2:= <dev-haskell/cabal-3.9:=
	>=dev-haskell/extra-1.4.7:=
	>=dev-haskell/unordered-containers-0.2.1:= <dev-haskell/unordered-containers-0.3:=
	>=dev-lang/ghc-8.4.3:=
	>=dev-util/shake-0.18.3:= <dev-util/shake-0.20:=
	static? (
		dev-libs/libffi[static-libs]
		dev-libs/gmp[static-libs]
	)
	test? (
		>=dev-haskell/quickcheck-2.6:= <dev-haskell/quickcheck-2.15:=
	)
"
DEPEND="${RDEPEND}
	>=dev-haskell/cabal-2.2.0.1
"

src_configure() {
	local configure_flags=(
		$(cabal_flag test selftest)
		$(cabal_flag threaded threaded)
	)

	if use static; then
		configure_flags+=(
			--disable-shared
			--enable-static
			--disable-executable-dynamic
			--enable-executable-static
		)
	fi

	haskell-cabal_src_configure "${configure_flags[@]}"
}