#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PYVERS=$(shell pyversions -vr)

doc_dir=doc/user_manual/
rst_docs=$(wildcard $(addsuffix /*.rst, $(doc_dir)))
html_docs=$(patsubst %.rst, %.html, $(rst_docs))

%:
	dh $* --with python2 --buildsystem=python_distutils

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
SELFTEST_CONCURRENCY = BZR_CONCURRENCY=$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
SELFTEST_PARALLEL = --parallel=fork
else
SELFTEST_CONCURRENCY =
SELFTEST_PARALLEL =
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(SELFTEST_CONCURRENCY) BZR_PLUGINS_AT=builddeb@$(CURDIR) python$* /usr/bin/bzr selftest \
	    $(SELFTEST_PARALLEL) -v -s bp.builddeb
endif

%.html: %.rst
	rst2html --stylesheet-path=$(doc_dir)/user_manual.css $< > $@

override_dh_auto_build-indep: $(html_docs)
	rst2html README > README.html

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(html_docs)
	rm -f README.html

