# Copyright 2026 Nadeŭka <me+oss@nadevko.cc>
# Distributed under the terms of the GNU General Public License v2
EAPI=8
inherit git-r3 udev

: ${BRILLO_GROUP:=video}

DESCRIPTION='Control the brightness of backlight and keyboard LED devices'
HOMEPAGE=https://gitlab.com/cameronnemo/brillo
EGIT_REPO_URI=https://gitlab.com/cameronnemo/${PN}.git
LICENSE=GPL-3

SLOT=0
IUSE='apparmor man policykit setgid +udev'

BDEPEND='man? ( dev-go/go-md2man )'
RDEPEND="
	policykit? ( sys-auth/polkit )
	udev? ( virtual/udev acct-group/${BRILLO_GROUP} )
"

PATCHES=( "${FILESDIR}" )

src_compile() {
	mkdir -p build || die
	emake build/brillo $(usev man build/brillo.1)
}

src_install() {
	emake DESTDIR="${D}" UDEVRULESDIR="$(get_udevdir)" \
		GROUP=${BRILLO_GROUP} \
		install.bin$(usev setgid .setgid) \
		$(usev apparmor install.apparmor) \
		$(usev man install.man) \
		$(usev policykit install.polkit) \
		$(usev udev install.udev)

	einstalldocs
	newinitd "${FILESDIR}"/brillo.initd brillo
}

pkg_postinst() {
	use udev && udev_reload

	elog 'To make brightness persistent across reboots with OpenRC, enable the service:'
	elog '  rc-update add brillo boot'
	elog '  rc-service brillo start'
}

pkg_postrm() {
	use udev && udev_reload
}