SUMMARY="A PKCS#11 wrapper library"
DESCRIPTION="libp11 is a library implementing a thin layer on top of PKCS#11 \
API to make using PKCS#11 implementations easier."
HOMEPAGE="https://github.com/opensc/libp11"
COPYRIGHT="2016-2019 Michał Trojnara
	2015-2016 Nikos Mavrogiannopoulos
	2007-2009 Andreas Jellinghaus
	2011 Martin Paljak"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="$HOMEPAGE/releases/download/libp11-$portVersion/libp11-$portVersion.tar.gz"
CHECKSUM_SHA256="639ea43c3341e267214b712e1e5e12397fd2d350899e673dd1220f3c6b8e3db4"
#PATCHES="libp11-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

libVersion="3.4.2"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	libp11$secondaryArchSuffix = $portVersion
	lib:libp11$secondaryArchSuffix = $libVersionCompat
	lib:libpkcs11$secondaryArchSuffix
	lib:pkcs11$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	"

PROVIDES_devel="
	libp11${secondaryArchSuffix}_devel = $portVersion
	devel:libp11$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	libp11$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autoheader
	cmd:automake
	cmd:awk
	cmd:diff
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:pkg_config$secondaryArchSuffix
	"

TEST_REQUIRES="
	cmd:softhsm2_util
	"

defineDebugInfoPackage libp11$secondaryArchSuffix \
	"$libDir"/engines/pkcs11.so \
	"$libDir"/libp11.so.$libVersion

enginesDir=$libDir/engines

BUILD()
{
	runConfigure ./configure --with-enginesdir=$enginesDir
	make $jobArgs
}

INSTALL()
{
	make install

	rm $libDir/libp11.la
	rm $enginesDir/pkcs11.la

	prepareInstalledDevelLib libp11
	fixPkgconfig

	packageEntries devel \
		$developDir
}

TEST()
{
	LIBRARY_PATH="$sourceDir/src/.libs${LIBRARY_PATH:+:$LIBRARY_PATH}" \
	make check
}
