# Генератор документации 

SRC=src
DOCBOOK-XSL = /usr/share/xml/docbook/stylesheet/docbook-xsl
DOCBOOKOPTS=--template=conf/pandoc/book.docbook --smart -t docbook -V lang=ru
ODTOPTS=-t odt --standalone
PANDOC_PDF_OPTIONS=--latex-engine=xelatex \
					   --template=conf/pandoc/template.latex \
					   -V lang=$(LANGUAGE) \
					   -V papersize:"a4paper" \
					   -V geometry:margin=2cm \
					   -V mainfont="Liberation Serif" \
					   -V sansfont="Liberation Sans" \
					   -V classoption=11pt \
					   --smart \
					   --no-tex-ligatures
#					   --highlight-style=kate \
#					   -V classoption=12pt \

spec.md: 
	gpp -H -I$(SRC) $(SRC)/index.md > spec.md

spec.xml: spec.md
	@echo Creating full XML image
ifdef VCSREV
	pandoc $(DOCBOOKOPTS) spec.md \
	| xsltproc --encoding utf8 \
		--stringparam vcs.revision $(VCSREV) \
		--stringparam vcs.changedby "$(VCSCHANGEDBY)" \
		--xinclude conf/vcs/insert-revision-and-build-date.xsl - > spec.xml
else
	pandoc $(DOCBOOKOPTS) spec.md -o spec.xml
	#SP_ENCODING="UTF-8" xmllint --encode utf8 --xinclude src/index.xml > spec.xml
endif
	sed -i 's/xml:base=".*"//g' spec.xml
	rm -f spec.md

html: spec.xml 
	@echo Creating html document
	rm -rf bin/html
	mkdir bin/html
	LC_ALL=en_US.UTF-8 xmlto xhtml -m conf/html/settings.xsl -o bin/html spec.xml
	tar --exclude-vcs -c resources | tar x -C bin/html
	# Working around images used in stylesheets
	mkdir bin/html/resources/docbook
	cp -a $(DOCBOOK-XSL)/images bin/html/resources/docbook
	rm -f spec.xml

pdf: spec.md
	@echo Creating pdf document
	mkdir -p bin/pdf
#	SP_ENCODING="UTF-8" docbook2pdf -o bin spec.xml
	pandoc $(PANDOC_PDF_OPTIONS) -o bin/pdf/spec.pdf spec.md
	rm -f spec.xml spec.md

odt-ru: spec.md
	[ -d bin/odt ] || mkdir bin/odt
	pandoc $(ODTOPTS) -o bin/odt/spec.odt spec.md

odt: odt-ru
	rm -f spec.md

docx: spec.md
	mkdir -p bin/docx
	pandoc -s -S -o bin/docx/spec.docx spec.md

clean:
	@echo Remove all
	rm -rf *.xml *.md bin/*
