# 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=(
	[aro-0.0.0-JSD1Qi7QNgDnfcrdEJf82v3o6MhZySjYVrtdfEf3E4Se.tar.gz]='https://github.com/Vexu/arocc/archive/5f5a050569a95ecc40a426f0c3666ae7ef987ede.tar.gz'
	[clap-0.11.0-oBajB7foAQC3Iyn4IVCkUdYaOVVng5IZkSncySTjNig1.tar.gz]='https://github.com/Hejsil/zig-clap/archive/fc1e5cc3f6d9d3001112385ee6256d694e959d2f.tar.gz'
	[ini-0.1.0-YCQ9YiwsAACghqF8LZyjAF2H_NnL6n29QLuCe0fsmPTo.tar.gz]='https://github.com/AshAmetrine/ziglibs-ini/archive/3b733e10adc6c4c48050709b97a22258bc2e6156.tar.gz'
	[translate_c-0.0.0-Q_BUWvP1BgCjAk6PWv5286tOlvzD9-X-NkuTzh0KxY0Q.tar.gz]='https://codeberg.org/ziglang/translate-c/archive/7a1a9fdc4ab00835748a6657ecbb835e3d5d45f7.tar.gz'
	[zigini-0.5.0-BSkB7e9WAACfyCBABNZiWL3gFMw18GKn3qBcPs8L1Ec1.tar.gz]='https://github.com/AshAmetrine/zigini/archive/a665d081dda42664a96da2840ea09c5ccf9d0692.tar.gz'
	[N-V-__8AAAUXBQD6Fwpi9m0MBqWXFFaqW5l1lVrJC2Ynj7a-.tar.gz]='https://github.com/AnErrupTion/termbox2/archive/c7f241e8888ce243e1748b05c26a42fcfaaad936.tar.gz'
)

ZIG_SLOT="0.16"

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}-kmsconvt@.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"
	systemd_dounit "${S}/res/${PN}-kmsconvt@.service"

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

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

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

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