#!/usr/bin/make -f

export PYBUILD_NAME=nbsphinx

DEB_PKG_VERSION := $(shell dpkg-parsechangelog -S Version)
DEB_SRC_VERSION := $(firstword $(subst -, ,$(DEB_PKG_VERSION)))
UPS_PKG_VERSION := $(firstword $(subst +, ,$(DEB_SRC_VERSION)))
export NBSPHINX_VERSION_RELEASE ?= "$(UPS_PKG_VERSION) (Debian $(DEB_PKG_VERSION))"

default:
	@uscan --no-conf --dehs --report || true

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild

DEB_SPHINXDOC_DOCHTMLDIR=$(CURDIR)/debian/python-nbsphinx-doc/usr/share/doc/python-nbsphinx-doc/html
override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) sphinx-build -b html doc $(DEB_SPHINXDOC_DOCHTMLDIR)
	## lintian privacy-breach fix
	$(foreach htmlsed,$(wildcard $(CURDIR)/debian/adhoc/lintian/privacy-breach/*.html.sed), \
		sed -i -f $(htmlsed) $(DEB_SPHINXDOC_DOCHTMLDIR)/$(notdir $(patsubst %.sed,%,$(htmlsed))) $(NEWLINE)\
		)
	cp -vpr -t $(DEB_SPHINXDOC_DOCHTMLDIR) $(CURDIR)/debian/adhoc/lintian/privacy-breach/www
	## lintian duplicate-files fix
	rdfind -outputname /dev/null -makesymlinks true $(DEB_SPHINXDOC_DOCHTMLDIR)
	symlinks -r -c -s -v $(DEB_SPHINXDOC_DOCHTMLDIR)
	## cf Debian Bug report #739300
	ln -s /usr/share/javascript/mathjax $(DEB_SPHINXDOC_DOCHTMLDIR)/_static
	dh_sphinxdoc -O--buildsystem=pybuild
endif

override_dh_compress:
	dh_compress -Xwww

get-orig-source:
	uscan --no-conf --download-current-version --compression xz --verbose


define NEWLINE


endef
