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

EAPI=8

inherit git-r3 toolchain-funcs

DESCRIPTION="A universal system-agnostic package manager"
HOMEPAGE="https://git.symlinx.net/pkgit/"
EGIT_REPO_URI="https://git.symlinx.net/pkgit"
EGIT_COMMIT="1.1.3"

LICENSE="GPL-2+"
SLOT="0"
KEYWORDS="amd64 arm64 arm x86"
IUSE=""

RDEPEND="dev-vcs/git"
DEPEND="${RDEPEND}"

src_compile() {
    tc-export CC
    emake
}

src_install() {
    emake DESTDIR="${D}" PREFIX="/usr" install

    keepdir /etc/pkgit

    if [[ -f config/init.lua ]]; then
        insinto /etc/pkgit
        doins config/init.lua

        insinto /etc/skel/.config/pkgit
        doins config/init.lua
    fi
}

pkg_postinst() {
    elog "Portage by default does not includes pre-made Lua file on .config folder."
    elog "You have to manually make directory and copy Lua file from skel folder:"
    elog " mkdir -p ~/.config/pkgit ~/.local/share/pkgit && cp /etc/pkgit/init.lua ~/.config/pkgit/init.lua "
    elog " "
    elog "For configuring Pkgit, you can consider watching Dacctal's video: "
    elog " https://youtu.be/LiAiovvBEfI?si=QsKte9DwpyUjtm5S "
    elog "or go on Dacctal Symlinx's source: "
    elog " https://git.symlinx.net/pkgit/about/#usage "
}