# $Id: Portfile,v 1.21 2006/08/09 05:45:01 jberry Exp $

PortSystem          1.0

name                dovecot
version             1.0.rc6
epoch               20060722

categories          mail
maintainers         yeled@opendarwin.org jberry@opendarwin.org
platforms           darwin

description         Secure, fast imap and pop3 server -- currently in alpha approaching final
long_description    Dovecot is an IMAP and POP3 server for Linux/UNIX-like \
                    systems, written with security primarily in mind. Although \
                    it's written in C, it uses several coding techniques to \
                    avoid most of the common pitfalls.

homepage            http://dovecot.org/

master_sites        ${homepage}releases/
distname            dovecot-${version}
checksums           rmd160  ddf49eece71d8766f994058ead1bed8410a9ee51 \
                    sha1    4d6c524dd52b54dc25d3114bee7fb0ae1120b994 \
                    md5     5c71b673d571e87bc084c494980e20a8

default_variants    +ssl
depends_lib         port:libiconv port:pkgconfig port:zlib

configure.args      --sysconfdir=${prefix}/etc/dovecot \
                    --localstatedir=${prefix}/var \
                    --without-ssl

post-configure {
    # madvise fails on darwin 7 and earlier, but is fixed on darwin 8
    if { ${os.platform} == "darwin" && [rpm-vercomp ${os.version} 8.0] < 0 } {
        reinplace "s|#define HAVE_MADVISE 1|/* #undef HAVE_MADVISE */|" ${worksrcpath}/config.h
    }
}

post-destroot   {
    # Create the dovecot user and group
    addgroup dovecot
    set gid [existsgroup dovecot]
    adduser dovecot gid=${gid} realname=Dovecot
}

platform darwin 7 {
    # Avoid broken poll
    configure.args-append --with-ioloop=select
}

platform darwin 8 {
    # Avoid broken poll
    configure.args-append --with-ioloop=select
}

platform darwin {
    post-patch {
    	# Reduce number of hardlink ops, nasty for HFS+
    	reinplace "s|set->use_excl_lock|/* set->use_excl_lock */ 1|"    ${worksrcpath}/src/lib/file-dotlock.c
        # Disable quotas, which don't build on Mac OS X at present
        reinplace "s|#define HAVE_FS_QUOTA|/* #undef HAVE_FS_QUOTA */|" ${worksrcpath}/src/plugins/quota/quota-fs.h
    }
}

variant ssl {
        depends_lib-append  port:openssl 
        configure.args-delete   --without-ssl
        configure.args-append   --with-ssl=openssl \
            --with-ssl-dir=${prefix}/etc/ssl
        configure.env-append    CPPFLAGS="-I${prefix}/include/openssl" \
            LDFLAGS="-L${prefix}/lib"
}

variant postgres    {   
    depends_lib-append  port:postgresql8
    configure.args-append   --with-pgsql
    configure.env-append    LDFLAGS="-L${prefix}/lib/pgsql8" \
        CPPFLAGS="-I${prefix}/include/pgsql8" 
}

variant rawlog  {   configure.args-append   --with-rawlog   }

variant ldap    {   configure.args-append   --with-ldap 
                depends_lib-append  port:openldap
}

startupitem.create  yes
startupitem.name    Dovecot
startupitem.start   ${prefix}/sbin/dovecot
startupitem.stop    "
    pidfile=${prefix}/var/run/dovecot/master.pid    
    \[ -r \${pidfile} \] && kill \$(cat \${pidfile})
    "
