SUMMARY="An implementation of a cryptographic store"
DESCRIPTION="SoftHSM is an implementation of a cryptographic store accessible \
through a PKCS #11 interface. You can use it to explore PKCS #11 without \
having a Hardware Security Module. It is being developed as a part of the \
OpenDNSSEC project. SoftHSM uses Botan for its cryptographic operations."
HOMEPAGE="https://www.opendnssec.org/softhsm/"
COPYRIGHT="2010 .SE, The Internet Infrastructure Foundation
	2010 SURFnet bv"
LICENSE="BSD (2-clause)"
REVISION="3"
SOURCE_URI="https://dist.opendnssec.org/source/softhsm-$portVersion.tar.gz"
CHECKSUM_SHA256="92aa56cf45e25892326e98b851c44de9cac8559e208720e579bf8e2cd1c132b2"
SOURCE_DIR="softhsm-$portVersion"
PATCHES="softhsm-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2 ?x86"
SECONDARY_ARCHITECTURES="x86"

commandBinDir=$binDir
commandSuffix=$secondaryArchSuffix
if [ "$targetArchitecture" = x86_gcc2 ]
then
	commandBinDir=$prefix/bin
	commandSuffix=
fi

majorVersion="${portVersion%%.*}"

GLOBAL_WRITABLE_FILES="
	settings/softhsm$majorVersion.conf keep-old
	var/lib/softhsm directory keep-old
	"
USER_SETTINGS_FILES="
	settings/softhsm$majorVersion.conf template data/softhsm/softhsm$majorVersion.conf.sample
	"

PROVIDES="
	softhsm$majorVersion$secondaryArchSuffix = $portVersion
	cmd:softhsm${majorVersion}_dump_file$commandSuffix = $portVersion
	cmd:softhsm${majorVersion}_keyconv$commandSuffix = $portVersion
	cmd:softhsm${majorVersion}_util$commandSuffix = $portVersion
	lib:libsofthsm$majorVersion$secondaryArchSuffix
	"
REQUIRES="
	haiku$secondaryArchSuffix
	cmd:botan$commandSuffix
#	lib:libbotan_2$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbotan_2$secondaryArchSuffix
	devel:libcppunit$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:diff
	cmd:find
	cmd:g++$secondaryArchSuffix
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:makeinfo
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage softhsm$majorVersion$secondaryArchSuffix \
	"$commandBinDir"/softhsm$majorVersion-dump-file \
	"$commandBinDir"/softhsm$majorVersion-keyconv \
	"$commandBinDir"/softhsm$majorVersion-util \
	"$libDir"/softhsm/libsofthsm$majorVersion.so

PATCH()
{
	sed -i \
		-e "/^objstoretest_LDFLAGS/ s/ -pthread//;" \
		-e "/^sessionmgrtest_LDFLAGS/ s/ -pthread//;" \
		-e "/^slotmgrtest_LDFLAGS/ s/ -pthread//;" \
		-e "/^p11test_LDFLAGS/ s/ -pthread//;" \
		src/lib/object_store/test/Makefile.* \
		src/lib/session_mgr/test/Makefile.* \
		src/lib/slot_mgr/test/Makefile.* \
		src/lib/test/Makefile.* \

}

BUILD()
{
	runConfigure --omit-dirs binDir ./configure \
		--bindir="$commandBinDir" \
		--disable-gost
	make $jobArgs
}

INSTALL()
{
	make install

	sed -i -e "/^directories\.tokendir/ \
			s|$prefix/|`finddir B_SYSTEM_DIRECTORY`/|;" \
		"$settingsDir"/softhsm$majorVersion.conf \
		"$settingsDir"/softhsm$majorVersion.conf.sample

	rm -f "$libDir"/softhsm/*.la

	mkdir -p "$dataDir"/softhsm
	mv "$settingsDir"/softhsm$majorVersion.conf.sample "$dataDir"/softhsm
}

TEST()
{
	make check
}
