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

EAPI=8

LLVM_COMPAT=( {15..21} )
PYTHON_COMPAT=( python3_{12..14} )

inherit cmake python-single-r1 llvm-r2

DESCRIPTION="RTC Testbench is a set of tools for validating Ethernet networks"
HOMEPAGE="https://github.com/Linutronix/RTC-Testbench"
SRC_URI="https://github.com/Linutronix/RTC-Testbench/archive/refs/tags/v${PV}.tar.gz -> ${PN}-${PV}.tar.gz"
S="${WORKDIR}/RTC-Testbench-${PV}"

LICENSE="BSD-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="doc mqtt"

# Generated eBPF files
QA_PREBUILT="usr/lib*/rtc-testbench/ebpf/*.o"

REQUIRED_USE="
	${PYTHON_REQUIRED_USE}
"

BDEPEND="
	${PYTHON_DEPS}
	virtual/pkgconfig
	doc? (
		media-gfx/graphviz
		$(python_gen_cond_dep '
			dev-python/sphinx[${PYTHON_USEDEP}]
			dev-python/sphinx-rtd-theme[${PYTHON_USEDEP}]
		')
	)
	$(llvm_gen_dep '
		llvm-core/clang:${LLVM_SLOT}=[llvm_targets_BPF(-)]
	')
"
DEPEND="
	mqtt? ( app-misc/mosquitto )
	dev-libs/libyaml
	dev-libs/libbpf:=
	dev-libs/openssl:=
	net-libs/xdp-tools
"
RDEPEND="
	${PYTHON_DEPS}
	${DEPEND}
"

pkg_setup() {
	llvm-r2_pkg_setup
}

src_configure() {
	local mycmakeargs=(
		-DWITH_MQTT=$(usex mqtt)
		-DRX_TIMESTAMP=TRUE
		-DTX_TIMESTAMP=TRUE
	)

	cmake_src_configure
}

src_compile() {
	cmake_src_compile
	use doc && emake -C "${S}/Documentation" html
}

src_install() {
	cmake_src_install
	use doc && HTML_DOCS=( "${S}/Documentation/_build/html" )
}
