# Makefile for PhotoML docs
# Most recent modification: 7 December 2007

prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@/photoml
docdir = @datadir@/doc/photoml

SECTIONS := $(shell find sections -name "*.xml")

INSTALL = @INSTALL@
SHELL = @SH@
RM = @RM@
DTDTO = @DTDTO@
XMLTO = @XMLTO@
FOP = @FOP@
LYNX = @LYNX@
LYNXFLAGS = @LYNXFLAGS@

.PHONY: all dtddoc test install uninstall clean clean-html clean-pdf clean-txt


all: dtddoc pmldoc.html pmldoc.pdf pmldoc.txt

dtddoc:
	@(cd sections; make)

test:

install: all
	@echo "Installing documentation in ${DESTDIR}${datadir}";\
	if [ ! -d ${DESTDIR}${datadir} ]; then \
          ${INSTALL} -d ${DESTDIR}${datadir}; \
	fi;\
	if [ ! -d ${DESTDIR}${docdir} ]; then \
          ${INSTALL} -d ${DESTDIR}${docdir}; \
	fi;\
	${INSTALL} -m 644 pmldoc.html pmldoc.css pmldoc.pdf pmldoc.txt\
	   ${DESTDIR}${docdir}

uninstall:
	@echo "Uninstalling documentation in ${DESTDIR}${datadir}";\
	${RM} -f ${DESTDIR}${docdir}/*
	@-rmdir ${DESTDIR}${docdir} 2>/dev/null;\
	@-rmdir ${DESTDIR}${datadir} 2>/dev/null

clean: clean-html clean-pdf clean-txt
	@${RM} -f pmldoc.fo;\
	(cd sections; make clean)

clean-html:
	@if [ -x "${XMLTO}" ]; then\
	  ${RM} -f pmldoc.html;\
	else\
	  echo "Not cleaning HTML document - can't find tool for rebuild";\
	fi

clean-pdf:
	@if [ -x "${XMLTO}" -a -x "${FOP}" ]; then\
	  ${RM} -f pmldoc.pdf;\
	else\
	  echo "Not cleaning PDF document - can't find tool for rebuild";\
	fi

clean-txt:
	@if [ -x "${XMLTO}" -a -x "${LYNX}" ]; then\
	  ${RM} -f pmldoc.txt;\
	else\
	  echo "Not cleaning TXT document - can't find tool for rebuild";\
	fi


%.html: %.xml $(SECTIONS)
	@if [ -x "${XMLTO}" -a -x "${DTDTO}" ]; then \
	  ${XMLTO} -m customhtml.xsl xhtml-nochunks $<; \
	else \
	  echo "Cannot update HTML document from XML source document"; \
	fi 


%.pdf: %.xml $(SECTIONS)
	@if [ -x "${XMLTO}" -a -x "${FOP}" -a -x "${DTDTO}" ]; then \
	  ${XMLTO} -m customfo.xsl fo $< ;\
	  ${FOP} $*.fo $@; \
	  ${RM} $*.fo; \
	else \
	  echo "Cannot update PDF document from XML source document"; \
	fi 


%.txt: %.html pmldoc.css
	@if [ -x "${LYNX}" ]; then \
	  ${LYNX} ${LYNXFLAGS} $< > $@; \
	else \
	  echo "Cannot update TXT document from HTML document"; \
	fi 
