
# Configuration
srcdir=.

# Java Runtime
JAVAVM=java

# This should work fine for every DocBook XML

# Java Classpath (if not in $JRE_ROOT/lib/ext)
CP_XERCES=$(srcdir)/lib/xercesImpl.jar
CP_XALAN=$(srcdir)/lib/xalan.jar
CP_XALAN_APIS=$(srcdir)/lib/xml-apis.jar
CP_FOP=$(srcdir)/lib/fop.jar
CP_BATIK=$(srcdir)/lib/batik.jar
CP_JIMI=$(srcdir)/lib/jimi-1.0.jar
CP_LOGKIT=$(srcdir)/lib/logkit-1.0.jar
CP_AVALON=$(srcdir)/lib/avalon-framework-4.0.jar
CP_SAXON=$(srcdir)/lib/saxon.jar

# Application Classpath Requirem
CP_XALANXSLT_ARGS=-cp $(CP_XALAN):$(CP_XALAN_APIS):$(CP_XERCES)
CP_SAXONXSLT_ARGS=-cp $(CP_SAXON)
CP_FOPFO_ARGS=-cp $(CP_FOP):$(CP_XERCES):$(CP_BATIK):$(CP_LOGKIT):$(CP_AVALON):$(CP_JIMI)

# XSLT Invoking
XALANXSLT=$(JAVAVM) $(CP_XALANXSLT_ARGS) org.apache.xalan.xslt.Process $(XALAN_XSLXPARAM)
SAXONXSLT=$(JAVAVM) $(CP_SAXONXSLT_ARGS) com.icl.saxon.StyleSheet $(SAXON_XSLPARAM)
FOPFO=$(JAVAVM) $(CP_FOPFO_ARGS) org.apache.fop.apps.Fop $(FOP_FOXPARAM)

# Stylesheets
XSL_HTMLCHUNK=$(srcdir)/sf_docbook-html-chunk.xsl
XSL_XHTMLCHUNK=$(srcdir)/sf_docbook-xhtml-chunk.xsl
XSL_HTML=$(srcdir)/sf_docbook-html.xsl
XSL_XHTML=$(srcdir)/sf_docbook-xhtml.xsl
XSL_FO=$(srcdir)/sf_docbook-print.xsl

# Misc
FOPCONFIG=$(srcdir)/fop/conf/fopconfig.xml

# Print Stylesheet to use
PRINTXSL=$(XSL_FO)
# XHTML
HTMLXSL=$(XSL_XHTML)
HTMLCHUNKXSL=$(XSL_XHTMLCHUNK)
# HTML4
# HTMLXSL=$(XSLHTML)
# HTMLCHUNKXSL=$(XSLHTMLCHUNK)

# Sources
DIST=Thai-HOWTO

# Target File/Dir
HTMLCHUNKBASE=Thai-HOWTO/
HTMLCHUNKINDEX=index

.PHONY: clean distclean %-chunk build

all:
	@echo "usage:"
	@echo "  make [$(DIST)-chunk] [$(DIST).html]"
	@echo "     [$(DIST).fo] [$(DIST).pdf] [$(DIST.ps)]"
	@echo "  make build (do all above)"
	@echo "  make [$(DIST).mif] [$(DIST).pcl] [$(DIST.svg)] [$(DIST).at]"
	@echo "  make extra_build (do all above)"
	@echo "  make all_build (do both build and extra_build)"
	@echo "  make clean"
	@echo "  make distclean"

build: $(DIST)-chunk $(DIST).html $(DIST).fo $(DIST).pdf $(DIST).ps

%-chunk: %.xml
#	$(XALANXSLT) -IN $< -XSL $(HTMLCHUNKXSL) \
#	-PARAM base.dir '$(HTMLCHUNKBASE)' -PARAM root.filename $(HTMLCHUNKINDEX) \
#	-PARAM use.extensions '1'
	$(SAXONXSLT) $< $(HTMLCHUNKXSL) \
	base.dir="$(HTMLCHUNKBASE)"  root.filename="$(HTMLCHUNKINDEX)" \
	use.extensions='1'

%.html: %.xml
	$(XALANXSLT) -IN $< -XSL $(HTMLXSL) -OUT $@ \
	-PARAM use.extensions '1'

%.fo: %.xml
	$(XALANXSLT) -IN $< -XSL $(PRINTXSL) -OUT $@ \
	-PARAM use.extensions '1' -PARAM fop.extensions '1'

%.pdf: %.fo
	$(FOPFO) -fo $< -pdf $@ -c $(FOPCONFIG) -l th

%.ps: %.fo
	$(FOPFO) -fo $< -ps  $@	-c $(FOPCONFIG) -l th

%.txt: %.fo
	$(FOPFO) -fo $< -txt $@ -c $(FOPCONFIG) -l th

%.mif: %.fo
	$(FOPFO) -fo $< -mif $@ -c $(FOPCONFIG) -l th

%.pcl: %.fo
	$(FOPFO) -fo $< -pcl $@	-c $(FOPCONFIG) -l th

%.svg: %.fo
	$(FOPFO) -fo $< -svg $@	-c $(FOPCONFIG) -l th

%.at: %.fo
	$(FOPFO) -fo $< -at  $@ -c $(FOPCONFIG) -l th

clean:
	rm -rf *.html *.fo *.pdf *.ps *.txt *.mif *.pcl *.svg *.at $(HTMLCHUNKBASE)/*.html

distclean: clean
	rm -rf Makefile *.xsl configure config.*

