DESTDIR		=
prefix		= /usr

docdir		= ${prefix}/share/doc/dh-kpatches
mandir		= ${prefix}/share/man
man1dir		= ${mandir}/man1

MANPAGES	= dh_installkpatches.1 lskpatches.1

POLICY		= kpatch-policy.sgml
PROCESSEDPOLICIES = ${POLICY:.sgml=.txt} ${POLICY:.sgml=.html}

# debiandoc2* attempts to do something nasty with locale set
export LC_ALL=C

all: ${MANPAGES} dh-kpatches

policy: ${PROCESSEDPOLICIES}
dh-kpatches: dh-kpatches.pdf dh-kpatches.html
dh-kpatches.pdf dh-kpatches.html: dh_installkpatches.refentry-contents.sgml

clean:
	rm -f ${MANPAGES} ${POLICY:.sgml=.txt} \
		manpage.refs manpage.links \
		*.jtex *.fot *.aux *.log *.out *.ps *.pdf
	rm -rf *.html

install: all
	install -m755 -d ${DESTDIR}${man1dir}
	install -m644 ${MANPAGES} ${DESTDIR}${man1dir}

	install -m755 -d ${DESTDIR}${docdir}
	install -m644 dh-kpatches.pdf dh-kpatches.html ${DESTDIR}${docdir}

uninstall:
	rm -rf ${DESTDIR}${docdir}
	cd ${DESTDIR}${man1dir} && rm -f ${MANPAGES}

%.txt: %.debiandoc.sgml
	debiandoc2text $<
	mv ${<:.sgml=.txt} $@

%.html: %.debiandoc.sgml
	debiandoc2html $<
	mv ${<:.sgml=.html} $@

%.1: %.refentry.sgml
	docbook2man $<

%.html: %.docbook.sgml
	docbook-2-html --dssslproc openjade1.3 -s gtk -O -Vnochunks -O -Vonechunk $< >$@
	rmdir -p $*-html

%.pdf: %.docbook.sgml
	docbook-2-pdf --dssslproc openjade1.3 $<

.DELETE_ON_ERROR:
