#!/usr/bin/make -f

export PYBUILD_NAME=gitlab
export DH_VERBOSE=1

# define DEB_VERSION
include /usr/share/dpkg/default.mk

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

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. http_proxy='http://127.0.0.1:9/' sphinx-build -N -E -bhtml docs build/html
	PYTHONPATH=. http_proxy='http://127.0.0.1:9/' sphinx-build -N -E -bman docs build/man
	rm -rf ./build/html/.doctrees

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	dh_sphinxdoc -ppython-gitlab-doc
endif

override_dh_auto_install:
	dh_auto_install
	# Remove the script from the Python 2 package and move it to gitlab-cli
	rm debian/python-gitlab/usr/bin/gitlab
	mkdir -p debian/gitlab-cli/usr/bin
	mv debian/python3-gitlab/usr/bin/gitlab debian/gitlab-cli/usr/bin/

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog.rst

override_dh_installman:
	PYTHONPATH=. \
		help2man -N -L C.UTF-8 \
		-n "GitLab API client" \
		--no-info --version-string="${DEB_VERSION}" \
		-o debian/gitlab.1 \
		./debian/gitlab-cli/usr/bin/gitlab
	dh_installman
