# $Id$
# Contributor: Jeff Brodnax <tullyarcher@bellsouth.net>
# Contributor: Paul Mattal <paul@archlinux.org>
# Maintainer: Gaetan Bisson <bisson@archlinux.org>

pkgname=postfix
pkgver=2.10.2
pkgrel=1
pkgdesc='Fast, easy to administer, secure mail server'
url='http://www.postfix.org/'
license=('custom')
arch=('i686' 'x86_64')
depends=('pcre' 'libsasl' 'db')
backup=('etc/postfix/'{access,aliases,canonical,generic,header_checks,main.cf,master.cf,relocated,transport,virtual})
source=("ftp://ftp.porcupine.org/mirrors/postfix-release/official/${pkgname}-${pkgver}.tar.gz"{,.sig}
        'aliases.patch'
        'service')
sha1sums=('4721024784d071c3e663d610db17f8bd99821f3d' 'SKIP'
          '5fc3de6c7df1e5851a0a379e825148868808318b'
          'dd12885d367bebaf0fc9d2e9823a7f82086b6ee9')

provides=('smtp-server' 'smtp-forwarder')
conflicts=('smtp-server' 'smtp-forwarder')

install=install

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	make makefiles DEBUG='' CCARGS=' \
		-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl \
		-DUSE_TLS \
		-DDEF_COMMAND_DIR=\"/usr/bin\" \
		-DDEF_DAEMON_DIR=\"/usr/lib/postfix\" \
		-DDEF_SENDMAIL_PATH=\"/usr/bin/sendmail\" \
#		-DDEF_README_DIR=\"/usr/share/doc/postfix\" \
		-DDEF_SAMPLE_DIR=\"/etc/postfix/sample\" \
		-DDEF_MANPAGE_DIR=\"/usr/share/man\" \
	' AUXLIBS=' \
		-lsasl2 \
		-lssl -lcrypto \
	' OPT="${CFLAGS} ${LDFLAGS}"

	make
}

package() {
	cd "${srcdir}/${pkgname}-${pkgver}"

	sh postfix-install -non-interactive install_root="${pkgdir}"

	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -Dm644 ../service "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"

	cd "${pkgdir}"
	patch -p0 -i "${srcdir}"/aliases.patch
	sed 's/^\(\$manpage[^:]*\):/\1.gz:/' -i "usr/lib/${pkgname}/postfix-files"
}