# Contributor: Shiz <hi@shiz.me>
# Maintainer: Shiz <hi@shiz.me>
pkgname=opensmtpd-extras
pkgver=201703132115
pkgrel=1
pkgdesc="OpenSMTPD addons"
url="https://opensmtpd.org/"
arch="all"
license="ISC"
depends=""
makedepends="libressl-dev libevent-dev python2-dev mariadb-dev postgresql-dev
	hiredis-dev sqlite-dev"
subpackages="$pkgname-doc"
source="https://www.opensmtpd.org/archives/$pkgname-$pkgver.tar.gz
	remove-decls.patch"
builddir="$srcdir/$pkgname-$pkgver"
options="!check"  # upstream does not provide tests

_extras="
	filter-monkey
	filter-stub
	filter-trace
	filter-void
	queue-null
	queue-python
	queue-ram
	queue-stub
	scheduler-python
	scheduler-ram
	scheduler-stub
	table-ldap
	table-mysql
	table-passwd
	table-postgres
	table-python
	table-redis
	table-socketmap
	table-sqlite
	table-stub
	"
for _extra in $_extras; do
	subpackages="$subpackages opensmtpd-$_extra:_package_extra"
	depends="$depends opensmtpd-$_extra"
done

build() {
	cd "$builddir"

	local with_extras
	local extra; for extra in $_extras; do
		with_extras="$with_extras --with-$extra"
	done

	./configure \
		--prefix=/usr \
		--sysconfdir=/etc/smtpd \
		--mandir=/usr/share/man \
		--libexecdir=/usr/lib \
		--with-pie \
		--with-mantype=man \
		$with_extras

	# the Redis table expects <hiredis.h> without subdirectory, so indulge it
	make REDIS_CPPFLAGS='-I /usr/include/hiredis'
}

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install
}

_package_extra() {
	local name="${subpkgname#opensmtpd-}"
	pkgdesc="OpenSMTPD $name addon"
	depends=""

	mkdir -p "$subpkgdir"/usr/lib/opensmtpd
	mv "$pkgdir"/usr/lib/opensmtpd/$name "$subpkgdir"/usr/lib/opensmtpd/
}

sha512sums="d841c63445ca674b368a5aa6012ae90e46b0c31b650067bdcea5badca3d818b1b732be880b2a18421fb39d07291dd413455944b178597bc13ae6ff5c75ac9aed  opensmtpd-extras-201703132115.tar.gz
36efd3b6cf75728cc8b75b3d9d6bf464d1e949ccfbe6151ed53dbba0f9ee1e50eb61afcca05af302ab359bc9ea1136e7750a15e5f5b824899141298d3060782a  remove-decls.patch"
