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

SRC=src
DOCBOOK-XSL = /usr/share/xml/docbook/stylesheet/docbook-xsl
DOCBOOKOPTS=--template=conf/pandoc/book.docbook --smart -t docbook -V lang=ru
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 \

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

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

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

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

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