# 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: opengl-example:examples,+recent-ish,+pkgconfig

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

DESCRIPTION="Both high- and low-level bindings to the SDL library (version 2.0.6+)"
HOMEPAGE="https://hackage.haskell.org/package/sdl2"

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

RDEPEND="
	>=dev-haskell/statevar-1.1.0.0:=[profile?] <dev-haskell/statevar-1.3
	>=dev-haskell/text-1.1.0.0:=[profile?] <dev-haskell/text-2.1
	>=dev-haskell/vector-0.10.9.0:=[profile?] <dev-haskell/vector-0.14
	>=dev-lang/ghc-8.10.6:=
	examples? (
		dev-haskell/opengl:=[profile?]
	)
	!no-linear? (
		>=dev-haskell/linear-1.10.1.2:=[profile?] <dev-haskell/linear-1.23:=[profile?]
	)
	media-libs/libsdl2
"
DEPEND="
	${RDEPEND}
	>=dev-haskell/cabal-3.2.1.0
	test? (
		>=dev-haskell/weigh-0.0.8
		dev-haskell/linear
	)
	virtual/pkgconfig
"

# These example exe's should be renamed to avoid filename collisions
src_prepare() {
	local example_exes=(
		lazyfoo-lesson-01
		lazyfoo-lesson-02
		lazyfoo-lesson-03
		lazyfoo-lesson-04
		lazyfoo-lesson-05
		lazyfoo-lesson-07
		lazyfoo-lesson-08
		lazyfoo-lesson-09
		lazyfoo-lesson-10
		lazyfoo-lesson-11
		lazyfoo-lesson-12
		lazyfoo-lesson-13
		lazyfoo-lesson-14
		lazyfoo-lesson-15
		lazyfoo-lesson-17
		lazyfoo-lesson-18
		lazyfoo-lesson-19
		lazyfoo-lesson-20
		lazyfoo-lesson-43
		twinklebear-lesson-01
		twinklebear-lesson-02
		twinklebear-lesson-04a # This needs to come before twinklebear-lesson-04
		twinklebear-lesson-04
		twinklebear-lesson-05
		audio-example
		eventwatch-example
		userevent-example
		rendergeometry-example
		opengl-example
	)

	export CABAL_CHBINS=()

	if use examples; then
		for e in "${example_exes[@]}"; do
			export CABAL_CHBINS+=(
				"$e"
				"haskell-sdl2-$e"
			)
		done
	fi

	haskell-cabal_src_prepare
}

src_configure() {
	local config_flags=(
		$(cabal_flag examples examples)
		$(cabal_flag no-linear no-linear)
		$(cabal_flag examples opengl-example)
		--flag=pkgconfig
		--flag=recent-ish
	)

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