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

EAPI=8

inherit cmake git-r3

DESCRIPTION="Open-source engine for Star Wars Jedi Knight: Jedi Academy and Jedi Outcast"
HOMEPAGE="https://github.com"

EGIT_MIN_CLONE_TYPE="shallow"
EGIT_REPO_URI="https://github.com/JACoders/OpenJK"
EGIT_BRANCH="master"
EGIT_SUBMODULES=()

LICENSE="GPL-2"
SLOT="0"
IUSE="dedicated +jk2 +jka mpa rend2"
REQUIRED_USE="
	|| ( jk2 jka )
	dedicated? ( jka )
	mpa? ( jka )
	rend2? ( mpa )
"

DEPEND="
	media-libs/libjpeg-turbo:=
	media-libs/libpng:=
	media-libs/libsdl2[opengl,sound,video]
	media-libs/openal
	virtual/opengl
"
RDEPEND="${DEPEND}"

PATCHES=(
	"${FILESDIR}"/${P}-fix_cmake_version_in_tools-WinSymbol.patch
)

src_configure() {
	local mycmakeargs=(
		-DBuildJK2SPEngine=$(usex jk2)
		-DBuildJK2SPGame=$(usex jk2)
		-DBuildJK2SPRdVanilla=$(usex jk2)
		-DBuildMPEngine=$(usex mpa)
		-DBuildMPCGame=$(usex mpa)
		-DBuildMPGame=$(usex mpa)
		-DBuildMPRdVanilla=$(usex mpa)
		-DBuildMPUI=$(usex mpa)
		-DBuildMPRend2=$(usex rend2)
		-DBuildSPEngine=$(usex jka)
		-DBuildSPGame=$(usex jka)
		-DBuildSPRdVanilla=$(usex jka)
		-DBuildMPDed=$(usex dedicated)
		-DCMAKE_INSTALL_PREFIX="/opt/openjk"
	)
	cmake_src_configure
}

pkg_postinst() {
	elog "OpenJK has been installed to /opt/openjk."
	elog "Copy your original retail .pk3 files into:"
	if use jka; then
		elog "  ~/.local/share/openjk/base/ (for Jedi Academy)"
		elog "or symlink your GameData directory to ~/.local/share/openjk"
	fi
	if use jk2; then
		elog "  ~/.local/share/openjo/base/ (for Jedi Outcast)"
		elog "or symlink your GameData directory to ~/.local/share/openjo"
	fi
}