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

EAPI=8

# ebuild generated by hackport 0.8.2.0.9999

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

DESCRIPTION="A GUI library for writing native Haskell applications"
HOMEPAGE="
	https://github.com/fjvallarino/monomer#readme
"

# The commit when this version was released (tagged 1.5.1.0)
GIT_RELEASE_COMMIT="ef4f10a07ed398a21f0d8f1063d001d5bb2f1b8d"

# NOTE: Assets needed for the examples only exist in the git repo
SRC_URI+="
	examples? (
		https://github.com/fjvallarino/${PN}/archive/${GIT_RELEASE_COMMIT}.tar.gz
			-> ${PN}-${GIT_RELEASE_COMMIT}.tar.gz
	)
"

LICENSE="BSD"
SLOT="0/${PV}"
KEYWORDS="~amd64"
IUSE="examples"

# Make example executables more resiliant to name collisions
CABAL_CHDEPS=(
	'executable books' 'executable monomer-examples-books'
	'executable dev-test-app' 'executable monomer-examples-test-app'
	'executable generative' 'executable monomer-examples-generative'
	'executable opengl' 'executable monomer-examples-opengl'
	'executable ticker' 'executable monomer-examples-ticker'
	'executable todo' 'executable monomer-examples-todo'
)

PATCHES=(
	"${FILESDIR}/${PN}-1.5.1.0-examples-01-togglable-test-exe.patch"
	"${FILESDIR}/${PN}-1.5.1.0-examples-02-examples-data-files.patch"
	"${FILESDIR}/${PN}-1.5.1.0-examples-03-tutorials-data-files.patch"
	"${FILESDIR}/${PN}-1.5.1.0-examples-04-enable-tutorial-examples.patch"
)

RDEPEND="
	>=dev-haskell/async-2.1:=[profile?] <dev-haskell/async-2.3:=[profile?]
	>=dev-haskell/attoparsec-0.12:=[profile?] <dev-haskell/attoparsec-0.15:=[profile?]
	>=dev-haskell/bytestring-to-vector-0.3:=[profile?] <dev-haskell/bytestring-to-vector-0.4:=[profile?]
	>=dev-haskell/data-default-0.5:=[profile?] <dev-haskell/data-default-0.8:=[profile?]
	>=dev-haskell/extra-1.6:=[profile?] <dev-haskell/extra-1.9:=[profile?]
	>=dev-haskell/formatting-6.0:=[profile?] <dev-haskell/formatting-8.0:=[profile?]
	>=dev-haskell/http-client-0.6:=[profile?] <dev-haskell/http-client-0.9:=[profile?]
	>=dev-haskell/juicypixels-3.2.9:=[profile?] <dev-haskell/juicypixels-3.5:=[profile?]
	>=dev-haskell/lens-4.16:=[profile?] <dev-haskell/lens-6:=[profile?]
	>=dev-haskell/nanovg-0.8.1:=[profile?] <dev-haskell/nanovg-1.0:=[profile?]
	>=dev-haskell/openglraw-3.3:=[profile?] <dev-haskell/openglraw-3.4:=[profile?]
	>=dev-haskell/sdl2-2.5.0:=[profile?] <dev-haskell/sdl2-2.6:=[profile?]
	>=dev-haskell/text-1.2:=[profile?] <dev-haskell/text-2.1:=[profile?]
	>=dev-haskell/text-show-3.7:=[profile?] <dev-haskell/text-show-3.12:=[profile?]
	>=dev-haskell/vector-0.12:=[profile?] <dev-haskell/vector-0.14:=[profile?]
	>=dev-haskell/wreq-0.5.2:=[profile?] <dev-haskell/wreq-0.6:=[profile?]
	>=dev-lang/ghc-8.10.1:=
	media-libs/glew:0
	examples? (
		>=dev-haskell/aeson-1.4:=[profile?] <dev-haskell/aeson-2.3:=[profile?]
		>=dev-haskell/random-1.1:=[profile?] <dev-haskell/random-1.3:=[profile?]
		>=dev-haskell/websockets-0.12:=[profile?] <dev-haskell/websockets-0.13:=[profile?]
		>=dev-haskell/wuss-1.1:=[profile?] <dev-haskell/wuss-2.3:=[profile?]
	)
"
DEPEND="${RDEPEND}
	dev-haskell/c2hs
	>=dev-haskell/cabal-3.2.0.0
	virtual/pkgconfig
	test? (
		>=dev-haskell/hspec-2.4 <dev-haskell/hspec-3.0
	)
"

src_prepare() {
	if use examples; then
		mv -v "${WORKDIR}/${PN}-${GIT_RELEASE_COMMIT}/assets" "${S}" || die
		mv -v "${WORKDIR}/${PN}-${GIT_RELEASE_COMMIT}/examples/opengl/shaders" "${S}/assets" || die
	fi
	haskell-cabal_src_prepare
}

src_configure() {
	haskell-cabal_src_configure \
		$(cabal_flag examples examples)
}