#!/usr/bin/make -f

UPSTREAM_GIT = https://github.com/openstack/neutron-fwaas.git
include /usr/share/openstack-pkg-tools/pkgos.make

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

override_dh_auto_clean:
	python3 setup.py clean
	rm -f debian/*.init debian/*.service debian/*.upstart

override_dh_clean:
	dh_clean
	find . -type f -name "*.pyc" -delete
	rm -rf build

override_dh_auto_build:
	echo "Do nothing..."

override_dh_auto_install:
	echo "Do nothing..."

override_dh_install:
	set -e ; for pyvers in $(PYTHON3S); do \
		python$$pyvers setup.py install --install-layout=deb \
			--root $(CURDIR)/debian/tmp; \
	done
	rm -rf $(CURDIR)/debian/tmp/usr/etc

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	pkgos-dh_auto_test --no-py2 'neutron_fwaas\.tests\.unit\.(?!.*services\.firewall\.plugins\.cisco\.test_cisco_fwaas_plugin\.TestCiscoFirewallPlugin\.test_update_csr_firewall.*)'
endif

	mkdir -p $(CURDIR)/debian/neutron-fwaas-common/etc/neutron
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages python3-oslo-config-generator \
		--output-file $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/fwaas_driver.ini \
		--wrap-width 140 \
		--namespace firewall.agent

	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages python3-oslo-config-generator \
		--output-file $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/neutron_fwaas.conf \
		--wrap-width 140 \
		--namespace neutron.fwaas

	# Enable the plugin by default
	pkgos-fix-config-default $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/fwaas_driver.ini fwaas driver neutron_fwaas.services.firewall.drivers.linux.iptables_fwaas.IptablesFwaasDriver
	pkgos-fix-config-default $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/fwaas_driver.ini fwaas enabled true

	mkdir -p $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/rootwrap.d
	cp etc/neutron/rootwrap.d/fwaas-privsep.filters $(CURDIR)/debian/neutron-fwaas-common/etc/neutron/rootwrap.d

	dh_install
	dh_missing --fail-missing

override_dh_auto_test:
	echo "Do nothing..."

# Commands not to run
override_dh_installcatalogs:
override_dh_installemacsen override_dh_installifupdown:
override_dh_installinfo override_dh_installmenu override_dh_installmime:
override_dh_installmodules override_dh_installlogcheck:
override_dh_installpam override_dh_installppp override_dh_installudev override_dh_installwm:
override_dh_installxfonts override_dh_gconf override_dh_icons override_dh_perl override_dh_usrlocal:
