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

# Generated by zig-ebuilder 0.3.0

EAPI=8

DESCRIPTION="Ly - a TUI display manager"
HOMEPAGE="https://codeberg.org/fairyglade/ly"

declare -g -r -A ZBS_DEPENDENCIES=(
	[clap-0.11.0-oBajB-HnAQDPCKYzwF7rO3qDFwRcD39Q0DALlTSz5H7e.tar.gz]='https://github.com/Hejsil/zig-clap/archive/refs/tags/0.11.0.tar.gz'
	[ini-0.1.0-YCQ9Ys0pAABixEvvQvhVXAdqRE3wrZk_wiL9TPNHhB8d.tar.gz]='https://github.com/AnErrupTion/ini/archive/918f16d0dcf893d0c1cdffe204faa08bb3584e04.tar.gz'
	[zigini-0.3.3-36M0FRJJAADZVq5HPm-hYKMpFFTr0OgjbEYcK2ijKZ5n.tar.gz]='https://github.com/AnErrupTion/zigini/archive/9281f47702b57779e831d7618e158abb8eb4d4a2.tar.gz'
	[N-V-__8AAOEWBQDt5tNdIzIFY6n8DdZsCP-6MyLoNS20wgpA.tar.gz]='https://github.com/AnErrupTion/termbox2/archive/496730697c662893eec43192f48ff616c2539da6.tar.gz'
)

ZIG_SLOT="0.15"

inherit pam systemd zig

SRC_URI="
	https://codeberg.org/fairyglade/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
	${ZBS_DEPENDENCIES_SRC_URI}
"

S="${WORKDIR}/${PN}"

LICENSE="WTFPL-2"
SLOT="0"
KEYWORDS="~amd64"

IUSE="X"

DEPEND="
	sys-libs/pam
	X? (
		x11-libs/libxcb
	)
"
RDEPEND="
	app-misc/brightnessctl
	X? (
		x11-base/xorg-server
		x11-apps/xauth
		x11-apps/xrdb
		x11-apps/xmessage
	)
"

# https://github.com/ziglang/zig/issues/3382
QA_FLAGS_IGNORED="usr/bin/ly"

src_prepare() {
	zig_src_prepare

	sed -e "s|\$PREFIX_DIRECTORY|/usr|g" \
	-e "s|\$EXECUTABLE_NAME|ly|g" \
	-e "s|\$DEFAULT_TTY|2|g" \
	-e "s|\$CONFIG_DIRECTORY|/etc|g"\
	-i "${S}/res/${PN}@.service" \
	-i "${S}/res/${PN}-openrc" \
	-i "${S}/res/config.ini" || die
}

src_configure() {
	local my_zbs_args=(
		-Denable_x11_support=$(usex X true false)
	)

	zig_src_configure
}

src_install() {
	zig_src_install

	dodoc readme.md
	newdoc res/custom-sessions/README custom-sessions

	newinitd "${S}/res/${PN}-openrc" ${PN}

	systemd_dounit "${S}/res/${PN}@.service"

	insinto "/etc/${PN}"
	doins "${S}/res/config.ini"

	exeinto "/etc/${PN}"
	doexe "${S}/res/setup.sh"

	insinto "/etc/${PN}/lang"
	doins "${S}/res/lang/"*.ini

	newpamd "${S}/res/pam.d/ly-linux" ly
}
