#
# Copyright (C) 2003 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

SHELL	:= /bin/sh

srcdir	:= @srcdir@

processors := Synopsis.Parsers.Python.Parser \
              Synopsis.Parsers.IDL.Parser \
              Synopsis.Parsers.Cpp.Parser \
              Synopsis.Parsers.C.Parser \
              Synopsis.Parsers.Cxx.Parser \
              Synopsis.Processors.Linker \
              Synopsis.Formatters.Dump.Formatter \
              Synopsis.Formatters.Docbook.Formatter \
              Synopsis.Formatters.Texinfo.Formatter \
              Synopsis.Formatters.Dot.Formatter \
              Synopsis.Formatters.HTML.Formatter \
              Synopsis.Formatters.SXR.Formatter

appendix:= $(patsubst %, %.xml, $(processors))
examples:= $(shell cd $(srcdir) && find examples -path '*/.svn' -prune -o -type f -a -print)

.PHONY: examples

vpath %.xml $(srcdir)

all: html pdf
html: html/Tutorial html/DevGuide
pdf: Tutorial.pdf DevGuide.pdf

html/Tutorial: Tutorial.xml $(appendix) examples 
	mkdir -p $@
	cp $(srcdir)/synopsis.css $@
	xsltproc --novalid --path $(shell pwd) --xinclude -o $@/ $(srcdir)/html.xsl $<
	mkdir -p $@/images
	cp $(srcdir)/images/*.png $@/images/
	cp examples/Paths/doc4/*.png $@/images/

html/DevGuide: DevGuide.xml
	mkdir -p $@
	cp $(srcdir)/synopsis.css $@
	xsltproc --novalid -o $@/ $(srcdir)/html.xsl $<
	mkdir -p $@/images
	cp $(srcdir)/images/*.png $@/images/

examples:
	for file in $(examples); do \
          if ! cmp -s $(srcdir)/$$file $$file 2>/dev/null; then \
            mkdir -p `dirname $$file`;\
            cp -p $(srcdir)/$$file $$file;\
          fi\
        done
	make -C examples       # build examples...
	make -C examples clean # ...but remove temporary files

Tutorial.pdf: $(appendix)

%.pdf: %.fo
	fop $< $@

%.fo: %.xml
	xsltproc --novalid --path $(shell pwd) --xinclude -o $@ $(srcdir)/fo.xsl $^
	mkdir -p images
	cp -u $(srcdir)/images/*.svg images/

$(appendix): %.xml:
	python $(srcdir)/parameters.py $(patsubst %.xml, %, $@) $@

clean:
	rm -f Synopsis.*.xml
	rm Tutorial.fo DevGuide.fo

distclean: clean
	rm -rf html Tutorial.pdf DevGuide.pdf

