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

EAPI=8

inherit toolchain-funcs

DESCRIPTION="Object capability-based sudo"
HOMEPAGE="https://github.com/kaniini/capsudo"
SRC_URI="https://github.com/kaniini/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="all-rights-reserved"
SLOT="0"
KEYWORDS="~alpha amd64 arm arm64 ~hppa ~loong ~m68k ~mips ppc ppc64 ~riscv ~s390 ~sparc x86"

DEPEND="
	sys-libs/libcap
	virtual/libcrypt:=
"
RDEPEND="${DEPEND}"
BDEPEND="virtual/pkgconfig"

src_compile() {
	emake CC="$(tc-getCC) ${CFLAGS} ${LDFLAGS}" || die "Failed to compile capsudo"
}

src_install() {
	emake DESTDIR="${D}" PREFIX="${EPREFIX}/usr" install || die "Failed to install capsudo"
	newinitd "${FILESDIR}/openrc/capsudo.initd" capsudo	
	newinitd "${FILESDIR}/openrc/capsudo.confd" capsudo
	einstalldocs
}

pkg_postinst() {
	elog "To use Capsudo, go to this link:"
	elog " https://github.com/kaniini/capsudo?tab=readme-ov-file#some-quick-command-line-examples "
}