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

EAPI=9

inherit libtool

DESCRIPTION="Library for Japanese pTeX providing a better way of handling character encodings"
HOMEPAGE="https://tutimura.ath.cx/ptexlive/?ptexenc"
# The historic mirror serves different bytes under this name (2026-11-19).
SRC_URI="https://mirrors.ctan.org/systems/texlive/Source/texlive-${PV#*_p}-source.tar.xz"
S="${WORKDIR}/texlive-${PV#*_p}-source/texk/${PN}"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64"
IUSE="iconv"

DEPEND="
	dev-libs/kpathsea:=
	iconv? ( virtual/libiconv )"
RDEPEND="${DEPEND}"

src_prepare() {
	default

	# Link against kpathsea; bug 377141.
	sed -i '/^LIBS/s:@LIBS@:@LIBS@ @KPATHSEA_LIBS@:' Makefile.in || die

	cd "${WORKDIR}/texlive-${PV#*_p}-source" || die
	S="${WORKDIR}/texlive-${PV#*_p}-source" elibtoolize
}

src_configure() {
	econf \
		--disable-static \
		--with-system-kpathsea \
		$(use_enable iconv kanji-iconv)
}

src_install() {
	default

	insinto /usr/include/ptexenc
	doins ptexenc/unicode-jp.h
	use iconv && doins ptexenc/kanjicnv.h

	find "${ED}" -name '*.la' -delete || die
}