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

EAPI=8

inherit toolchain-funcs

DESCRIPTION="A small vi/ex terminal text editor"
HOMEPAGE="https://github.com/kyx0r/nextvi"

if [[ "${PV}" != 9999 ]]; then
	SRC_URI="https://github.com/kyx0r/nextvi/archive/${PV}.tar.gz -> ${P}.tar.gz"
	KEYWORDS="amd64 x86"
else
	inherit git-r3
	EGIT_REPO_URI="https://github.com/kyx0r/nextvi"
fi

LICENSE="ISC"
SLOT="0"

RESTRICT="mirror"

src_unpack() {
	if [[ "${PV}" != 9999 ]]; then
		default
	else
		git-r3_src_unpack
		git-r3_fetch "https://github.com/kyx0r/nextvi" "refs/heads/manual"
		git-r3_checkout "https://github.com/kyx0r/nextvi" "nextvi-manual"
	fi
}

src_compile() {
	$(tc-getCC) vi.c ${CFLAGS} ${LDFLAGS} -o nextvi || die
}

src_install() {
	dobin nextvi

	[[ "${PV}" != 9999 ]] && newman vi.1 nextvi.1 || \
		newman "${WORKDIR}/nextvi-manual/vi.1" nextvi.1
}