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

SRC=src
DOCBOOK-XSL = /usr/share/xml/docbook/stylesheet/docbook-xsl
DOCBOOKOPTS=--template=conf/pandoc/book.docbook --smart -t docbook -V lang=ru

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

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

html: additional.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 additional.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 additional.xml

pdf: additional.xml
	@echo Creating pdf document
#	SP_ENCODING="UTF-8" docbook2pdf -o bin additional.xml
	dblatex -b xetex -o bin/additional.pdf additional.xml
	rm -f additional.xml

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