SUMMARY="XML Security Library"
DESCRIPTION="XML Security Library is a C library based on LibXML2. \
The library supports major XML security standards:
- XML Signature
- XML Encryption
- Canonical XML (part of the LibXML2)
- Exclusive Canonical XML (part of the LibXML2)"
HOMEPAGE="https://www.aleksey.com/xmlsec/"
COPYRIGHT="2002-2021 Aleksey Sanin"
LICENSE="MIT"
REVISION="1"
SOURCE_URI="https://www.aleksey.com/xmlsec/download/xmlsec1-$portVersion.tar.gz"
CHECKSUM_SHA256="26041d35a20a245ed5a2fb9ee075f10825664d274220cb5190340fa87a4d0931"
SOURCE_DIR="xmlsec1-$portVersion"

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

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

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

PROVIDES="
	xmlsec$secondaryArchSuffix = $portVersion
	cmd:xmlsec1$commandSuffix = $portVersion
	lib:libxmlsec1$secondaryArchSuffix = $libVersionCompat
	lib:libxmlsec1_openssl$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libltdl$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libxslt$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	xmlsec${secondaryArchSuffix}_devel = $portVersion
	cmd:xmlsec1_config$commandSuffix = $portVersion
	devel:libxmlsec1$secondaryArchSuffix = $libVersionCompat
	devel:libxmlsec1_gcrypt$secondaryArchSuffix = $libVersionCompat
	devel:libxmlsec1_nss$secondaryArchSuffix = $libVersionCompat
	devel:libxmlsec1_openssl$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	xmlsec$secondaryArchSuffix == $portVersion base
	xmlsec${secondaryArchSuffix}_gcrypt == $portVersion
	xmlsec${secondaryArchSuffix}_nss == $portVersion
	"

COPYRIGHT_nss="2002-2018 Aleksey Sanin
	2003 America Online, Inc."
PROVIDES_nss="
	xmlsec${secondaryArchSuffix}_nss = $portVersion
	lib:libxmlsec1_nss$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_nss="
	haiku$secondaryArchSuffix
	xmlsec$secondaryArchSuffix == $portVersion base
	lib:libnspr4$secondaryArchSuffix
	lib:libnss3$secondaryArchSuffix
	lib:libplc4$secondaryArchSuffix
	lib:libplds4$secondaryArchSuffix
	lib:libsmime3$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libxslt$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_gcrypt="
	xmlsec${secondaryArchSuffix}_gcrypt = $portVersion
	lib:libxmlsec1_gcrypt$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_gcrypt="
	haiku$secondaryArchSuffix
	xmlsec$secondaryArchSuffix == $portVersion base
	lib:libgcrypt$secondaryArchSuffix
	lib:libgpg_error$secondaryArchSuffix
	lib:libxml2$secondaryArchSuffix
	lib:libxslt$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libcrypto$secondaryArchSuffix
	devel:libgcrypt$secondaryArchSuffix
#	devel:libgnutls$secondaryArchSuffix
	devel:libltdl$secondaryArchSuffix
	devel:libnspr4$secondaryArchSuffix
	devel:libnss3$secondaryArchSuffix
	devel:libplc4$secondaryArchSuffix
	devel:libplds4$secondaryArchSuffix
	devel:libsmime3$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libxslt$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:cmp
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage xmlsec$secondaryArchSuffix \
	"$libDir"/libxmlsec1.so.$libVersion \
	"$libDir"/libxmlsec1-openssl.so.$libVersion \
	"${libDir/$portName/${portName}_nss}"/libxmlsec1-nss.so.$libVersion \
	"${libDir/$portName/${portName}_gcrypt}"/libxmlsec1-gcrypt.so.$libVersion \


BUILD()
{
	runConfigure --omit-dirs binDir ./configure \
		--bindir=$commandBinDir

	make $jobArgs
}

INSTALL()
{
	make install

	# prepare develop/lib
	for l in "" -openssl -nss -gcrypt; do
		rm -f $libDir/libxmlsec1$l.la
		prepareInstalledDevelLib libxmlsec1$l
		ln -s $libDir/libxmlsec1$l.so.$portVersion $libDir/libxmlsec1$l.so
	done
	fixPkgconfig

	# devel package
	packageEntries devel \
		$commandBinDir/xmlsec1-config \
		$developDir \
		$dataDir/aclocal \
		$manDir/man1/xmlsec1-config.1

	# openssl is compiled as default, so xmlsec1 command requires it to work
	packageEntries nss \
		$libDir/libxmlsec1-nss*
	packageEntries gcrypt \
		$libDir/libxmlsec1-gcrypt*
}

TEST()
{
	# test crashes
	make check
}
