# $Id: Portfile 62920 2010-01-21 23:37:30Z ryandesign@macports.org $

PortSystem 1.0
PortGroup muniversal 1.0

name            openldap
version         2.4.21
categories      databases
maintainers     landonf
description     OpenLDAP Software 
long_description	OpenLDAP Software is an open source implementation \
			of the Lightweight Directory Access Protocol.  

platforms       darwin
homepage	http://www.openldap.org/
master_sites	ftp://ftp.OpenLDAP.org/pub/OpenLDAP/openldap-release/ \
		http://www.openldap.org/software/download/OpenLDAP/openldap-release/ \
		ftp://ftp.nl.uu.net/pub/unix/db/openldap/openldap-release/
extract.suffix	.tgz
checksums	md5     e7128c57b2bacd940e8906057c94ff26 \
		sha1    cfcfff3df7804bab8eb0d9464d3712a3e32d677b \
		rmd160  94f662e8fe1b009f5836cb9c19b095f1b159b1bd

depends_lib	path:bin/perl:perl5 \
		port:cyrus-sasl2 \
		port:openssl \
		port:db46 \
		port:icu

patchfiles	patch-ltmain

configure.env-append		LANG=C
configure.cppflags-append	-I${prefix}/include/db46 -I${prefix}/include/openssl -DBIND_8_COMPAT
configure.ldflags-append	-L${prefix}/lib/db46

configure.args	--mandir=${prefix}/share/man \
		--localstatedir=${prefix}/var \
		--with-cyrus-sasl \
		--with-tls \
		--enable-crypt \
		--enable-wrappers \
		--enable-syncprov \
                --enable-ipv6

startupitem.create      yes
startupitem.name	slapd
startupitem.init	"PID=${prefix}/var/run/slapd.pid"
startupitem.start       "${prefix}/libexec/slapd -u ldap -f ${prefix}/etc/openldap/slapd.conf"
startupitem.stop        "\[ -r \${PID} \] && kill \$(cat \${PID})"

variant aci description {Enable per-object ACIs (experimental)} {
        configure.args-append --enable-aci
}

pre-build {
    set dirs {}
    if {[variant_isset universal]} {
        foreach arch ${universal_archs_to_use} {
            lappend dirs ${worksrcpath}-${arch}
        }
    } else {
        lappend dirs ${worksrcpath}
    }
    foreach dir ${dirs} {
        system "cd ${dir} && make depend"
    }
}

pre-destroot {
	# should be in pre-deploy....
	addgroup ldap
	set gid [existsgroup ldap]
	adduser ldap gid=${gid}
}

post-destroot {
	xinstall -d -g ldap -m 700 -o ldap \
		"${destroot}${prefix}/var/run/openldap-data"
# Delete the duplicate .conf files (leaves .conf.default) so upgrades won't overwrite .conf files.
	file delete -force ${destroot}${prefix}/etc/openldap/slapd.conf
	file delete -force ${destroot}${prefix}/etc/openldap/ldap.conf
}

test.run	yes
test.target	check
