#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

STEM = m2r
DESTDIR = debian/tmp
DOCDIR = debian/python-$(STEM)-doc/usr/share/doc/python-$(STEM)-doc/html

CMD = $(STEM)
_ENV = $(strip \
 PATH="$(DESTDIR)/usr/bin:$(PATH)" \
 PYTHONPATH="$(DESTDIR)/usr/lib/$(shell py3versions -d)/dist-packages")

# generate manpage with help2man from --help option of python script
_mkman = $(_ENV) \
 help2man $(if $3,--name "$(strip $3)") --no-info --version-string $(DEB_VERSION_UPSTREAM) --output $2 $1 \
 || { $(_ENV) $1 --help; false; }

%:
	dh $@ --with python3,sphinxdoc --buildsystem=pybuild --exclude=.nojekyll

execute_after_dh_auto_build:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	sphinx-build -b html docs debian/doc/html
endif

override_dh_sphinxdoc:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_sphinxdoc --exclude=MathJax.js
endif

# * generate manpage
execute_after_dh_auto_install:
	$(call _mkman, $(CMD), debian/$(CMD).1, \
		command-line tool to convert from markdown containing reStructuredText (rst) to reStructuredText)
#	find $(destdir)/usr/lib -name '*.pyc' -delete
#	find $(destdir)/usr/lib -type d -empty -delete
