DSSSL_JADETEX=/usr/share/sgml/docbook/dsssl-stylesheets/print/docbook.dsl
XSL_JADETEX=/usr/share/sgml/docbook/xsl-stylesheets/xhtml/docbook.xsl
JADE=openjade

%.tex: %.xml $(DSSSL_JADETEX)
	$(JADE) -t tex -d $(DSSSL_JADETEX) -c /usr/share/sgml/openjade/catalog \
		-o $@ /usr/share/sgml/openjade/pubtext/xml.dcl $<

%.pdf %.out %.aux %.log: %.tex
	if [ -e prior.aux ]; then cp -pf prior.aux pprior.aux; fi
	f=$(shell basename $< .tex).aux; if [ -e $$f ]; then cp -pf $$f prior.aux; fi
	-pdfjadetex $< > pdfjadetex.log
	if ! cmp $(shell basename $< .tex).aux prior.aux > /dev/null 2>&1 && \
		! cmp $(shell basename $< .tex).aux pprior.aux > /dev/null 2>&1 && \
		expr $(MAKELEVEL) '<' 4 > /dev/null; then \
		rm -f $@; \
		echo "Found undefined references, compiling again..."; \
		$(MAKE) $@; \
	fi

%.html: %.xml
	xsltproc -o $@ $(XSL_JADETEX) $<

clean:
	rm -rf *.html *.pdf *.tex *.aux *.log *.out