# This DocBook build stuff is inspired by LogReport's Lire
# ( http://www.logreport.org/ ) documentation build system which is
# Copyright (C) 2000, 2001, 2002, 2003, 2004 Stichting LogReport Foundation
#
# See also caspar ( http://mdcc.cx/caspar/ ), which ships a similar system
#
# Copyright (C) 2001, 2002, 2003, 2004, 2005 Joost van Baal
#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program (see COPYING); if not, check with
#     http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
#

HTML2TXT_RULE = $(HTML2TXT) $< > $@

XML2HTML_RULE = $(JADE) -t sgml -D $(top_builddir)/$(subdir) -d $(srcdir)/html.dsl $(XMLDCL) $<

XML2TEX_RULE = $(JADE) -t tex -D $(top_builddir)/$(subdir) -d $(srcdir)/print.dsl -o $@ $(XMLDCL) $<

# run 3 times for toc processing
TEX2DVI_RULE = $(JADETEX) $< && $(JADETEX) $< && $(JADETEX) $< && rm -f $*.log $*.out $*.aux
TEX2PDF_RULE = $(PDFJADETEX) -interaction=batchmode $< && $(PDFJADETEX) -interaction=batchmode $< && $(PDFJADETEX) -interaction=batchmode $< && rm -f $*.log $*.out $*.aux

DVI2PS_RULE = $(DVIPS) -f < $< > $@

base = manual
tmpfiles = $(base).log $(base).aux $(base).out $(base).dvi $(base).tex
buildfiles = $(base).html $(base).ps $(base).pdf $(base).txt

docdir = $(datadir)/doc/$(PACKAGE)
doc_DATA = $(buildfiles)

# do not require jade stuff for installing from .tar.gz distribution: ship
# typesetted docs
EXTRA_DIST = man.ent html.dsl print.dsl manual.dbx $(buildfiles) $(tmpfiles)

DISTCLEANFILES = $(buildfiles) $(tmpfiles)

# FIXME TODO
CONFIG_CLEAN_FILES =

$(base).tex: $(base).dbx man.ent
	$(XML2TEX_RULE)

$(base).dvi: $(base).tex
	$(TEX2DVI_RULE)
## 	rm $*.log

$(base).ps: $(base).dvi
	$(DVI2PS_RULE)

$(base).pdf: $(base).tex
	$(TEX2PDF_RULE)

## PS2PDF_RULE = $(PS2PDF) $< $@
## %.pdf: %.ps
## 	$(PS2PDF_RULE)

$(base).html: $(base).dbx man.ent
	$(XML2HTML_RULE)

$(base).txt: $(base).html
	$(HTML2TXT_RULE)
