# Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

# $Id: Makefile.in,v 1.5 2009/03/04 00:09:51 marka Exp $

srcdir =	@srcdir@
top_srcdir =	@top_srcdir@

@BIND9_MAKE_RULES@

MANDIR =	${DESTDIR}/${mandir}

TR = @TR@
SED = @SED@
TBL = @TBL@
NROFF = @NROFF@
MANROFF = ( ${TBL} | ${NROFF} -mandoc )

#
# Extensions for the generated manual entries
#
MAN_EXT = man
CAT_EXT = cat
LIB_NETWORK_EXT = 3
LIB_NETWORK_MAN_EXT = ${MAN_EXT}${LIB_NETWORK_EXT}
LIB_NETWORK_CAT_EXT = ${CAT_EXT}${LIB_NETWORK_EXT}
FORMAT_EXT = 5
FORMAT_MAN_EXT = ${MAN_EXT}${FORMAT_EXT}
FORMAT_CAT_EXT = ${CAT_EXT}${FORMAT_EXT}
DESC_EXT = 7
DESC_MAN_EXT = ${MAN_EXT}${DESC_EXT}
DESC_CAT_EXT = ${CAT_EXT}${DESC_EXT}

#
# Network library routines manual entries
#
LIB_NETWORK_BASE =	gethostbyname inet_cidr resolver hesiod getnetent \
			tsig getaddrinfo getnameinfo getipnodebyname
LIB_NETWORK_SRC = 	gethostbyname.${LIB_NETWORK_EXT} \
			inet_cidr.${LIB_NETWORK_EXT} \
			resolver.${LIB_NETWORK_EXT} \
			hesiod.${LIB_NETWORK_EXT} \
			getnetent.${LIB_NETWORK_EXT} \
			tsig.${LIB_NETWORK_EXT} \
			getaddrinfo.${LIB_NETWORK_EXT} \
			getnameinfo.${LIB_NETWORK_EXT} \
			getipnodebyname.${LIB_NETWORK_EXT}
LIB_NETWORK_MAN =	gethostbyname.${LIB_NETWORK_MAN_EXT} \
			inet_cidr.${LIB_NETWORK_MAN_EXT} \
			resolver.${LIB_NETWORK_MAN_EXT} \
			hesiod.${LIB_NETWORK_MAN_EXT} \
			getnetent.${LIB_NETWORK_MAN_EXT} \
			tsig.${LIB_NETWORK_MAN_EXT} \
			getaddrinfo.${LIB_NETWORK_MAN_EXT} \
			getnameinfo.${LIB_NETWORK_MAN_EXT} \
			getipnodebyname.${LIB_NETWORK_MAN_EXT}
LIB_NETWORK_CAT =	gethostbyname.${LIB_NETWORK_CAT_EXT} \
			inet_cidr.${LIB_NETWORK_CAT_EXT} \
			resolver.${LIB_NETWORK_CAT_EXT} \
			hesiod.${LIB_NETWORK_CAT_EXT} \
			getnetent.${LIB_NETWORK_CAT_EXT} \
			tsig.${LIB_NETWORK_CAT_EXT} \
			getaddrinfo.${LIB_NETWORK_CAT_EXT} \
			getnameinfo.${LIB_NETWORK_CAT_EXT} \
			getipnodebyname.${LIB_NETWORK_CAT_EXT}
LIB_NETWORK_OUT =	${LIB_NETWORK_MAN} ${LIB_NETWORK_CAT}

#
# File format manual entries
#
FORMAT_BASE =	resolver irs.conf
FORMAT_SRC = 	resolver.${FORMAT_EXT} \
		irs.conf.${FORMAT_EXT}
FORMAT_MAN = 	resolver.${FORMAT_MAN_EXT} \
		irs.conf.${FORMAT_MAN_EXT}
FORMAT_CAT = 	resolver.${FORMAT_CAT_EXT} \
		irs.conf.${FORMAT_CAT_EXT}
FORMAT_OUT =	${FORMAT_MAN} ${FORMAT_CAT}

#
# Feature Description manual entries
#
DESC_BASE =	hostname
DESC_EXT = 	7
DESC_SRC = 	hostname.${DESC_EXT}
DESC_MAN = 	hostname.${DESC_MAN_EXT}
DESC_CAT = 	hostname.${DESC_CAT_EXT}
DESC_OUT =	${DESC_MAN} ${DESC_CAT}

#
# This sed command is used to update the manual entries so they refer to 
# the appropriate section of the manual for a given platform.
#
EXT_SED_CMD =	LIB_NETWORK_EXT_U=`echo "${LIB_NETWORK_EXT}"|tr "[a-z]" "[A-Z]"`; \
		export LIB_NETWORK_EXT_U; \
		FORMAT_EXT_U=`echo "${FORMAT_EXT}"|tr "[a-z]" "[A-Z]"`; \
		export FORMAT_EXT_U; \
		DESC_EXT_U=`echo "${DESC_EXT}"|tr "[a-z]" "[A-Z]"`; \
		export DESC_EXT_U; \
		SYSCALL_EXT_U=`echo "${SYSCALL_EXT}"|tr "[a-z]" "[A-Z]"`; \
		export SYSCALL_EXT_U; \
		BSD_SYSCALL_EXT_U=`echo "${BSD_SYSCALL_EXT}"|tr "[a-z]" "[A-Z]"`; \
		export BSD_SYSCALL_EXT_U; \
		${SED} -e "s/@LIB_NETWORK_EXT@/${LIB_NETWORK_EXT}/g" \
		-e "s/@LIB_NETWORK_EXT_U@/$${LIB_NETWORK_EXT_U}/g" \
		-e "s/@FORMAT_EXT@/${FORMAT_EXT}/g" \
		-e "s/@FORMAT_EXT_U@/$${FORMAT_EXT_U}/g" \
		-e "s/@DESC_EXT@/${DESC_EXT}/g" \
		-e "s/@DESC_EXT_U@/$${DESC_EXT_U}/g" \
		-e "s/@SYSCALL_EXT@/${SYSCALL_EXT}/g" \
		-e "s/@SYSCALL_EXT_U@/$${SYSCALL_EXT_U}/g" \
		-e "s/@BSD_SYSCALL_EXT@/${BSD_SYSCALL_EXT}/g" \
		-e "s/@BSD_SYSCALL_EXT_U@/$${BSD_SYSCALL_EXT_U}/g"

.SUFFIXES:	.${LIB_NETWORK_EXT} .${LIB_NETWORK_MAN_EXT} \
		.${FORMAT_EXT} .${FORMAT_MAN_EXT} \
		.${DESC_EXT} .${DESC_MAN_EXT} 
.SUFFIXES:	.${LIB_NETWORK_MAN_EXT} .${LIB_NETWORK_CAT_EXT} \
		.${FORMAT_MAN_EXT} .${FORMAT_CAT_EXT} \
		.${DESC_MAN_EXT} .${DESC_CAT_EXT} 

.${LIB_NETWORK_EXT}.${LIB_NETWORK_MAN_EXT}:
	@echo "$*.${LIB_NETWORK_EXT} -> $*.${LIB_NETWORK_MAN_EXT}"
	@${EXT_SED_CMD} <$*.${LIB_NETWORK_EXT} >$*.${LIB_NETWORK_MAN_EXT}

.${FORMAT_EXT}.${FORMAT_MAN_EXT}:
	@echo "$*.${FORMAT_EXT} -> $*.${FORMAT_MAN_EXT}"
	@${EXT_SED_CMD} <$*.${FORMAT_EXT} >$*.${FORMAT_MAN_EXT}

.${DESC_EXT}.${DESC_MAN_EXT}:
	@echo "$*.${DESC_EXT} -> $*.${DESC_MAN_EXT}"
	@${EXT_SED_CMD} <$*.${DESC_EXT} >$*.${DESC_MAN_EXT}

.${LIB_NETWORK_MAN_EXT}.${LIB_NETWORK_CAT_EXT}:
	@echo "$*.${LIB_NETWORK_MAN_EXT} -> $*.${LIB_NETWORK_CAT_EXT}"
	@${MANROFF} <$*.${LIB_NETWORK_MAN_EXT} >$*.${LIB_NETWORK_CAT_EXT}

.${FORMAT_MAN_EXT}.${FORMAT_CAT_EXT}:
	@echo "$*.${FORMAT_MAN_EXT} -> $*.${FORMAT_CAT_EXT}"
	@${MANROFF} <$*.${FORMAT_MAN_EXT} >$*.${FORMAT_CAT_EXT}

.${DESC_MAN_EXT}.${DESC_CAT_EXT}:
	@echo "$*.${DESC_MAN_EXT} -> $*.${DESC_CAT_EXT}"
	@${MANROFF} <$*.${DESC_MAN_EXT} >$*.${DESC_CAT_EXT}

OUTFILES =	${LIB_NETWORK_OUT} ${FORMAT_OUT} ${DESC_OUT}

doc man:: ${OUTFILES}

docclean manclean maintainer-clean::
	rm -f ${OUTFILES}

installdirs:
	$(SHELL) ${top_srcdir}/mkinstalldirs \
		${MANDIR}/man${LIB_NETWORK_EXT} \
		${MANDIR}/cat${LIB_NETWORK_EXT} \
		${MANDIR}/man${FORMAT_EXT} \
		${MANDIR}/cat${FORMAT_EXT} \
		${MANDIR}/man${DESC_EXT} \
		${MANDIR}/cat${DESC_EXT}

install:: doc installdirs
	@set -x; N=${LIB_NETWORK_EXT}; for f in ${LIB_NETWORK_BASE}; do \
		${INSTALL_DATA} $${f}.${LIB_NETWORK_MAN_EXT} \
		${MANDIR}/man${LIB_NETWORK_EXT}/$${f}.${LIB_NETWORK_EXT}; \
	done
	@set -x; N=${LIB_NETWORK_EXT}; for f in ${LIB_NETWORK_BASE}; do \
		${INSTALL_DATA} $${f}.${LIB_NETWORK_CAT_EXT} \
		${MANDIR}/cat${LIB_NETWORK_EXT}/$${f}.${LIB_NETWORK_EXT}; \
	done
	@set -x; N=${FORMAT_EXT}; for f in ${FORMAT_BASE}; do \
		${INSTALL_DATA} $${f}.${FORMAT_MAN_EXT} \
		${MANDIR}/man${FORMAT_EXT}/$${f}.${FORMAT_EXT}; \
	done
	@set -x; N=${FORMAT_EXT}; for f in ${FORMAT_BASE}; do \
		${INSTALL_DATA} $${f}.${FORMAT_CAT_EXT} \
		${MANDIR}/cat${FORMAT_EXT}/$${f}.${FORMAT_EXT}; \
	done
	@set -x; N=${DESC_EXT}; for f in ${DESC_BASE}; do \
		${INSTALL_DATA} $${f}.${DESC_MAN_EXT} \
		${MANDIR}/man${DESC_EXT}/$${f}.${DESC_EXT}; \
	done
	@set -x; N=${DESC_EXT}; for f in ${DESC_BASE}; do \
		${INSTALL_DATA} $${f}.${DESC_CAT_EXT} \
		${MANDIR}/cat${DESC_EXT}/$${f}.${DESC_EXT}; \
	done

