## Process this with automake to create Makefile.in

docdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/refdb-manual
doc_DATA = refdb-manual.pdf refdb-manual/*

indexdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/
index_DATA = index.html

citestylexdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citestylex
citestylex_DATA = citestylex/*.html
citestylexdtdelemdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citestylex/dtdelem
citestylexdtdelem_DATA = citestylex/dtdelem/*
citestylexeledescdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citestylex/ele-desc
citestylexeledesc_DATA = $(top_srcdir)/doc/citestylex/ele-desc/*.html
citestylexelementsdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citestylex/elements
citestylexelements_DATA = citestylex/elements/*

risxdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/risx
risx_DATA = risx/*.html
risxdtdelemdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/risx/dtdelem
risxdtdelem_DATA = risx/dtdelem/*
risxeledescdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/risx/ele-desc
risxeledesc_DATA = $(top_srcdir)/doc/risx/ele-desc/*.html
risxelementsdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/risx/elements
risxelements_DATA = risx/elements/*

citationlistxdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citationlistx
citationlistx_DATA = citationlistx/*.html
citationlistxdtdelemdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citationlistx/dtdelem
citationlistxdtdelem_DATA = citationlistx/dtdelem/*
citationlistxeledescdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citationlistx/ele-desc
citationlistxeledesc_DATA = $(top_srcdir)/doc/citationlistx/ele-desc/*.html
citationlistxelementsdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/citationlistx/elements
citationlistxelements_DATA = citationlistx/elements/*

xnotedir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/xnote
xnote_DATA = xnote/*.html
xnotedtdelemdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/xnote/dtdelem
xnotedtdelem_DATA = xnote/dtdelem/*
xnoteeledescdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/xnote/ele-desc
xnoteeledesc_DATA = $(top_srcdir)/doc/xnote/ele-desc/*.html
xnoteelementsdir = $(datadir)/doc/$(PACKAGE)-$(VERSION)/xnote/elements
xnoteelements_DATA = xnote/elements/*

####################################################################
# the manual
manual_sources = refdb-manual.xml chapter-backend-api.xml chapter-bibliographies.xml chapter-cs-protocol.xml chapter-data-input.xml chapter-inout-formats.xml chapter-installation.xml chapter-introduction.xml chapter-limitations.xml chapter-managing-notes.xml chapter-managing-references.xml chapter-overview-clients.xml chapter-perl-client-module.xml chapter-refdb-database-design.xml chapter-refdba.xml chapter-refdbc.xml chapter-refdbd-administration.xml chapter-refdbd.xml chapter-refdbib.xml chapter-reference-database-design.xml chapter-ris-risx-format.xml chapter-system-requirements.xml chapter-programming.xml chapter-sru.xml

manpage_sources = RefDB.7.xml bib2ris.1.xml db2ris.1.xml eenc.1.xml en2ris.1.xml marc2ris.1.xml med2ris.1.xml refdb-backup.1.xml refdb-ms.1.xml refdb-restore.1.xml refdb.8.xml refdba.1.xml refdbc.1.xml refdbctl.1.xml refdbd.1.xml refdbib.1.xml refdbjade.1.xml refdbnd.1.xml refdbxml.1.xml refdbxp.1.xml runbib.1.xml runbib-missing.1.xml refdb-init.8.xml refdb-bug.1.xml refdb_dos2unix.1.xml refdb_latex2utf8txt.1.xml refdbsru.1.xml refdb-sruserver.1.xml rtfcitations.1.xml refdbrtf.1.xml refdb-pubmed.1.xml


svg_images = refdbmanualfig1.svg refdbmanualfig2.svg refdbmanualfig3.svg refdbmanualfig4.svg refdbmanualfig5.svg refdbmanualfig6.svg

png_images = $(top_srcdir)/doc/refdbmanualfig1.png $(top_srcdir)/doc/refdbmanualfig2.png $(top_srcdir)/doc/refdbmanualfig3.png $(top_srcdir)/doc/refdbmanualfig4.png $(top_srcdir)/doc/refdbmanualfig5.png $(top_srcdir)/doc/refdbmanualfig6.png

html_extra_files = $(top_srcdir)/doc/manual.css $(png_images)

manual_include_files = include/fotitlepage.templates.xml include/fotitlepages.xsl include/manual-fo.xsl include/manual-man.xsl include/manual-xhtml.xsl 

####################################################################
# the dtd documentation
dtdparsefiles = citestylex.xml citestylex/elements.html risx.xml risx/elements.html citationlistx.xml citationlistx/elements.html xnote.xml xnote/elements.html

EXTRA_DIST = $(doc_DATA) $(manual_sources) $(manpage_sources) $(html_extra_files) $(svg_images) $(citestylex_DATA) $(citestylexdtdelem_DATA) $(citestylexeledesc_DATA) $(citestylexelements_DATA) $(risx_DATA) $(risxdtdelem_DATA) $(risxeledesc_DATA) $(risxelements_DATA) $(citationlistx_DATA) $(citationlistxdtdelem_DATA) $(citationlistxeledesc_DATA) $(citationlistxelements_DATA) $(xnote_DATA) $(xnotedtdelem_DATA) $(xnoteeledesc_DATA) $(xnoteelements_DATA) $(index_DATA) $(dtdparsefiles) $(manual_include_files) refdb-manual-statustable.xml 

all: refdb-manual.pdf refdb-manual/* citestylex/elements.html risx/elements.html citationlistx/elements.html xnote/elements.html

####################################################################
# building the manual

# this is how we could validate the manual:
# xmllint --noout --xinclude --relaxng /usr/local/share/emacs/21.3/site-lisp/nxml/schema/docbook.rng refdb-manual.xml 2>&1|less

refdb-manual-statustable.xml: $(top_srcdir)/scripts/statgen.pl
	$(top_srcdir)/scripts/statgen.pl docbook > refdb-manual-statustable.xml

if HAVEBATIK
$(png_images): %.png: %.svg
	batik-rasterizer -m image/png $<
else
$(png_images): %.png: %.svg
	convert $< $@
endif

include/fotitlepages.xsl: include/fotitlepage.templates.xml
	xsltproc -output include/fotitlepages.xsl $(docbk_xsl)/template/titlepage.xsl include/fotitlepage.templates.xml

refdb-manual.pdf: $(manual_sources) $(manpage_sources) $(svg_images) refdb-manual-statustable.xml include/fotitlepages.xsl include/manual-fo.xsl
	@echo "Creating PDF manual...";
#	xsltproc -o refdb-manual.fo --nonet --xinclude $(top_srcdir)/doc/include/manual-fo.xsl $(top_srcdir)/doc/refdb-manual.xml
# workaround for a null pointer exception in fop 1.0: disable hyphenation
	@echo "hyphenation temporarily unavailable"
	xsltproc -o refdb-manual.fo --stringparam hyphenate 0 --nonet --xinclude $(top_srcdir)/doc/include/manual-fo.xsl $(top_srcdir)/doc/refdb-manual.xml
# we have to give Java a little extra memory lest fop will die a horrible death
	JAVA_OPTS=-Xmx256M fop -fo refdb-manual.fo -pdf refdb-manual.pdf

refdb-manual/*: $(manual_sources) $(manpage_sources) $(png_images) refdb-manual-statustable.xml include/manual-xhtml.xsl
	@echo "Creating HTML manual...";
	rm -rf refdb-manual/*
# building outside the source dir won't work here because the docbook
# stylesheets screw up the location of the image files for HTML output
	mkdir -p refdb-manual && cp $(html_extra_files) refdb-manual/ && xsltproc -o refdb-manual/ --nonet --xinclude include/manual-xhtml.xsl refdb-manual.xml


####################################################################
# building the DTD doc

citestylex.xml: $(top_srcdir)/dtd/citestylex.dtd
# dtdparse does not grok CATALOG directives, therefore we have to temporarily
# disable all entries in SGML_CATALOG_FILES
	SGML_CATALOG_FILES=""  dtdparse --title "citestyle XML DTD" --output citestylex.xml --declaration $(top_srcdir)/declarations/xml.dcl --system-id "http://refdb.sourceforge.net/dtd/citestylex.dtd" $(top_srcdir)/dtd/citestylex.dtd 

citestylex/elements.html: citestylex.xml $(top_srcdir)/doc/citestylex/ele-desc/*
	dtdformat --html citestylex.xml
	$(top_srcdir)/scripts/dtdparseweave citestylex

citestylex/dtdelem/*: citestylex/elements.html
citestylex/elements/*: citestylex/elements.html
citestylex/*.html: citestylex/elements.html

risx.xml: $(top_srcdir)/dtd/risx.dtd
	SGML_CATALOG_FILES=""  dtdparse --title "risx XML DTD" --output risx.xml --declaration $(top_srcdir)/declarations/xml.dcl --system-id "http://refdb.sourceforge.net/dtd/risx.dtd" $(top_srcdir)/dtd/risx.dtd 

risx/elements.html: risx.xml $(top_srcdir)/doc/risx/ele-desc/*
	dtdformat --html risx.xml
	$(top_srcdir)/scripts/dtdparseweave risx

risx/dtdelem/*: risx/elements.html
risx/elements/*: risx/elements.html
risx/*.html: risx/elements.html

citationlistx.xml: $(top_srcdir)/dtd/citationlistx.dtd
	SGML_CATALOG_FILES=""  dtdparse --title "citationlistx XML DTD" --output citationlistx.xml --declaration $(top_srcdir)/declarations/xml.dcl --system-id "http://refdb.sourceforge.net/dtd/citationlistx.dtd" $(top_srcdir)/dtd/citationlistx.dtd 

citationlistx/elements.html: citationlistx.xml $(top_srcdir)/doc/citationlistx/ele-desc/*
	dtdformat --html citationlistx.xml
	$(top_srcdir)/scripts/dtdparseweave citationlistx

citationlistx/dtdelem/*: citationlistx/elements.html
citationlistx/elements/*: citationlistx/elements.html
citationlistx/*.html: citationlistx/elements.html

xnote.xml: $(top_srcdir)/dtd/xnote.dtd
	SGML_CATALOG_FILES=""  dtdparse --title "xnote XML DTD" --output xnote.xml --declaration $(top_srcdir)/declarations/xml.dcl --system-id "http://refdb.sourceforge.net/dtd/xnote.dtd" $(top_srcdir)/dtd/xnote.dtd 

xnote/elements.html: xnote.xml $(top_srcdir)/doc/xnote/ele-desc/*
	dtdformat --html xnote.xml
	$(top_srcdir)/scripts/dtdparseweave xnote

xnote/dtdelem/*: xnote/elements.html
xnote/elements/*: xnote/elements.html
xnote/*.html: xnote/elements.html

maintainer-clean: clean
	rm -f refdb-manual.pdf refdb-manual.tex refdb-manual.aux refdb-manual.log refdb-manual.out
	rm -rf refdb-manual/
	rm -f $(png_images)
	rm -f include/fotitlepages.xsl
	rm -f citestylex.xml risx.xml citationlistx.xml xnote.xml
	rm -f citestylex/*.html
	rm -rf citestylex/dtdelem citestylex/dtdent citestylex/elements citestylex/entities citestylex/notations
	rm -f risx/*.html
	rm -rf risx/dtdelem risx/dtdent risx/elements risx/entities risx/notations
	rm -f citationlistx/*.html
	rm -rf citationlistx/dtdelem citationlistx/dtdent citationlistx/elements citationlistx/entities citationlistx/notations
	rm -f xnote/*.html
	rm -rf xnote/dtdelem xnote/dtdent xnote/elements xnote/entities xnote/notations

dist-hook:
# remove the subversion housekeeping directories from the tarball
	rm -rf `find $(distdir) -name .svn`
	rm -f `find $(distdir) -name *~`
