# Maintainer: Max Rees <maxcrees@me.com>
pkgname=xmlsec
pkgver=1.3.4
_pkgname="$pkgname${pkgver%%.*}"
pkgrel=0
pkgdesc="C-based XML signature and encryption syntax and processing library"
url="https://www.aleksey.com/xmlsec/"
arch="all"
license="MIT"
depends=""
checkdepends="nss-tools"
makedepends="gnutls-dev libgcrypt-dev libtool libxml2-dev libxslt-dev
	nss-dev openssl-dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-gcrypt $pkgname-gnutls
	$pkgname-nss"
source="https://github.com/lsh123/xmlsec/releases/download/${pkgver}/${_pkgname}-${pkgver}.tar.gz
	testrun.patch"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-static \
		--enable-pkgconfig \
		--with-openssl \
		--with-gnutls \
		--with-gcrypt \
		--with-default-crypto='openssl' \
		--enable-md5=no
	make
}

check() {
	make -k check
}

package() {
	make DESTDIR="$pkgdir" install

	install -m755 -d "$pkgdir/usr/share/licenses/$pkgname"
	install -m644 'COPYING' "$pkgdir/usr/share/licenses/$pkgname/"
}

dev() {
	default_dev
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/xmlsec1Conf.sh "$subpkgdir"/usr/lib
}

gcrypt() {
	pkgdesc="xmlsec gcrypt plugin"
	install_if="$pkgname=$pkgver-r$pkgrel gcrypt"
	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libxmlsec1-gcrypt.so* "$subpkgdir"/usr/lib/
}

gnutls() {
	pkgdesc="xmlsec gnutls plugin"
	install_if="$pkgname=$pkgver-r$pkgrel gnutls"
	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libxmlsec1-gnutls.so* "$subpkgdir"/usr/lib/
}

nss() {
	pkgdesc="xmlsec NSS plugin"
	install_if="$pkgname=$pkgver-r$pkgrel nss"
	mkdir -p "$subpkgdir"/usr/lib/
	mv "$pkgdir"/usr/lib/libxmlsec1-nss.so* "$subpkgdir"/usr/lib/
}

sha512sums="959a97ed7d7cbdc3e5ef037b2cb4f05bda299274c09ed3dfe24f7203d97e3dfc13bf480e15a2d15bcc7893569d341204884de58cc9b462b6c29306b67672e9c7  xmlsec1-1.3.4.tar.gz
d29fad9689d6c8d9583802143bdfa38b27fbcc2e54232a052138da08f495b40de677849e3c1062070ef2d2efe59357d6efa6b7df429ea6563ea6b6cb126c3b6f  testrun.patch"