# Copyright 2026 Ben Buhse
# Distributed under the terms of the GNU General Public License v2

EAPI=8

if [[ ${PV} == 9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://codeberg.org/rc23/rc23.git"
else
	SRC_URI="https://codeberg.org/rc23/rc23/archive/v${PV}.tar.gz -> ${P}.tar.gz"
	S="${WORKDIR}/rc23"
	KEYWORDS="~amd64"
	PATCHES=( "${FILESDIR}/${P}-whatis-test.patch" )
fi

DESCRIPTION="Reimplementation of the Plan 9 rc shell for Unix"
HOMEPAGE="https://codeberg.org/rc23/rc23"

LICENSE="ZLIB"
SLOT="0"
IUSE="libedit readline"
REQUIRED_USE="?? ( libedit readline )"

RDEPEND="
	readline? ( sys-libs/readline:= )
	libedit? ( dev-libs/libedit )
"
DEPEND="${RDEPEND}"

src_compile() {
	local edit=null
	use readline && edit=readline
	use libedit && edit=edit
	emake EDIT="${edit}" PREFIX="${EPREFIX}/usr"
}

src_install() {
	emake DESTDIR="${D}" PREFIX="${EPREFIX}/usr" install
	dodoc README.md AUTHORS
}