#!/usr/bin/make -f

VER := $(shell dpkg-parsechangelog | sed -n 's/^Version: *\([^-]\+\)-.\+/\1/p')

%:
	dh $@ --with python2,python3 --with sphinxdoc

override_dh_auto_install:
	python setup.py install --root debian/odemis --install-layout=deb
	python3 setup.py install --root debian/odemis --install-layout=deb


override_dh_installdocs:
	# Just be sure there is no left over from previous builds
	rm -rfv build/

	# Must be before any call to build_sphinx, so that the generated files are copied
	make -C doc/develop/ images # To build dependencies (eg: SVG -> PDF)

	# build & install multiple doc in multiple formats
	python setup.py build_sphinx --source-dir doc/develop/ --build-dir build/doc/develop/ --builder html --version $(VER) --release $(VER)
	# HTML is build/doc/develop/html/ , but rename so that it looks like ../develop-html
	mv build/doc/develop/html/ build/doc/develop/develop-html
	dh_installdocs build/doc/develop/develop-html
	
	# rst -> latex -> pdf
	python setup.py build_sphinx --source-dir doc/develop/ --build-dir build/doc/develop/ --builder latex --version $(VER) --release $(VER)
	make -C build/doc/develop/latex all-pdf # PDF is build/doc/develop/latex/odemis-develop.pdf
	dh_installdocs build/doc/develop/latex/odemis-develop.pdf
	
	# Install the "normal" documentation files (not needed? taken care by setup.py?)
	#dh_installdocs


override_dh_compress:
	# make sure it doesn't compress example scripts and PDF files
	dh_compress -X.py -X.m -X .pdf

