# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Jonathan Curran <jonathan@curran.in>
# Contributor: Shiz <hi@shiz.me>
# Maintainer: Jonathan Curran <jonathan@curran.in>
pkgname=opensmtpd
pkgver=6.0.2p1
pkgrel=7
pkgdesc="secure, reliable, lean, and easy-to configure SMTP server"
url="http://www.opensmtpd.org"
arch="all"
license="ISC"
depends="!postfix"
makedepends="automake autoconf libtool mdocml db-dev libasr-dev libevent-dev
	fts-dev zlib-dev libressl-dev bison flex-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
source="https://www.opensmtpd.org/archives/$pkgname-$pkgver.tar.gz
	smtpd.initd
	aliases
	autoconf-decl-checks.patch
	missing-decls.patch
	libressl-compat.patch"
options="suid !check"
builddir="$srcdir"/$pkgname-$pkgver

build() {
	cd "$builddir"
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc/smtpd \
		--with-libssl=/usr/include/openssl \
		--mandir=/usr/share/man \
		--libexecdir=/usr/lib \
		--with-path-mbox=/var/spool/mail \
		--with-table-db \
		--with-user-queue=smtpq \
		--with-group-queue=smtpq \
		--with-user-smtpd=smtpd \
		--with-path-socket=/run \
		--with-libs="-lfts" \
		--with-pie \
		--with-path-CAfile=/etc/ssl/certs/ca-certificates.crt \
		--with-mantype=doc
	make
}

package() {
	make DESTDIR="$pkgdir" -C "$builddir" install

	sed -i 's#/etc/mail#/etc/smtpd#g' "$pkgdir"/etc/smtpd/smtpd.conf

	install -Dm755 "$srcdir"/smtpd.initd "$pkgdir"/etc/init.d/smtpd
	install -Dm644 "$srcdir"/aliases "$pkgdir"/etc/smtpd/aliases

	# Create compatibility symlinks for mailq, newaliases, makemap and sendmail.
	local binary; for binary in mailq newaliases makemap sendmail; do
		ln -s /usr/sbin/smtpctl "$pkgdir"/usr/sbin/$binary
	done
	rmdir "$pkgdir"/usr/bin
}

sha512sums="1e4275795dd2c43174ffa268398a0d9864ce4cb7d370330f7b8c55a9b40e757616bbd280919a409ebde403769e3dea62047857dc2ff98d7ecce660b459c7ff1c  opensmtpd-6.0.2p1.tar.gz
8d3b27c760df84804baadc90c23b34f3e99980fae97c685f98ab096c3e84ab293316cd7c49317fa3cffac7ab5e63217ada6a2c5b245f352bafe880b087e7705e  smtpd.initd
51d47b34eb3d728daa45f29d6434cc75db28dfa69b6fb3ecd873121df85b296a2d2c81016d765a07778aa26a496e4b29c09a30b82678cf42596a536734b5deca  aliases
e61b7b0ab98acca9c092469d3ed756161225af5126e2fc0611b2676b8e1df05db7037549febe85b860fa48e47536a01fa3bfa37976f42e47666065ba4198e903  autoconf-decl-checks.patch
217e7212345f4202bf7e136b2d5b347a9967ea10d15ef50a216bfcd8e4a522076e4ee2044d18a606baf670c0fe6a339951b6381cdb9047730e06987ab7796790  missing-decls.patch
67b5bb221f10e014749592d24f7681bea6872785fa4a70e4e4b978f94859b527c4999aabb489586f7c19fac182acca450bdfa01af3ebc52c009f723830212058  libressl-compat.patch"
