# $Id: Portfile 92526 2012-04-30 20:31:39Z dluke@macports.org $

PortSystem 1.0

name			bind9
version			9.9.0
revision		1

categories		net
maintainers		geeklair.net:dluke
platforms		darwin freebsd sunos

description		Domain Name System server
# license is actually ISC, a BSD style license, though.
# see http://www.isc.org/software/license
license			BSD

long_description	The BIND DNS Server is used on the vast majority of name \
				serving machines on the Internet, providing a robust \
				and stable architecture on top of which an \
				organization's naming architecture can be built. The \
				resolver library included in the BIND distribution \
				provides the standard APIs for translation between domain names \
				and Internet addresses and is intended to be linked with applications \
				requiring name service.

homepage		http://www.isc.org

distname		bind-${version}
master_sites		isc:${name}/${version}

# Patch for segfault see https://kb.isc.org/article/AA-00664
patchfiles		patch-lib-dns-resolver.c.diff

checksums	md5	9281d0b04f711d28153ba1ab04a54026 \
		sha1	6be77c75c8649088b0ae7124d819b5f412bb0094 \
		rmd160	5fda36a3aa84062f7936978cb540e8ad3f1c4e08

depends_lib		port:openssl port:libxml2

use_parallel_build	no
universal_variant	no

test.run		yes
test.target		test

startupitem.create	yes
startupitem.netchange	yes
startupitem.executable	${prefix}/sbin/named -f

configure.env		STD_CDEFINES=-DDIG_SIGCHASE=1

configure.args		--mandir=${prefix}/share/man \
				--with-openssl=${prefix} \
				--with-libxml2=${prefix} \
				--enable-threads \
				--enable-ipv6

platform darwin 9 {
	configure.args-append --with-dlopen=no
}

post-destroot	{
	# Ensure needed directories
	xinstall -m 755 -d \
		${destroot}${prefix}/var/named \
		${destroot}${prefix}/var/run
	
	# Install the conf file as a sample
	xinstall -o root -m 644 ${filespath}/named.conf \
		${destroot}${prefix}/etc/named.conf.dist
	reinplace "s|%%PREFIX%%|${prefix}|g" \
		${destroot}${prefix}/etc/named.conf.dist
	
	# Install the db files as samples
	foreach f "db.127.0.0 db.cache db.localhost" {
		xinstall -o root -m 644 ${filespath}/${f} \
			${destroot}${prefix}/var/named/${f}.dist
	}

	destroot.keepdirs ${destroot}${prefix}/var/run
}

notes "******************************************************
* To setup named to run, you need to copy named.conf.dist
* to named.conf:
* sudo cp ${prefix}/etc/named.conf.dist ${prefix}/etc/named.conf
* and edit as needed. If you use the default zone files for
* 127.0.0, localhost, and the cache, you also need to copy
* those files:
* sudo cp ${prefix}/var/named/db.127.0.0.dist ${prefix}/var/named/db.127.0.0
* sudo cp ${prefix}/var/named/db.cache.dist ${prefix}/var/named/db.cache
* sudo cp ${prefix}/var/named/db.localhost.dist ${prefix}/var/named/db.localhost
******************************************************"

variant dlz_mysql5 description {Dynamically Loaded Zones (dlz) stored in MySQL 5.x} {
	depends_lib-append \
		path:bin/mysql_config5:mysql5
	patchfiles-append patch-configure
	patchfiles-append patch-contrib-dlz-config.dlz.in
	# Threads are not safe when bind9 is compiled with dlz
	configure.args-delete \
		--enable-threads
	configure.args-append \
		--with-dlz-mysql=${prefix}/bin/mysql_config5 \
		--disable-threads
}
