# Makefile for PhotoML documentation DTD appendices
# Most recent modification: 22 October 2010

prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@/photoml
docdir = ${datadir}/doc

RM = @RM@
DTDTO = @DTDTO@

DTDPATH = ../../dtd
PHOTODTD = $(DTDPATH)/photo.dtd
PHOTODOC = photodtd.xml

DTDVERSION = @DTDVERSION@

.PHONY: all dtdver clean

all: $(PHOTODOC) dtdver

$(PHOTODOC): $(PHOTODTD)
	@if [ -x "$(DTDTO)" ]; then \
	   $(DTDTO) --docbook --top-id photodtd --title "PhotoML DTD" \
                    --anchor-prefix "photo-" $(PHOTODTD) $(PHOTODOC); \
	   sed -e 's/^<?xml.*?>//' $(PHOTODOC) > sed.tmp; \
	   mv sed.tmp $(PHOTODOC); \
	 else \
	  echo "Cannot build DTD description using dtdto"; \
	 fi

dtdver:
	@v=`grep -o -m 1 '<\!--DTDver-->\([\.0-9]\)\+' using.xml | sed 's/<\!--DTDver-->//'`;\
	if [ "$$v" != "${DTDVERSION}" ]; then\
	  sed 's/\(<\!--DTDver-->\)[\.0-9]\+/\1${DTDVERSION}/' using.xml > sed.tmp;\
	  mv sed.tmp using.xml;\
	fi

clean:
	@if [ -x "$(DTDTO)" ]; then \
	    ${RM} -f $(PHOTODOC); \
	  else \
	    echo "Not cleaning $(PHOTODOC) - can't find tool for rebuild"; \
	  fi
