# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

srcdir =	@srcdir@
VPATH =		@srcdir@
top_srcdir =	@top_srcdir@

@BIND9_MAKE_RULES@

MANOBJS = Bv9ARM.html notes.html

TXTOBJS = notes.txt

PDFOBJS = Bv9ARM.pdf notes.pdf

NOTESXML = notes-download.xml notes-eol.xml notes-intro.xml notes-license.xml \
	   notes-thankyou.xml \
	   notes-9.11.37.xml \
	   notes-9.11.36.xml \
	   notes-9.11.35.xml \
	   notes-9.11.34.xml \
	   notes-9.11.33.xml \
	   notes-9.11.32.xml \
	   notes-9.11.31.xml \
	   notes-9.11.30.xml \
	   notes-9.11.29.xml \
	   notes-9.11.28.xml \
	   notes-9.11.27.xml \
	   notes-9.11.26.xml \
	   notes-9.11.25.xml \
	   notes-9.11.24.xml \
	   notes-9.11.23.xml \
	   notes-9.11.22.xml \
	   notes-9.11.21.xml \
	   notes-9.11.20.xml \
	   notes-9.11.19.xml \
	   notes-9.11.18.xml \
	   notes-9.11.17.xml \
	   notes-9.11.16.xml \
	   notes-9.11.15.xml \
	   notes-9.11.14.xml \
	   notes-9.11.13.xml \
	   notes-9.11.12.xml \
	   notes-9.11.11.xml \
	   notes-9.11.10.xml \
	   notes-9.11.9.xml \
	   notes-9.11.8.xml \
	   notes-9.11.7.xml \
	   notes-9.11.6.xml \
	   notes-9.11.5.xml \
	   notes-9.11.4.xml \
	   notes-9.11.3.xml \
	   notes-9.11.2.xml \
	   notes-9.11.1.xml \
	   notes-9.11.0.xml \
	   notes.xml

doc man:: ${MANOBJS} ${TXTOBJS} ${PDFOBJS}

clean::
	rm -f Bv9ARM.aux Bv9ARM.brf Bv9ARM.glo Bv9ARM.idx Bv9ARM.toc
	rm -f Bv9ARM.log Bv9ARM.out
	rm -f notes.aux notes.brf notes.glo notes.idx notes.toc
	rm -f notes.log notes.out

docclean manclean maintainer-clean:: clean
	rm -f *.html ${PDFOBJS}

maintainer-clean distclean::
	rm -f releaseinfo.xml
	rm -f pkgversion.xml
	rm -f noteversion.xml

# use xmllint to process include
notes.html: notes-wrapper.xml ${NOTESXML} releaseinfo.xml pkgversion.xml noteversion.xml
	expand notes-wrapper.xml | ${XMLLINT} --xinclude - | \
	${XSLTPROC} --stringparam generate.toc "" ../xsl/isc-notes-html.xsl - > notes.html

notes.pdf: notes-wrapper.xml ${NOTESXML} releaseinfo.xml pkgversion.xml noteversion.xml
	${XSLTPROC} ${top_srcdir}/doc/xsl/pre-latex.xsl notes-wrapper.xml | \
	${DBLATEX} -c notes.conf -Pdoc.layout="mainmatter" -o notes.pdf -

# Produce notes.txt from notes.html using w3m, with some post-processing:
#
#  - remove trailing spaces from every line,
#  - remove empty lines from the end of the document,
#  - prevent GitLab issue/MR identifiers from being split across two lines.
notes.txt: notes.html
	${W3M} -dump -cols 75 -O utf-8 -T text/html < notes.html | \
		sed 's/  *$$//' | \
		sed -e :a -e '/^\n*$$/{$$d;N;};/\n$$/ba' | \
		sed '/ [!#]$$/{N;s| \([!#]\)\(\n[[:space:]]*\)\([0-9][0-9]*\)|\2\1\3|;};' > notes.txt

# use xmllint to process include
Bv9ARM.html: Bv9ARM-book.xml ${NOTESXML} releaseinfo.xml pkgversion.xml noteversion.xml
	expand Bv9ARM-book.xml | ${XMLLINT} --xinclude - | \
	${XSLTPROC} --stringparam root.filename Bv9ARM \
		${top_srcdir}/doc/xsl/isc-docbook-chunk.xsl -

# use xmllint to process include
Bv9ARM-all.html: Bv9ARM-book.xml ${NOTESXML} releaseinfo.xml pkgversion.xml noteversion.xml
	expand Bv9ARM-book.xml | ${XMLLINT} --xinclude - |\
	${XSLTPROC} -o Bv9ARM-all.html ../xsl/isc-docbook-html.xsl -

Bv9ARM.pdf: Bv9ARM-book.xml ${NOTESXML} releaseinfo.xml pkgversion.xml noteversion.xml
	expand Bv9ARM-book.xml | \
	${XSLTPROC} ${top_srcdir}/doc/xsl/pre-latex.xsl - | \
	${DBLATEX} -c Bv9ARM.conf -o Bv9ARM.pdf -
