#
# 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

xsltproc:= xsltproc --novalid --path $(shell pwd) --xinclude
fop	:= xmlroff --backend=cairo

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.Processors.MacroFilter \
              Synopsis.Processors.Comments.Filter \
              Synopsis.Processors.Comments.Translator \
              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 html/examples
pdf: Tutorial.pdf DevGuide.pdf print/examples

html/Tutorial: Tutorial.xml $(appendix) examples 
	mkdir -p $@
	cp $(srcdir)/synopsis.css $@
	$(xsltproc) -o $@/ $(srcdir)/html.xsl $<
	mkdir -p $@/images
	cp $(srcdir)/images/*.png $@/images/
	cp examples/Paths/diagrams/*.png $@/images/

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

html/examples: examples
	mkdir -p $@
	make -C examples install-html prefix=$(abspath $@)

print/examples: examples
	mkdir -p $@
	make -C examples install-print prefix=$(abspath $@)

examples:
	make -C examples

print/Tutorial.pdf: $(appendix)

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

%.fo: %.xml
	$(xsltproc) -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 -f Tutorial.fo DevGuide.fo

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

