# Description: IMAP and POP3 server with ssl/ipv6 support, written with security primarily in mind
# URL: https://dovecot.org
# Maintainer: Juergen Daubert, jue at crux dot nu
# Depends on: bzip2 libcap linux-pam openssl sqlite3 xz zlib
# Optional: clucene cyrus-sasl icu krb5 libsodium lua lz4 mariadb nss openldap postgresql

name=dovecot
version=2.4.4
release=1
source=(https://dovecot.org/releases/2.4/$name-$version.tar.gz
    dovecot.rc dovecot.pam)

build() {
    cd $name-$version

    prt-get isinst clucene && PKGMK_DOVECOT+=' --with-lucene'
    prt-get isinst icu && PKGMK_DOVECOT+=' --with-icu'
    prt-get isinst krb5 && PKGMK_DOVECOT+=' --with-gssapi'
    prt-get isinst libsodium && PKGMK_DOVECOT+=' --with-sodium'
    prt-get isinst lua && PKGMK_DOVECOT+=' --with-lua=plugin' || PKGMK_DOVECOT+=' --without-lua'
    prt-get isinst mariadb && PKGMK_DOVECOT+=' --with-mysql'
    prt-get isinst openldap && PKGMK_DOVECOT+=' --with-ldap=plugin'
    prt-get isinst postgresql && PKGMK_DOVECOT+=' --with-pgsql'

    ./configure $PKGMK_DOVECOT \
        --prefix=/usr \
        --libexecdir=/usr/lib \
        --sysconfdir=/etc \
        --localstatedir=/var \
        --with-rundir=/run/dovecot \
        --with-moduledir=/usr/lib/dovecot/modules \
        --with-sql \
        --with-sqlite \
        --with-libcap \
        --with-pam

    make
    make DESTDIR=$PKG install

    # RC script
    install -D -m 755 $SRC/dovecot.rc $PKG/etc/rc.d/dovecot

    # PAM
    install -D -m 644 $SRC/dovecot.pam $PKG/etc/pam.d/dovecot

    # cleanup
    rm -r $PKG/usr/share/doc
}
