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

EAPI=8

# ebuild generated by hackport 0.9.0.0.9999
#hackport: flags: opengl-example:examples,+recent-ish,+pkgconfig

CABAL_HACKAGE_REVISION=1

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"

RESTRICT=test # requires functional audio and video devices (bad for sandboxes)

CABAL_CHDEPS=(
	'bytestring >= 0.10.4.0 && < 0.12' 'bytestring >= 0.10.4.0'
)

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

# 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() {
	haskell-cabal_src_configure \
		$(cabal_flag examples examples) \
		$(cabal_flag no-linear no-linear) \
		$(cabal_flag examples opengl-example) \
		--flag=pkgconfig \
		--flag=recent-ish
}