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

EAPI=8

inherit autotools flag-o-matic

DESCRIPTION="Embedded SSL library"
HOMEPAGE="https://www.wolfssl.com/ https://github.com/wolfSSL/wolfssl"
SRC_URI="https://github.com/wolfSSL/${PN}/archive/refs/tags/v${PV}-stable.tar.gz -> ${P}.tar.gz"

S="${WORKDIR}/${P}-stable"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~ppc64 ~x86"
IUSE="debug cpu_flags_x86_aes jni sniffer +writedup"

DEPEND="sniffer? ( net-libs/libpcap )"
RDEPEND="${DEPEND}"
BDEPEND="app-arch/unzip"

src_prepare() {
	eautoreconf
	default
}

src_configure() {
	# The x86_64 SipHash assembly fails the wolfCrypt known-answer test when GCC 16
	# optimises it (passes at -O0); the C implementation passes.
	append-cppflags -DWC_SIPHASH_NO_ASM
	econf \
		"$(use_enable cpu_flags_x86_aes aesni)" \
		"$(use_enable sniffer)" \
		"$(use_enable debug)" \
		--enable-distro \
		"$(use_enable jni)" \
		"$(use_enable writedup)"
}

src_test() {
	# The test scripts re-exec under bwrap --unshare-net, which cannot map users
	# inside the Portage sandbox.
	local -x AM_BWRAPPED=yes
	default
}