# Example -*- makefile -*- for building a site using DocBook Website
#
# $Id: Makefile-example.txt,v 1.2 2005/04/18 18:58:58 xmldoc Exp $
#
# ------------------------------------------------------------------
# The default value DOCBOOK_WEBSITE below is the canonical URI for
# the current DocBook Website distribution. If you have SGML or
# XML catalogs correctly set up for DocBook Website in your
# environment, and have the DocBook Website distribution installed
# locally on your system, the URI will automatically be resolved
# to the appropriate local path on your system.
# ------------------------------------------------------------------
#                        IMPORTANT!
# ------------------------------------------------------------------
# IF YOU DO NOT HAVE SGML OR XML CATALOGS SET UP ON YOUR SYSTEM,
# change the value of DOCBOOK_WEBSITE to the appropricate local
# pathname for your system. OR, run "make" like this:
#
#  make DOCBOOK_WEBSITE=/foo/bar/website
#
# Note that DOCBOOK_WEBSITE SHOULD NOT BE THE URI FOR YOUR SITE!
# There is nowhere in this makefile where you need to specify that.
# ------------------------------------------------------------------
#
DOCBOOK_WEBSITE=http://docbook.sourceforge.net/release/website/current
#DOCBOOK_WEBSITE=/usr/share/xml/docbook/custom/website/current

# generate non-tabular output instead of tabular? 1=Yes 0=No
MAKENONTAB=0

# use HTML Tidy to pretty-print HTML? 1=Yes 0=No
USETIDY=0
# specifies how to call tidy
TIDY=tidy
# specifies options to feed to tidy
TIDYOPTS=-iq -latin1 -mn

# specifies command for calling your XSLT engine
# (this default uses Saxon)
XSLT=java \
	-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl \
	-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl \
	-Djavax.xml.transform.TransformerFactory=com.icl.saxon.TransformerFactoryImpl \
	com.icl.saxon.StyleSheet \
	-x org.apache.xml.resolver.tools.ResolvingXMLReader \
	-y org.apache.xml.resolver.tools.ResolvingXMLReader \
	-r org.apache.xml.resolver.tools.CatalogResolver

# to use xsltproc as your XSLT engine, either uncomment the next
# line or just run make like this: "make XSLT=xsltproc"
#XSLT=xsltproc

# XMLPARSER specifies command for calling your preferred XML
# parser for validating the DocBook XML sources for your site
ifeq ($(notdir $(XSLT)),xsltproc)
XMLPARSER=xmllint --valid --noout
else
XMLPARSER=java \
	-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl \
	-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl \
	org.apache.xml.resolver.apps.xread
endif

# the following is empty by default; put any custom DocBook
# stylesheet params you want here; they will be applied globally
# to all HTML transformations from your DocBook XML sources
STYLEOPT=

# name of directory to use if chunking output with "make chunk"
DESTPATH=.

# what prefix to use on non-tabular versions HTML files?
NONTABPREFIX=n-

TABSTYLE      =  $(DOCBOOK_WEBSITE)/xsl/tabular.xsl
WEBSTYLE      =  $(DOCBOOK_WEBSITE)/xsl/website.xsl
TABCHUNK      =  $(DOCBOOK_WEBSITE)/xsl/chunk-tabular.xsl
WEBCHUNK      =  $(DOCBOOK_WEBSITE)/xsl/chunk-website.xsl
AUTOLAYOUT    =  $(DOCBOOK_WEBSITE)/xsl/autolayout.xsl 
MAKEDEPENDS   =  $(DOCBOOK_WEBSITE)/xsl/makefile-dep.xsl
MAKETARGETSDB =  $(DOCBOOK_WEBSITE)/xsl/website-targets.xsl

XMLDEPENDS    = autolayout.xml website.database.xml

.PHONY : clean

all:
	$(MAKE) website
	$(MAKE) MAKENONTAB=1 website

ifeq ($(MAKENONTAB),0)
STYLESHEET=$(TABSTYLE)
STYLECHUNK=$(TABCHUNK)
NONTAB_OPT=
-include depends.tabular
else
STYLESHEET=$(WEBSTYLE)
STYLECHUNK=$(WEBCHUNK)
ifeq ($(basename $(XSLT)),xsltproc)
NONTAB_OPT= --stringparam filename-prefix $(NONTABPREFIX)
else
NONTAB_OPT= filename-prefix=$(NONTABPREFIX)
endif
-include depends.nontabular
endif

autolayout.xml: layout.xml
	$(XMLPARSER) $(filter-out $(XMLDEPENDS),$^)
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) $(AUTOLAYOUT) $< > $@
else
	$(XSLT) $< $(AUTOLAYOUT) use.extensions=1 > $@
endif

chunk: autolayout.xml
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) --param output-root $(DESTPATH) $(STYLECHUNK) autolayout.xml
else
	$(XSLT) autolayout.xml $(STYLECHUNK) use.extensions=1 output-root=$(DESTPATH)
endif

%.html: autolayout.xml website.database.xml
	$(XMLPARSER) $(filter-out $(XMLDEPENDS),$^)
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) $(NONTAB_OPT) $(STYLEOPT) $(STYLESHEET) $(filter-out $(XMLDEPENDS),$^) > $@
else
	$(XSLT) $(filter-out $(XMLDEPENDS),$^) $(STYLESHEET) $(NONTAB_OPT) $(STYLEOPT) use.extensions=1 > $@ 
endif
ifeq ($(USETIDY),1)
	-$(TIDY) -iq -latin1 -mn $@
endif

# RDDL gets its own rule because we never want to call tidy on it
ifeq ($(MAKENONTAB),0)
rddl.html: autolayout.xml
else
$(NONTABPREFIX)rddl.html: autolayout.xml
endif
	$(XMLPARSER) $(filter-out $(XMLDEPENDS),$^)
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) $(NONTAB_OPT) $(STYLEOPT) $(STYLESHEET) $(filter-out $(XMLDEPENDS),$^) > $@
else
	$(XSLT) $(filter-out $(XMLDEPENDS),$^) $(STYLESHEET) $(NONTAB_OPT) $(STYLEOPT) use.extensions=1 > $@
endif

depends.tabular depends.nontabular: autolayout.xml
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) --stringparam depends-file $@ $(NONTAB_OPT) $(MAKEDEPENDS) $< > $@
else
	$(XSLT) $< $(MAKEDEPENDS) depends-file=$@ $(NONTAB_OPT) use.extensions=1 > $@
endif

website.database.xml: autolayout.xml
ifeq ($(basename $(XSLT)),xsltproc)
	$(XSLT) $(MAKETARGETSDB) $< > $@
else
	$(XSLT) $< $(MAKETARGETSDB) use.extensions=1 > $@
endif

ifeq ($(MAKENONTAB),0)
depends: autolayout.xml website.database.xml depends.tabular
else
depends: autolayout.xml website.database.xml depends.nontabular
endif

realclean: clean
ifeq ($(MAKENONTAB),0)
	rm -f autolayout.xml depends.tabular website.database.xml
else
	rm -f autolayout.xml depends.nontabular website.database.xml
endif
