# Copyright 2019-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit systemd go-module

DESCRIPTION="Framework for dark and light mode transitions"
HOMEPAGE="https://gitlab.com/WhyNotHugo/darkman"
SRC_URI="https://gitlab.com/whynothugo/${PN}/-/archive/v${PV}/${PN}-v${PV}.tar.bz2"
SRC_URI+=" https://files.levelnine.at/${P}-vendor.tar.xz"

LICENSE="ISC"
SLOT="0"
KEYWORDS="~amd64"
IUSE="+man +examples"

S="${WORKDIR}/${PN}-v${PV}"

RDEPEND="app-misc/geoclue"
BDEPEND="man? ( app-text/scdoc )"

DOCS=( CHANGELOG.md README.md )

src_compile() {
	ego build -v -x -o ${PN} -ldflags="-X main.Version=${PV}" ./cmd/${PN}

	if use man; then
		scdoc < ./${PN}.1.scd > ./${PN}.1 || die
	fi
}

src_install() {
	dobin ${PN}

	systemd_dounit ${PN}.service
	doman ${PN}.1

	use examples && DOCS+=( examples/. )
	einstalldocs

	insinto /usr/share/dbus-1/services
	doins contrib/dbus/*

	insinto  /usr/share/xdg-desktop-portal/portals/
	doins contrib/portal/darkman.portal

	dodir /etc/env.d/
	echo "XDG_DATA_DIRS=\"~/.local/share/\"" >> "${ED}"/etc/env.d/99darkman || die
}
