# Copyright (C) 2009-2010  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 589 2010-01-15 05:00:12Z pselkirk $

VERSION='1.0'

TOPDIR=..
MANDIR=${TOPDIR}/man
HTMLDIR=${TOPDIR}/html

MANPAGES= ${MANDIR}/aftr.8 ${MANDIR}/aftr.conf.5 ${MANDIR}/aftr.commands.5
HTMLPAGES= ${HTMLDIR}/aftr.html ${HTMLDIR}/aftr.conf.html \
	${HTMLDIR}/aftr.commands.html
MANOBJS= ${MANPAGES} ${HTMLPAGES}
DOCOBJS= ${TOPDIR}/book.pdf
HTMLAUX= apa.html ch01.html ch02.html ch03.html ch04.html man.aftr.html \
	re02.html re03.html

man: ${MANOBJS}
doc: ${DOCOBJS} ${MANOBJS}

clean:
	rm -f book.aux book.brf book.glo book.idx book.toc
	rm -f book.log book.out book.tex book.tex.tmp book.pdf
	rm -f releaseinfo.xml *.8 *.5 *.html

all: doc

XSLTPROC=	/usr/bin/xsltproc --novalid --xinclude --nonet
PERL=		/usr/bin/perl
LATEX=		latex
PDFLATEX=	pdflatex
W3M=		w3m

.SUFFIXES: .docbook .html .5 .8

.docbook.html:
	${XSLTPROC} -o $@ xsl/isc-docbook-html.xsl $<

.docbook.5:
	${XSLTPROC} -o $@ xsl/isc-manpage.xsl $<

.docbook.8:
	${XSLTPROC} -o $@ xsl/isc-manpage.xsl $<

manclean:
	rm -f ${MANOBJS}

docclean:
	rm -f ${DOCOBJS} ${MANOBJS}

${MANDIR}/aftr.8: aftr.8
	cp aftr.8 ${MANDIR}/aftr.8

${MANDIR}/aftr.conf.5: aftr.conf.5
	cp aftr.conf.5 ${MANDIR}/aftr.conf.5

${MANDIR}/aftr.commands.5: aftr.commands.5
	cp aftr.commands.5 ${MANDIR}/aftr.commands.5

${HTMLDIR}/aftr.html: aftr.html
	cp aftr.html ${HTMLDIR}/aftr.html

${HTMLDIR}/aftr.conf.html: aftr.conf.html
	cp aftr.conf.html ${HTMLDIR}/aftr.conf.html

${HTMLDIR}/aftr.commands.html: aftr.commands.html
	cp aftr.commands.html ${HTMLDIR}/aftr.commands.html

${HTMLDIR}/book.html: book.xml releaseinfo.xml
	expand book.xml | \
	${XSLTPROC} --stringparam root.filename book \
		xsl/isc-docbook-chunk.xsl -
	cp book.html ${HTMLDIR}/book.html
	cp ${HTMLAUX} ${HTMLDIR}/

${HTMLDIR}/book-all.html: book.xml releaseinfo.xml
	expand book.xml | \
	${XSLTPROC} -o book-all.html xsl/isc-docbook-html.xsl -
	cp book-all.html ${HTMLDIR}/book-all.html

book.tex: book.xml releaseinfo.xml
	expand book.xml | \
	${XSLTPROC} xsl/pre-latex.xsl - | \
	${XSLTPROC} xsl/isc-docbook-latex.xsl - | \
	${PERL} latex-fixup.pl >$@.tmp
	if test -s $@.tmp; then mv $@.tmp $@; else rm -f $@.tmp; exit 1; fi

${TOPDIR}/book.dvi: book.tex releaseinfo.xml
	rm -f book.aux book.dvi book.log
	${LATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	${LATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	${LATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	cp book.dvi ${TOPDIR}/book.dvi

${TOPDIR}/book.pdf: book.tex releaseinfo.xml
	rm -f book.aux book.pdf book.log
	${PDFLATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	${PDFLATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	${PDFLATEX} '\batchmode\input book.tex' || (rm -f $@ ; exit 1)
	cp book.pdf ${TOPDIR}/book.pdf

releaseinfo.xml:
	echo >$@ '<releaseinf>AFTR Version ${VERSION}</releaseinfo>'
