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

EAPI=8

GHIDRA_EXT_NAME="ghidra-xbe"

inherit edo ghidra-extension

# Upstream tags builds by date rather than versioning the loader.
MY_TAG="build-202602250354"
# The version of XboxDev/xtlid that upstream's build script pins.
XTLID_PV="0.1.2"

DESCRIPTION="Ghidra loader for original Xbox XBE executables."
HOMEPAGE="https://github.com/XboxDev/ghidra-xbe"
SRC_URI="https://github.com/XboxDev/${PN}/archive/refs/tags/${MY_TAG}.tar.gz
	-> ${P}.tar.gz
	https://github.com/XboxDev/xtlid/releases/download/v${XTLID_PV}/xtlid.xml
	-> xtlid-${XTLID_PV}.xml"
S="${WORKDIR}/${PN}-${MY_TAG}"

# Upstream ships no licence file and states no terms anywhere in the repository.
LICENSE="all-rights-reserved"
KEYWORDS="~amd64"
RESTRICT="bindist mirror"

BDEPEND+=" dev-libs/libxslt"

src_prepare() {
	ghidra-extension_src_prepare

	# Generated by upstream's build script, which downloads xtlid.xml first.
	edo xsltproc -o src/main/java/XbeLoader/XbeXtlidDb.java xtlid2java.xslt \
		"${DISTDIR}/xtlid-${XTLID_PV}.xml"
	[[ -s src/main/java/XbeLoader/XbeXtlidDb.java ]] ||
		die "xsltproc produced no XbeXtlidDb.java"

	# Upstream's own build machinery and its headless test, none of which
	# belongs in the installed extension.
	rm -r build.sh tests xtlid2java.xslt || die
}

pkg_postinst() {
	elog "The XbSymbolDatabase analyzer looks for an XbSymbolDatabaseCLI"
	elog "executable, which is not packaged. Without it that one analyzer does"
	elog "nothing; the loader itself is unaffected."
}