#!/usr/bin/make -f
#export DH_VERBOSE = 1

# Canonical OpenStack debian/rules template for Neutron plugins
# This package is an Octavia provider driver, not a Neutron plugin.

export PYBUILD_NAME = ovn_octavia_provider

# -e: Fail build if any command fails, not just the last call
SHELL := /bin/sh -e

UPSTREAM_GIT := https://opendev.org/openstack/ovn-octavia-provider.git

DEBVERS ?= $(shell dpkg-parsechangelog -SVersion)
VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/[+].*//' -e 's/~git.*//g' -e 's/+git.*//g' -e 's/~/./g')
# pbr's only version source: clean drops PKG-INFO and a .dsc has no .git.
export PBR_VERSION = $(VERSION)

include /usr/share/openstack-pkg-tools/pkgos.make

# Whole-word match; also honors the nodoc/nocheck build profiles.
NODOC   := $(filter nodoc nodocs,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES))
NOCHECK := $(filter nocheck,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES))

DOCPKG := python-ovn-octavia-provider-doc

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

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build .pybuild .stestr .testrepository .eggs
	find . -type d -name __pycache__ -prune -exec rm -rf {} +

	# doc/source/conf.py runs the config and policy sample generators,
	# which write into the source tree.
	rm -rf doc/build
	rm -f doc/source/_static/*.policy.yaml.sample
	rm -f doc/source/_static/config-samples/*.sample
	rm -f etc/policy.yaml.sample etc/*.conf.sample

override_dh_auto_build:
	# Regenerates ovn_octavia_provider.egg-info, which dh_auto_clean
	# removed. Otherwise entry points vanish and generators create empty
	# files with exit 0
	dh_auto_build

override_dh_auto_test:
ifeq (,$(NOCHECK))
	# Package-specific
	# The OVN idl fixtures are not parallel-safe.
	pkgos-dh_auto_test --no-py2 --serial
endif

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2

override_dh_sphinxdoc:
ifeq (,$(NODOC))
	PYTHONPATH=$(CURDIR) python3 -m sphinx -b html doc/source \
		$(CURDIR)/debian/$(DOCPKG)/usr/share/doc/$(DOCPKG)/html
	dh_sphinxdoc -p$(DOCPKG)
endif

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