# Template file for 'bind'
pkgname=bind
_distver=9.9.2
_patchver=P2
version="${_distver}.${_patchver}"
wrksrc="bind-${_distver}-${_patchver}"
revision=1
short_desc="Berkeley Internet Name Domain server"
maintainer="Juan RP <xtraeme@gmail.com>"
license="ISC"
homepage="http://www.isc.org/software/bind/"
distfiles="http://ftp.isc.org/isc/bind9/${_distver}-${_patchver}/bind-${_distver}-${_patchver}.tar.gz"
checksum=ff822734e3550969251411e20f6f7397d14a912613a42af423752e93fdb565d2
long_desc="
 BIND is by far the most widely used DNS software on the Internet. It provides
 a robust and stable platform on top of which organizations can build
 distributed computing systems with the knowledge that those systems are fully
 compliant with published DNS standards."

hostmakedepends="automake libtool perl"
makedepends="openssl-devel mit-krb5-devel libxml2-devel
 libcap-devel readline-devel"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" libxml2-devel"
fi

pre_configure() {
	# disable bin tests for now.
	sed -e "s,tests,,g" -i bin/Makefile.in
	rm -f aclocal.m4 libtool
	autoreconf -fi
}

do_configure() {
	if [ "$CROSS_BUILD" ]; then
		configure_args+=" --with-openssl=$XBPS_CROSS_BASE
			--with-gssapi=$XBPS_CROSS_BASE
			--with-libxml2=$XBPS_CROSS_BASE"
	fi

	./configure ${configure_args} --disable-static \
		--enable-threads --enable-largefile \
		--with-libtool --enable-atomic --sysconfdir=/etc/named \
		--enable-epoll --with-gost=no --enable-ipv6 \
		--with-randomdev=/dev/urandom
}

do_build() {
	make ${makejobs}
}

do_install() {
	make DESTDIR=$DESTDIR install

	vinstall ${FILESDIR}/named.service 644 usr/lib/systemd/system
	vinstall ${FILESDIR}/named.logrotate 600 etc/logrotate.d named
	vinstall ${FILESDIR}/named.conf 640 etc/named

	vinstall bin/tests/system/common/root.hint 640 var/named
	vinstall ${FILESDIR}/127.0.0.zone 640 var/named
	vinstall ${FILESDIR}/localhost.zone 640 var/named
}

bind-libs_package() {
	short_desc="Berkeley Internet Name Domain server - Runtime libraries"
	pkg_install() {
		vmove "usr/lib/*.so*"
	}
}

bind-utils_package() {
	short_desc="Berkeley Internet Name Domain server - DNS utils"
	pkg_install() {
		for f in dig host nslookup; do
			vmove usr/bin/${f}
			vmove usr/share/man/man1/$(basename ${f}).1
		done
	}
}

bind-devel_package() {
	depends="bind-libs>=$version"
	short_desc="Berkeley Internet Name Domain server - development files"
	pkg_install() {
		vmove usr/bin/isc-config.sh
		vmove usr/share/man/man1/isc-config.sh.1
		vmove usr/include
		vmove usr/share/man/man3
	}
}

bind_package() {
	systemd_services="named.service true"
	conf_files="/etc/named/named.conf"
	system_accounts="named"
	named_desc="BIND DNS server"
	named_homedir="/var/named"
	named_shell="/bin/false"
	make_dirs="/var/named 0770 root named"
	depends="shadow"
	pkg_install() {
		vmove all
	}
}
