# Template file for 'openldap'
pkgname=openldap
version=2.6.9
revision=1
build_style=gnu-configure
configure_args="--prefix=/usr
 --libexecdir=/usr/libexec
 --sysconfdir=/etc
 --localstatedir=/var/lib/openldap
 --sbindir=/usr/bin
 --enable-dynamic --with-tls --enable-ldap
 --enable-ipv6 --enable-local --with-cyrus-sasl --with-threads
 --enable-syslog --enable-slapd --enable-crypt --enable-spasswd
 --enable-overlays=yes --enable-meta=yes
 --disable-static --with-yielding_select=yes --enable-modules"
hostmakedepends="pkg-config groff"
makedepends="openssl-devel libsasl-devel db-devel libltdl-devel"
depends="openldap-tools>=${version}_${revision}"
conf_files="/etc/openldap/ldap.conf /etc/openldap/slapd.conf /etc/openldap/slapd.ldif"
short_desc="OpenLDAP (Lightweight Directory Access Protocol)"
maintainer="Klara Modin <klarasmodin@gmail.com>"
license="OLDAP-2.0"
homepage="http://www.openldap.org"
distfiles="https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-${version}.tgz"
checksum=2cb7dc73e9c8340dff0d99357fbaa578abf30cc6619f0521972c555681e6b2ff

system_accounts="ldap"
ldap_homedir="/var/lib/openldap"

if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	makedepends+=" libxcrypt-devel"
fi

pre_configure() {
	sed -i 's|#define LDAPI_SOCK LDAP_RUNDIR LDAP_DIRSEP "run" LDAP_DIRSEP "ldapi"|#define LDAPI_SOCK LDAP_DIRSEP "run" LDAP_DIRSEP "openldap" LDAP_DIRSEP "ldapi"|' include/ldap_defaults.h
	sed -i 's|%LOCALSTATEDIR%/run|/run/openldap|' servers/slapd/slapd.{conf,ldif}
	sed -i 's|-$(MKDIR) $(DESTDIR)$(localstatedir)/run|-$(MKDIR) $(DESTDIR)/run/openldap|' servers/slapd/Makefile.in
}

pre_build() {
	make ${makejobs} ${make_build_args} depend
}

post_install() {
	ln -sf ../libexec/slapd ${DESTDIR}/usr/bin/slapd
	vsv slapd
	vlicense LICENSE
	chmod 755 ${DESTDIR}/usr/lib/*.so.*
	vmkdir usr/share/examples/openldap
	mv ${DESTDIR}/etc/openldap/*.default ${DESTDIR}/usr/share/examples/openldap
	chmod 0644 ${DESTDIR}/usr/share/examples/openldap/*
}


libldap-devel_package() {
	depends="${makedepends} libldap>=${version}_${revision}"
	short_desc+=" library - development files"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.so"
		vmove usr/share/man/man3
	}
}
libldap_package() {
	short_desc+=" library"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}

openldap-tools_package() {
	short_desc+=" - utilities"
	pkg_install() {
		vmove usr/bin/ldapmodrdn
		vmove usr/bin/ldapsearch
		vmove usr/bin/ldapcompare
		vmove usr/bin/ldapurl
		vmove usr/bin/ldapmodify
		vmove usr/bin/ldapexop
		vmove usr/bin/ldappasswd
		vmove usr/bin/ldapwhoami
		vmove usr/bin/ldapdelete
		vmove usr/bin/ldapadd
		vmove usr/bin/ldapvc
		vmove usr/share/man/man1/ldapmodrdn.1
		vmove usr/share/man/man1/ldapsearch.1
		vmove usr/share/man/man1/ldapcompare.1
		vmove usr/share/man/man1/ldapurl.1
		vmove usr/share/man/man1/ldapmodify.1
		vmove usr/share/man/man1/ldapexop.1
		vmove usr/share/man/man1/ldappasswd.1
		vmove usr/share/man/man1/ldapwhoami.1
		vmove usr/share/man/man1/ldapdelete.1
		vmove usr/share/man/man1/ldapadd.1
		vmove usr/share/man/man1/ldapvc.1
	}
}
