#!/usr/bin/make -f

UPSTREAM_GIT := https://github.com/openstack-infra/jenkins-job-builder.git
include /usr/share/openstack-pkg-tools/pkgos.make

LAST_CHANGE = $(shell dpkg-parsechangelog -S Date)
BUILD_DATE  = $(shell LC_ALL=C date -u "+%B %d, %Y" -d "$(LAST_CHANGE)")
SPHINXOPTS := -D html_last_updated_fmt="$(BUILD_DATE)"

%:
	dh $@ --with python3,sphinxdoc

override_dh_auto_clean:
	python3 setup.py clean

override_dh_clean:
	rm -rf doc/build build .testrepository
	dh_clean

override_dh_auto_build:
	echo "Do nothing..."

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2 'tests\.(?!(.*TestCaseModuleBuilders\.test_yaml_snippet.*|.*TestCaseModulePublishers\.test_yaml_snippet.*|.*builder\.test_builder\.TestCaseTestBuilder\.test_plugins_list.*|.*builder\.test_builder\.TestCaseTestBuilder\.test_plugins_list_from_jenkins.*|.*localyaml\.test_localyaml\.TestCaseLocalYamlIncludeAnchors\.test_multiple_same_anchor_in_multiple_toplevel_yaml.*))'
endif
	mkdir $(CURDIR)/debian/jenkins-job-builder/usr
	mv $(CURDIR)/debian/python3-jenkins-job-builder/usr/bin \
	   $(CURDIR)/debian/jenkins-job-builder/usr/bin

override_dh_missing:
	dh_missing --fail-missing

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) PATH=$(PATH):$(CURDIR)/debian/jenkins-job-builder/usr/bin/ PYTHON=python3 python3 -m sphinx $(SPHINXOPTS) -b html doc/source debian/jenkins-job-builder-doc/usr/share/doc/jenkins-job-builder-doc/html
	dh_sphinxdoc -O--buildsystem=python_distutils
endif

override_dh_installman:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=$(CURDIR) PATH=$(PATH):$(CURDIR)/debian/jenkins-job-builder/usr/bin/ PYTHON=python3 python3 -m sphinx $(SPHINXOPTS) -b man doc/source doc/build/man
	dh_installman
endif

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
