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

EAPI=8
PYTHON_COMPAT=( python3_{12..15} )

# Generate a sub-slot from UVER and UREV values or use PV as a fallback.
usub() {
        local sub

        [[ -n ${UVER} ]] && sub="${UVER#+}-" || sub="${PV}-"
        [[ -n ${UREV} ]] && sub+="${UREV}" || sub="${sub%-}"
        echo "${sub}"
}

UVER=+17.10.20170616
UREV=8build1
UURL="https://launchpad.net/ubuntu/+archive/primary/+files/${PN}_${PV}${UVER}"

inherit python-single-r1 vala autotools

DESCRIPTION="Objects for creating Model-View-Controller type programs across DBus"
HOMEPAGE="https://launchpad.net/dee/"
SRC_URI="${UURL}.orig.tar.gz
		 ${UURL}-${UREV}.debian.tar.xz"
S="${WORKDIR}"

LICENSE="GPL-3 LGPL-3"
SLOT="0/$(usub)"
KEYWORDS="amd64"
IUSE="debug doc examples test"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
RESTRICT="!test? ( test )"

COMMON_DEPEND="
	dev-libs/glib:2
	dev-libs/icu:=
"
RDEPEND="${COMMON_DEPEND}
	${PYTHON_DEPS}
	$(python_gen_cond_dep 'dev-python/pygobject:3[${PYTHON_USEDEP}]')
"
DEPEND="${COMMON_DEPEND}"
BDEPEND="
	dev-build/gtk-doc-am
	dev-libs/gobject-introspection
	virtual/pkgconfig

	doc? ( dev-util/gtk-doc )
	test? (
		dev-util/dbus-test-runner
		sys-apps/dbus
	)

	${PYTHON_DEPS}
	$(python_gen_cond_dep 'dev-python/pygobject:3[${PYTHON_USEDEP}]')

	$(vala_depend)
"

src_prepare() {
	# gtkdocize.patch is skipped, eautoreconf already refreshes gtk-doc.make.
	local x
	local -a upatches=()
	for x in $(grep -v '^#' debian/patches/series); do
		[[ ${x} == gtkdocize.patch ]] && continue
		upatches+=( "debian/patches/${x}" )
	done
	eapply "${upatches[@]}"

	default

	vala_setup
	export VALA_API_GEN="${VAPIGEN}"

	eautoreconf
}

src_configure() {
	local myeconfargs=(
		--disable-silent-rules
		$(use_enable debug trace-log)
		$(use_enable doc gtk-doc)
		--enable-icu
		$(use_enable test tests)
	)
	econf "${myeconfargs[@]}"
}

src_install() {
	default

	doman debian/"${PN}"-tool.1

	if use examples; then
		docinto examples
		dodoc examples/{list-peers,*.c,*.py,*.vala}
		docompress -x /usr/share/doc/${PF}/examples
	fi

	find "${ED}" -name '*.la' -delete || die
}