# -*- coding: unix -*-

ifdef COMMIT
SVN=/usr/bin/svn
else
SVN=/bin/true
endif


# The local stylesheet imports the generic stylesheets and
# sets some custom parameters.

STYLESHEET = xsl/openmcl.xsl

# Obtain a temporary ID to be used as the identifier of this invocation of
# make.

TEMP := build-$(shell date +%s)

# Save the current directory for use in the tarfile target.

CWD := $(shell pwd)

# There's datestamps on the page; let's make sure they're in
# UTC instead of local time.

export TZ = UTC

# Compute some targets.

XMLFILES = $(wildcard *.xml)
XSLFILES = $(shell find xsl -name "*.xsl")
HTMLFILES = ccl-documentation.html
PARENT = ../ccl-documentation.html

# Save the xsltproc version string for use in debugging.

XSLTPROCVERSION = $(shell $(XSLTPROC) --version | head -n 1)

# Try to determine the svn revishion
SVNREV = $(shell /usr/bin/svnversion)


.PHONY: all clean distclean show


$(HTMLFILES): $(XMLFILES)  $(XSLFILES)
	rm -rf build-* *~
	$(XSLTPROC) \
		--xinclude \
		--stringparam root.filename $(basename $(@F)) \
		--stringparam base.dir $(TEMP)/ \
		--stringparam openmcl.directory $(@D)/ \
		--stringparam onechunk \
			$(if $(findstring Doc, $(@D)), 0, 1) \
		--stringparam xsltproc.version "$(XSLTPROCVERSION)." \
                --stringparam svnrev "$(SVNREV)"\
		$(EXTRAPARAMS) \
		$(STYLESHEET) ccl-documentation.xml
	rm -f $(if $(findstring Doc, $(@D)), $(@D)/*.html, $@)
	mv $(TEMP)/*.html $(@D)/

${PARENT}: ${HTMLFILES}
	cp ${HTMLFILES} ${PARENT}
	$(CCL) -b -n -l ../doc-splitter -e '(doc-splitter:split-doc-file "ccl-documentation.html" "../manual/")' </dev/null
	(cd .. ; $(SVN) commit -m "updated" ccl-documentation.html)

all: ${TEMP} ${HTMLFILES} distclean
	echo ${HTMLFILES}


install: $(PARENT)


$(TEMP):
	mkdir $(TEMP)

clean:
	rm -rf build-*

distclean: clean 
	rm -f *~

