#!/usr/bin/make -f

DEBVERS ?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION ?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//' -e 's/[+].*//' -e 's/~git.*//g' -e 's/~/./g')
export PBR_VERSION=$(VERSION)

UPSTREAM_GIT := https://opendev.org/x/ovn-bgp-agent
include /usr/share/openstack-pkg-tools/pkgos.make

%:
	dh $@ --buildsystem=python_distutils --with python3

override_dh_auto_clean:
	rm -rf build *.egg-info $(CURDIR)/debian/ovn-bgp-agent.init $(CURDIR)/debian/ovn-bgp-agent.service
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_auto_build:
	echo "Doing nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_auto_test:
	echo "Do nothing..."

override_dh_install:
	pkgos-dh_auto_install --no-py2 --in-tmp
		
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2 'ovn_bgp_agent\.tests\.unit\.(?!utils\.test_linux_net\.TestLinuxNet\.test_add_ips_to_dev|utils\.test_linux_net\.TestLinuxNet\.test_del_ips_from_dev|utils\.test_linux_net\.TestLinuxNet\.test_delete_ip_routes)'
endif

	mkdir -p $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslo-config-generator \
		--namespace ovnbgpagent \
		--output-file $(CURDIR)/debian/ovn-bgp-agent/etc/ovn-bgp-agent/bgp-agent.conf

	dh_install
	dh_missing --fail-missing


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