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

EAPI=8

inherit linux-info meson

DESCRIPTION="IP over DNS tunnel"
HOMEPAGE="https://code.kryo.se/iodine/"
SRC_URI="
	https://code.kryo.se/${PN}/${P}.tar.gz
	https://github.com/yarrick/iodine/releases/download/v${PV}/${P}.tar.gz
"

LICENSE="ISC GPL-2" # GPL-2 for init script bug #426060
SLOT="0"
KEYWORDS="~amd64 ~arm64 ~x86"
IUSE="caps selinux systemd test"
RESTRICT="!test? ( test )"

# libcap
RDEPEND="
	virtual/zlib:=
	selinux? ( sys-libs/libselinux )
	systemd? ( sys-apps/systemd:= )
"
DEPEND="
	${RDEPEND}
	test? ( dev-libs/check )
"
RDEPEND+=" selinux? ( sec-policy/selinux-iodine )"

CONFIG_CHECK="~TUN"

src_prepare() {
	default

	# TODO: In >0.9.1, replace this with the meson option
	if ! use test ; then
		sed -i -e "/^libcheck = /s:'check':'check-idonotexist':" meson.build || die
	fi
}

src_configure() {
	local emesonargs=(
		-Ddocdir="${EPREFIX}"/usr/share/doc/${PF}
		$(meson_feature caps libcapng)
		$(meson_feature selinux)
		$(meson_feature systemd)
	)

	meson_src_configure
}

src_install() {
	meson_src_install

	newinitd "${FILESDIR}"/iodined-1.init-r1 iodined
	newconfd "${FILESDIR}"/iodined.conf-r1 iodined
	keepdir /var/empty
	fperms 600 /etc/conf.d/iodined
}