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

EAPI=8

# ebuild generated by hackport 0.8.4.0.9999
#hackport: flags: -dev

CABAL_FEATURES="lib profile haddock hoogle hscolour test-suite"
inherit haskell-cabal

DESCRIPTION="A formatter for Haskell source code"
HOMEPAGE="https://github.com/fourmolu/fourmolu"

LICENSE="BSD"
SLOT="0/${PV}"
KEYWORDS="~amd64"
IUSE="examples executable +internal-bundle-fixities"

PATCHES=(
	"${FILESDIR}/${PN}-0.13.1.0-add-executable-flag.patch"
)

CABAL_CHDEPS=(
	'Cabal-syntax >=3.10 && <3.11' 'Cabal-syntax >=3.8 && <3.11'
	'text >=2.0 && <3.0' 'text >=1.0 && <3.0'
)

TEST_REQUIRED_BINS=(
	"${PN}"
)

RDEPEND="
	>=dev-haskell/aeson-1.0:=[profile?] <dev-haskell/aeson-3.0:=[profile?]
	>=dev-haskell/ansi-terminal-0.10:=[profile?] <dev-haskell/ansi-terminal-1.1:=[profile?]
	>=dev-haskell/cabal-syntax-3.8:=[profile?] <dev-haskell/cabal-syntax-3.11:=[profile?]
	>=dev-haskell/diff-0.4:=[profile?] <dev-haskell/diff-1.0:=[profile?]
	>=dev-haskell/file-embed-0.0.15:=[profile?] <dev-haskell/file-embed-0.1:=[profile?]
	>=dev-haskell/ghc-lib-parser-9.6:=[profile?] <dev-haskell/ghc-lib-parser-9.7:=[profile?]
	>=dev-haskell/megaparsec-9.0:=[profile?]
	>=dev-haskell/memotrie-0.6:=[profile?] <dev-haskell/memotrie-0.7:=[profile?]
	>=dev-haskell/scientific-0.3.2:=[profile?] <dev-haskell/scientific-1:=[profile?]
	>=dev-haskell/syb-0.7:=[profile?] <dev-haskell/syb-0.8:=[profile?]
	>=dev-haskell/text-1.0:=[profile?] <dev-haskell/text-3.0:=[profile?]
	>=dev-haskell/yaml-0.11.6.0:=[profile?] <dev-haskell/yaml-1:=[profile?]
	>=dev-lang/ghc-9.2:=
	executable? (
		>=dev-haskell/optparse-applicative-0.14:=[profile?] <dev-haskell/optparse-applicative-0.19:=[profile?]
		>=dev-haskell/th-env-0.1.1:=[profile?] <dev-haskell/th-env-0.2:=[profile?]
	)
"
DEPEND="${RDEPEND}
	>=dev-haskell/cabal-3.2.1.0
	test? (
		>=dev-haskell/diff-0.3 <dev-haskell/diff-0.5
		>=dev-haskell/hspec-2.0 <dev-haskell/hspec-3.0
		>=dev-haskell/hspec-megaparsec-2.2
		>=dev-haskell/path-0.6 <dev-haskell/path-0.10
		>=dev-haskell/path-io-1.4.2 <dev-haskell/path-io-2.0
		>=dev-haskell/quickcheck-2.14
		>=dev-haskell/temporary-1.3 <dev-haskell/temporary-1.4
	)
"

src_configure() {
	local exe_flag
	if use test || use executable; then
		exe_flag=executable
	else
		exe_flag=-executable
	fi

	haskell-cabal_src_configure \
		--flag=-dev \
		--flag=$exe_flag \
		$(cabal_flag internal-bundle-fixities internal-bundle-fixities)
}

src_install() {
	local to_install=( lib:$PN )
	use executable && to_install+=( "exe:${PN}" )

	haskell-cabal_src_install "${to_install[@]}"

	if use examples; then
		# Don't compress example source files
		docompress -x /usr/share/doc/${PF}/examples
		dodoc -r data/examples/
	fi
}