# Makefile to drive ivoadoc.
#
# To use this, you must have checked out ivoadoc as svn:externals into
# your document directory.  Copy this Makefile into that directory and
# edit it as necessary.
#
# The Makefile assumes you have xalanb-xslt and fop in your path.  On
# Debian-derived systems, you could say
#
# sudo aptitude install xalan fop w3c-dtd-xhtml
#
# You most likely want the hyphenation patterns for fop (the PDF
# formatter), too.  Presumably for licensing reasons, you have to 
# get them manually from http://offo.sourceforge.net.  Drop them
# into your working directory as fop-hyph.jar.
#
# Edit your source as $(STDNAME).html; available targets then are:
#
# * default: format the html, expanding the magic things explained in
#   README
# * $(STDNAME).pdf: same, but make a pdf
# * package: package the docs, css, all pngs and whatever is in
#   PACKAGE_EXTRAS into an aptly-named zip that expands into a
#   nicely-named subdirectory.
#
# Contact for this Makefile: Markus Demleitner (gavo@ari.uni-heidelberg.de)
#
# Fix (and maintain, as you go on) the following set of variables:
#
# The base name of the files (a sensible abbreviation of your standard's 
# title; this is case sensitive)
STDNAME=uri-fragments
# The current version
DOCVERSION=1.0
# YYYY-MM-DD of the current release
DOCDATE=20120525
# One of NOTE, WD, PR, REC
PUBSTATUS=NOTE
# Extra files that need to end up in the final package
# (pngs are included automatically)
#PACKAGE_EXTRAS=TAPRegExt-v1.0.xsd tre-vor.xml
PACKAGE_EXTRAS=

DOCBASE=http://www.ivoa.net/Documents/
#DOCBASE=http://www.astro.gla.ac.uk/users/norman/temp/


# You probably want to configure your system so the following works
SAXON=saxonb-xslt
FOP=FOP_HYPHENATION_PATH=./fop-hyph.jar fop
HTMLSTYLE=ivoadoc/ivoarestructure.xslt
FOSTYLE=ivoadoc/ivoa-fo.xsl
TAR=tar

# You should not need to edit anything below this line

versionedName:=$(PUBSTATUS)-$(STDNAME)-$(DOCVERSION)
ifneq "$(PUBSTATUS)" "REC"
		versionedName:=$(versionedName)-$(subst -,,$(DOCDATE))
endif

.PHONY: package

%-fmt.html: %.html $(HTMLSTYLE)
	rm -f $@
	$(SAXON) -o $@.tmp -s $< $(HTMLSTYLE) docdate=$(DOCDATE) document-id=$< \
		docversion=$(DOCVERSION) pubstatus=$(PUBSTATUS) ivoname=$(STDNAME) \
		docbase=$(DOCBASE) && mv $@.tmp $@
# $(SAXON) -o:$@.tmp -s:$< -xsl:$(HTMLSTYLE) docdate=$(DOCDATE) document-id=$< \
# 	docversion=$(DOCVERSION) pubstatus=$(PUBSTATUS) ivoname=$(STDNAME) \
# 	docbase=$(DOCBASE) && mv $@.tmp $@

%.fo: %-fmt.html
	$(SAXON) -o $@ $< $(FOSTYLE) docdate=$(DOCDATE)\
		docversion=$(DOCVERSION) pubstatus=$(PUBSTATUS) ivoname=$(STDNAME)

%.pdf: %.fo
	$(FOP) -pdf $@ -fo $<

%.bbl: %.html
	rm -f $@
	$(SAXON) -o ${@:.bbl=.aux} -s $< ivoadoc/extractcite.xslt document-id=$<
#	$(SAXON) -o:${@:.bbl=.aux} -s:$< -xsl:ivoadoc/extractcite.xslt document-id=$<
	bibtex ${<:.html=}
	rm -f ${<:.html=.aux}
	sed -f ivoadoc/detex.sed $@ >$@.tmp && mv $@.tmp $@

%.gz: %
	rm -f $@
	gzip --best $<
%.tar: %
	rm -f $@
	$(TAR) cf $@ $<


all: $(STDNAME)-fmt.html

dist: $(versionedName).tar.gz

uri-fragments.bbl: note.bib

# This must create a directory, the layout of which matches the
# 'current version' link generated by the stylesheet:
# http://www.ivoa.net/Documents/$(STDNAME)/$(DOCDATE)
$(versionedName): $(STDNAME)-fmt.html
	rm -Rf -- $(versionedName)
	D=$(versionedName)/$(STDNAME)/`echo $(DOCDATE) | sed 's/-//g'`; \
	  mkdir -p $$D; \
	  cp $(STDNAME)-fmt.html $$D/index.html; \
	  cp ivoadoc/*.css $(SCHEMA_FILE) $(PACKAGE_EXTRAS) $$D
#	cp $(STDNAME).pdf $(versionedName)/$(versionedName).pdf

# package: $(STDNAME)-fmt.html $(STDNAME).pdf
# 	rm -rf -- $(versionedName)
# 	mkdir $(versionedName)
# 	cp $(STDNAME)-fmt.html $(versionedName)/$(versionedName).html
# 	cp $(STDNAME).pdf $(versionedName)/$(versionedName).pdf
# 	cp ivoadoc/*.css *.png $(SCHEMA_FILE) $(PACKAGE_EXTRAS) $(versionedName)
# 	zip -r $(versionedName).zip $(versionedName)
# 	rm -rf -- $(versionedName)

clean:
	rm -f $(PUBSTATUS)-$(STDNAME)-*.html $(PUBSTATUS)-$(STDNAME)-*.pdf $(STDNAME).pdf
	rm -f $(STDNAME)-fmt.html $(STDNAME).bbl
	rm -Rf $(versionedName)*