# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=djbdns
pkgver=1.05
pkgrel=47
pkgdesc="Excellent high-performance DNS services"
url="http://cr.yp.to/djbdns.html"
arch="all"
license="Public-Domain"
subpackages="djbdns-common tinydns dnscache $pkgname-doc"
source="http://cr.yp.to/djbdns/$pkgname-$pkgver.tar.gz
http://www.fefe.de/dns/djbdns-1.05-test25.diff.bz2
	headtail.patch
	dnsroots.patch
	dnstracesort.patch
	djbdns-1.05-jumbo-josb.patch
	$pkgver-errno.patch
	$pkgver-response.patch
	tinydns.pre-install
	tinydns.initd
	tinydns.confd
	dnscache.initd
	dnscache.confd
	dnscache.monthly
	"

builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	default_prepare
	cd "$builddir"
	# remove all the generated headers. they came with the jumbo patch and should
	# never have been there...
	sed -n 's/^\([a-z0-9]\+\.h\):.*/\1/gp' Makefile Makefile.sig | xargs rm -f
}

build() {
	cd "$builddir"
	echo "${CC:-"gcc"} ${CFLAGS}" > conf-cc
	echo "${CC:-"gcc"} ${LDFLAGS}" > conf-ld
	echo "/usr" > conf-home
	make -j1
}

package() {
	cd "$builddir"
	mkdir -p "$pkgdir"/etc/
	cp dnsroots.global "$pkgdir"/etc/
	mkdir -p "$pkgdir"/usr/bin
	cp *-conf dnscache tinydns walldns rbldns pickdns axfrdns \
		*-get *-data *-edit dnsip dnsipq dnsname dnstxt dnsmx \
		dnsfilter random-ip dnsqr dnsq dnstrace dnstracesort \
		"$pkgdir"/usr/bin/
	mkdir -p "$pkgdir"/usr/share/doc/djbdns
}

common() {
	pkgdesc="Base utilities of djbdns"
	replaces="djbdns"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dnsqr "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dnsip "$subpkgdir"/usr/bin
}

tinydns() {
	pkgdesc="A small and secure DNS server"
	install=tinydns.pre-install

	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/etc/tinydns \
		"$subpkgdir"/var/cache/tinydns
	mv "$pkgdir"/usr/bin/tinydns* "$subpkgdir"/usr/bin
	install -D -m755 "$srcdir"/tinydns.initd \
		"$subpkgdir"/etc/init.d/tinydns
	install -D -m644 "$srcdir"/tinydns.confd \
		"$subpkgdir"/etc/conf.d/tinydns
}

dnscache() {
	pkgdesc="A recursive resolver"
	install=dnscache.pre-install
	depends=djbdns-common

	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/etc/dnscache/ip \
		"$subpkgdir"/etc/dnscache/servers

	cp "$pkgdir"/etc/dnsroots.global "$subpkgdir"/etc/dnscache/servers/@
	touch "$subpkgdir"/etc/dnscache/ip/127

	mv "$pkgdir"/usr/bin/dnscache* "$subpkgdir"/usr/bin
	install -D -m755 "$srcdir"/dnscache.initd \
		"$subpkgdir"/etc/init.d/dnscache
	install -D -m644 "$srcdir"/dnscache.confd \
		"$subpkgdir"/etc/conf.d/dnscache
	install -D -m755 "$srcdir"/dnscache.monthly \
		"$subpkgdir"/etc/periodic/monthly/dnscache-hints-refresh
}

sha512sums="20f066402801d7bec183cb710a5bc51e41f1410024741e5803e26f68f2c13567e48eba793f233dfab903459c3335bc169e24b99d66a4c64e617e1f0779732fa9  djbdns-1.05.tar.gz
41cca597dba971010b9844071e0349d3a4b25cc4b144e12721b0bc8250589fb374e40ece8908f1081762597048179b1177e88b9a5f97be0b47b63e3183e654bb  djbdns-1.05-test25.diff.bz2
be4c9aea40c737364a56f188ad2276d90deac0dffb73ba4b659490836c0fe92ffb65ccf23c6724b913b2d6354336727004be0cf5b43ebc47abe7004700dfe1e8  headtail.patch
0cd97d833e0aaee2b82ed27b56ce183e9ab9806ff1e77bc61b7f38ae3168aa7310b12d2ed330713c4da97e60881ee339f6af449142cc29823865d87270733211  dnsroots.patch
ae9cd51f24041aed135b5ba88d1efd0310b8095bccd6fb60a986756b460a4f98a93e163c3ddae7c146d56a9d41778d17449f772b91fdc58d9e69523cf6c2a6e9  dnstracesort.patch
af7c0a0a2f519ec16ac2a937664b7984aafeb19d04fbd6e0fd0afa5482f3cb0b4ac5cf6a846d574a8591f3cec725b4f828cca95344c3c774cb77ee5630ff6617  djbdns-1.05-jumbo-josb.patch
086d02600034d486f084fd2500aba9041dfa02110781594cdc3781a3ad7823f61f11c54c053c8c1241f58660527abe536906aba0e7f6c49ed3b8dbd74ba8f2b7  1.05-errno.patch
407207f8387e2344fdebe68ab2213adbd9f1e6034e343b4359c8c1fa6ce36b0878a8367e4ee05cb4a44c199d4956aef0c6c8e84ab4f5556178547346ab88b82d  1.05-response.patch
20dd227e4f1362136070d914d5ee41082b5f16ee8602ad591e52b02f03ff0531d0589fff4352fc6799a8c192b69a99af1b013f87ee4ddbdffa03715d33e2f5af  tinydns.pre-install
797671630dd1943a0b0f5fb35ad4972f846752595fb9ddb1f5e4f75db81a59ab23e3f96bc29c814b5fcefdfcd9d55c39aa2835618cad877a74c0707376130aff  tinydns.initd
31b52bd4dd0f78ff63e105ff3937fb9bf582628fe7a04bfcba91195d4fc4b55b60869f993a42ef55a228892647af07ed7ea22cfff72812430c7b8207debdd8f1  tinydns.confd
31bf58ed6a049e02210ce1cbbea00b62e2fe92339cd861eb3ee35f16186a3904e85fcd2f056e2d788b8a284068d83a3767cef01519a6d0152f1958be8e418956  dnscache.initd
1b281a4892c1c9ad39a15c95d0fbd14b0ada69b31723250e33d96946bd19f3edc4b36ec90fb9b6b884d7907b7e86cc3980f116f16fe35fb7496feffd728b1ffa  dnscache.confd
70d3431db407d02f145cb1521d563559b536e89a6a88f50cf853036b2833d78b594398df30cc33c17debea23aa6a7112614741e13f8ec5d1429fad075273a9f6  dnscache.monthly"
