# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../djbdns/djbdns.conf
# Copyright (C) 2007 - 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if [ "$prefix_auto" == 1 ]; then
	prefix=opt/djbdns
	set_confopt
fi

makeopt="$makeopt prog"
makeinstopt=

pkg_djbdns_config() {
	echo $CC > conf-cc
	echo $CC > conf-ld
	echo /$prefix > conf-home
	echo -e "#include \"auto_home.h\"
const char auto_home[]=\"/$prefix\";" > auto_home.c
}

pkg_djbdns_install() {
	while read dir file ; do
		mkdir -p $root/$prefix/$dir
		cp $file $root/$prefix/$dir/$file
	done < <( grep "c(.*man\|c(.*bin" hier.c | cut -d \" --output-delimiter ' '  -f 2,4 )
}

hook_add premake 5 'pkg_djbdns_config'
hook_add postmake 4 'pkg_djbdns_install'
hook_add postmake 5 'pkg_djbdns_installman'
pkg_djbdns_installman() {
	local x= saved_pwd=$PWD
	cd $builddir

	tar -v $taropt `match_source_file -p djbdns.*man`
	cd djbdns-man
	for x in 1 5 8; do
		gzip *.$x
		mkdir -p $root/$mandir/man$x/
		cp -v *.$x.gz $root/$mandir/man$x/
	done

	cd $saved_pwd
}

[ "$SDECFG_PKG_DJBDNS_SIGHUP" = "1" ] && \
	var_append patchfiles ' ' "`match_source_file -p tinydns_sighup`"
[ "$SDECFG_PKG_DJBDNS_MULTIDATA" = "1" ] && \
	var_append patchfiles ' ' "`match_source_file -p multi_data`"
if [ "$SDECFG_PKG_DJBDNS_DUMPCACHE" = "1" ]; then
	[ "$SDECFG_PKG_DJBDNS_SIGHUP" = "1" ] &&
		var_append patchfiles ' ' "`match_source_file -p dumpcache_over_sighup-v4`" ||
		var_append patchfiles ' ' "`match_source_file -p dumpcache-v4`"
fi
[ "$SDECFG_PKG_DJBDNS_FWDZONE" = "1" ] && \
	var_append patchfiles ' ' "`match_source_file -p fwdzone`"