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

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

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

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

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

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

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