# $Id: Portfile,v 1.28 2005/07/02 17:18:57 michaelm Exp $

PortSystem 1.0
name            exim
version         4.52
categories      mail
description     complete replacement for sendmail
long_description        Exim is a mail transfer agent (MTA) developed \
                        at the University of Cambridge for use on Unix \
                        systems connected to the Internet. It is freely \
                        available under the terms of the GNU General \
                        Public Licence. In overall style it is similar \
                        to Smail 3, but its facilities are more extensive.
homepage        http://www.exim.org/
platforms       darwin
maintainers     michaelm@opendarwin.org
master_sites    ftp://ftp.csx.cam.ac.uk/pub/software/email/exim/exim4/ \
                ftp://ftp.exim.org/pub/exim/exim4/
checksums       md5 299a40aaa75ee9de9f6048239cbfc38c
depends_build   bin:perl:perl5.8
depends_lib     port:db4 port:openssl
depends_run     path:/Library/StartupItems/DarwinPortsStartup:DarwinPortsStartup

set exim_user   exim
patch.pre_args  -p1

configure   {   cd ${worksrcpath}
                system "cp src/EDITME Local/Makefile"
                reinplace "s|/usr/exim/bin|${prefix}/sbin|g" Local/Makefile
                reinplace "s|/usr/exim/configure|${prefix}/etc/exim/exim.conf|g" Local/Makefile
                reinplace "s|EXIM_USER=|EXIM_USER=${exim_user}|g" Local/Makefile
                reinplace "s|/var/spool/exim|${prefix}/var/spool/exim|g" Local/Makefile
                reinplace "s|EXIM_MONITOR=eximon.bin|#EXIM_MONITOR=eximon.bin|g" Local/Makefile
                reinplace "s|# WITH_CONTENT_SCAN=yes|WITH_CONTENT_SCAN=yes|g" Local/Makefile       
                reinplace "s|# LOOKUP_PASSWD=yes|LOOKUP_PASSWD=yes|g" Local/Makefile
                reinplace "s|# LOOKUP_CDB=yes|LOOKUP_CDB=yes|g" Local/Makefile
                reinplace "s|# LOOKUP_DSEARCH=yes|LOOKUP_DSEARCH=yes|g" Local/Makefile
                reinplace "s|# SUPPORT_MAILDIR=yes|SUPPORT_MAILDIR=yes|g" Local/Makefile       
                reinplace "s|# TLS_LIBS=-L/usr/local/openssl/lib|TLS_LIBS=-L${prefix}/lib|g" Local/Makefile       
                reinplace "s|# TLS_INCLUDE=-I/usr/local/openssl/include|TLS_INCLUDE=-L${prefix}/include/openssl|g" Local/Makefile       
                reinplace "s|# Exim: OS-specific make file for Darwin (Mac OS X).|INCLUDE=-I${prefix}/include/db4|g" OS/Makefile-Darwin                
                reinplace "s|DBMLIB =|DBMLIB=${prefix}/lib/libdb-4.dylib|g" OS/Makefile-Darwin                
                reinplace "s|/etc/aliases|${destroot}${prefix}/etc/aliases|g" scripts/exim_install
                adduser ${exim_user} gid=[existsgroup mail] }

destroot.destdir    ROOT=${destroot}
destroot.keepdirs   ${destroot}${prefix}/var/spool/exim

post-destroot { system "mv ${destroot}${prefix}/etc/exim/exim.conf ${destroot}${prefix}/etc/exim/exim.conf.sample"
                xinstall -o root -m 755 -d ${destroot}${prefix}/share/exim
                cd ${worksrcpath}
                system "cp -R doc/ ${destroot}${prefix}/share/exim"
                xinstall -o ${exim_user} -g mail -m 750 -d ${destroot}${prefix}/var/spool/exim
                xinstall -o root -m 755 -d ${destroot}${prefix}/etc/rc.d
                xinstall -o root -m 755 -c \
                  ${portpath}/files/exim.sh ${destroot}${prefix}/etc/rc.d
                reinplace "s|__PREFIX|${prefix}|g" ${destroot}${prefix}/etc/rc.d/exim.sh }


platform darwin 6 {

    if {[variant_isset mysql] || [variant_isset mysql4]} {
        patchfiles-append patch-EDITME
        reinplace "s|LOOKUP_LIBS=-lresolv|LOOKUP_LIBS=-L${prefix}/lib/mysql -L${prefix}/lib -L/usr/lib -lmysqlclient|g" ${filespath}/patch-EDITME
    }
}

platform darwin 7 { 
    patchfiles-append   patch-EDITME
    if {[variant_isset mysql] || [variant_isset mysql4]} {
        reinplace "s|LOOKUP_LIBS=-lresolv|LOOKUP_LIBS=-L${prefix}/lib/mysql -L${prefix}/lib -L/usr/lib -lresolv -lmysqlclient|g" ${filespath}/patch-EDITME
    }
    
}

variant mysql4 { depends_lib-append      lib:libmysqlclient:mysql4 }

post-configure {
    reinplace "s|# AUTH_CRAM_MD5=yes|AUTH_CRAM_MD5=yes|g" Local/Makefile
    reinplace "s|# AUTH_PLAINTEXT=yes|AUTH_PLAINTEXT=yes|g" Local/Makefile
    reinplace "s|# AUTH_SPA=yes|AUTH_SPA=yes|g" Local/Makefile  
    reinplace "s|# SUPPORT_TLS=yes|SUPPORT_TLS=yes|g" Local/Makefile
    reinplace "s|# TLS_LIBS=-lssl -lcrypto|TLS_LIBS=-lssl -lcrypto|g" Local/Makefile
    reinplace "s|# LDAP_LIB_TYPE=OPENLDAP2|LDAP_LIB_TYPE=OPENLDAP2|g" Local/Makefile
    reinplace "s|# LOOKUP_LIBS=-L/usr/local/lib -lldap -llber -lmysqlclient -lpq -lgds|LOOKUP_LIBS=-lldap|g" Local/Makefile

    if {[variant_isset mysql] || [variant_isset mysql4]} {
        reinplace "s|# LOOKUP_MYSQL=yes|LOOKUP_MYSQL=yes|g" Local/Makefile
        reinplace "s|# LOOKUP_INCLUDE=.*|LOOKUP_INCLUDE=-I ${prefix}/include/mysql -I ${prefix}/include -I /usr/include|g" Local/Makefile
    }

}

