PortSystem 1.0

name			maradns
version			1.2.12.09

set branch		[strsed ${version} {s/\.[0-9]*\.[0-9]*$//}]

categories		net
license			BSD
platforms		darwin
maintainers		nomaintainer
description		DNS server supporting authoritative, recursive and caching DNS
long_description	MaraDNS is a fully functional DNS server supporting \
			authoritative DNS, recursive DNS, and caching DNS.

homepage		http://www.maradns.org/
master_sites		http://www.maradns.org/download/${branch}/${version} \
			sourceforge
			
checksums		md5	ee82cb6d4989cee2b9937257dc48c025 \
			sha1	091964ee898d1ee79e35b9e8bb42ae1df5b076e0 \
			rmd160	47b4816d125883d0a7d676677102fc906546f2f8

use_bzip2		yes

patchfiles		patch-configure.diff patch-install.darwin.diff \
			patch-build__Makefile.darwin.diff

post-extract {
# Delete unneeded stress-testing code (not built by default).  It may be worth
# adding this as a variant in a future revision.
	file delete -force ${worksrcpath}/sqa
# Delete Portuguese documentation sources (documentation not built by default;
# will need to add a section to build these docs if localisation desired)
	file delete -force ${worksrcpath}/doc/pt_br
# Delete unneeded English documentation sources (documentation already built)
# and support files that will otherwise be installed in the doc directories
	file delete -force ${worksrcpath}/doc/en/source
	file delete ${worksrcpath}/doc/en/man/read.manpage
	file delete ${worksrcpath}/doc/en/pdf/tmac.an.patch
	file delete \
		{*}[glob ${worksrcpath}/doc/en/*/{Makefile,*.embed,make.*}]
# Fix installation script (called by "make install") so that configuration
# files and directories are placed in destroot
	reinplace "s|\$RPM_BUILD_ROOT|${destroot}${prefix}|g" \
		${worksrcpath}/build/install.sh
# Fix hardcoding of default paths to chroot, log and zone file dirs, and
# configuration file, in source and docs. copy.devs.c is only used if maradns
# is built for Solaris, and maraconf.sh is neither installed by default nor yet
# by this Portfile, but hey.
	set marabindocpages	"duende maradns mararc zoneserver"
	set marasetupdocpages	"authoritative compile convert dangling \
		dnsmaster dnsslave dnstcp quick_start recursive update"
	set marareinplace	"s|/etc/mara|${prefix}/etc/mara|g"
	foreach docpage ${marabindocpages} {
		reinplace "${marareinplace}" \
		${worksrcpath}/doc/en/text/man.${docpage}.txt \
		${worksrcpath}/doc/en/tutorial/man.${docpage}.html
	}
	foreach docpage ${marasetupdocpages} {
		reinplace "${marareinplace}" \
		${worksrcpath}/doc/en/text/${docpage}.txt \
		${worksrcpath}/doc/en/tutorial/${docpage}.html
	}
	reinplace "${marareinplace}" \
		${worksrcpath}/MaraDns.h \
		${worksrcpath}/build/copy.devs.c \
		${worksrcpath}/parse/ParseMaraRc.c \
		${worksrcpath}/tools/maraconf.sh \
		${worksrcpath}/doc/en/QuickStart \
		${worksrcpath}/doc/en/examples/example_authoritative_mararc.txt \
		${worksrcpath}/doc/en/examples/example_full_mararc \
		${worksrcpath}/doc/en/examples/example_mararc \
		${worksrcpath}/doc/en/examples/example_recursive_mararc.txt \
		${worksrcpath}/doc/en/man/duende.8 \
		${worksrcpath}/doc/en/man/maradns.8 \
		${worksrcpath}/doc/en/man/zoneserver.8 \
		${worksrcpath}/doc/en/man/mararc.5
}


configure.pre_args

build.args	CPPFLAGS=${configure.cppflags} \
		CFLAGS=${configure.cflags} \
		LDFLAGS=${configure.ldflags}

destroot.env	PREFIX=${destroot}${prefix}
destroot.destdir

# Keep chroot directory for duende (monitors and logs maradns instances)
#
# (This places a .turd file in the logger directory, but the duende man page
# states that it requires a _blank_ logger directory to run (emphasis added).
# Testing has not revealed any interference from the .turd file so far, but
# the testing done may not have been exhaustive (I don't know enough about
# chroot jails).)
destroot.keepdirs	${destroot}${prefix}/etc/maradns/logger

post-destroot {
# Delete remaining unneeded build files; this also deletes the man page for
# the mqhash tool, which is not installed by default, but it appears to be only
# for development testing.
	file delete -force \
		${destroot}${prefix}/share/doc/maradns-${version}/Makefile \
		${destroot}${prefix}/share/doc/maradns-${version}/man
	file rename ${destroot}${prefix}/etc/mararc \
		${destroot}${prefix}/etc/example-mararc
}

startupitem.create	yes
startupitem.init	\
	"PID=${prefix}/var/run/${name}.pid\nBIN=${prefix}/sbin/maradns"
startupitem.start	"\[ -x \${BIN} \] && \${BIN} &; echo \$! > \${PID}"
startupitem.stop	"\[ -r \${PID} \] && /bin/kill \$(cat \${PID})"

post-install {
	ui_msg "***************************************************************"
	ui_msg "* To make MaraDNS functional, you will need to create"
	ui_msg "* ${prefix}/etc/mararc.  Please read the mararc man page"
	ui_msg "* for details.  Example mararc files are in"
	ui_msg "* ${prefix}/share/doc/maradns-${version}/examples ."
	ui_msg "***************************************************************"
}

variant authonly description {Build only the authoritative DNS server, omitting the recursive one} {
	configure.args-append	--authonly
	startupitem.init	\
		"PID=${prefix}/var/run/${name}.pid\nBIN=${prefix}/sbin/maradns.authonly"
}

livecheck.type  regex
livecheck.url   http://www.maradns.org/download/${branch}/${version}/
livecheck.regex ${name}-(\\d+\\.\\d+\\.\\d+\\.\\d+)${extract.suffix}
