#!/usr/bin/make -f

UPSTREAM_GIT := https://github.com/osrg/ryu.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)")

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

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func ryu-bin.postinst

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	for i in $(PYTHON3S) ; do \
		http_proxy=127.0.0.1:9 https_proxy=127.0.0.1:9 PYTHONPATH=. python$$i ryu/tests/run_tests.py ; \
	done
endif

override_dh_installman:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	cd doc; \
	make man SPHINXOPTS="-D today=\"$(BUILD_DATE)\"" ;\
	cp build/man/* ../debian/
	dh_installman
endif

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. PYTHON=python3 python3 -m sphinx -b html doc/source debian/python-ryu-doc/usr/share/doc/python-ryu-doc/html
	dh_sphinxdoc
endif

override_dh_auto_install:
	pkgos-dh_auto_install --no-py2
	rm -rf $(CURDIR)/debian/python3-ryu/usr/etc $(CURDIR)/debian/python-ryu/usr/etc

override_dh_installinit:
	dh_installinit --no-start --name=ryu

override_dh_installlogrotate:
	dh_installlogrotate --name=ryu

override_dh_clean:
	http_proxy=127.0.0.1:9 https_proxy=127.0.0.1:9 dh_clean
	rm -rf debian/*.init debian/*.upstart debian/*.service build doc/build

override_dh_auto_clean:
	rm -rf debian/ryu-manager.8 debian/ryu.8 debian/ryu-bin.postinst

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