#!/usr/bin/make -f

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

%:
	dh $@  --with python3

override_dh_auto_clean:
	python3 setup.py clean
	rm -f debian/*.init debian/*.service debian/*.upstart debian/mistral-common.postinst debian/mistral-common.config
	rm -rf debian/mistral-common.postrm debian/*.templates debian/po debian/mistral-api.config debian/mistral-api.postinst
	rm -rf build .stestr *.egg-info .pybuild mistral.log
	find . -iname '*.pyc' -delete
	for i in $$(find . -type d -iname __pycache__) ; do rm -rf $$i ; done

override_dh_auto_build:
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-common.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-common.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-api.config
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func mistral-api.postinst
	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_postrm mistral-common.postrm
	pkgos-merge-templates mistral-api mistral endpoint
	pkgos-merge-templates mistral-common mistral db rabbit ksat

override_dh_auto_install:
	echo "Do nothing..."

override_dh_auto_test:
	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

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	# The test selection data lives in debian/tests/include-list.txt
	# and debian/tests/exclude-list.txt, which pkgos-dh_auto_test
	# passes to stestr as its inclusion and exclusion lists.
	pkgos-dh_auto_test --dynamic
endif


	# Copy the configuration files
	set -e ; for i in logging.conf wf_trace_logging.conf ; do \
		install -D -m 0664 etc/$$i.sample $(CURDIR)/debian/mistral-common/usr/share/mistral-common/$$i ; \
	done
	install -D -m 0664 etc/policy.json $(CURDIR)/debian/mistral-common/usr/share/mistral-common/policy.json ; \
	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslo-config-generator \
		--namespace mistral.config \
		--namespace cotyledon \
		--namespace oslo.concurrency \
		--namespace oslo.db \
		--namespace oslo.messaging \
		--namespace oslo.middleware.cors \
		--namespace oslo.middleware.healthcheck \
		--namespace oslo.middleware.http_proxy_to_wsgi \
		--namespace keystonemiddleware.auth_token \
		--namespace oslo.log \
		--namespace oslo.policy \
		--namespace oslo.service.sslutils \
		--output-file $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf
	pkgos-readd-keystone-authtoken-missing-options $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf keystone_authtoken mistral

	PYTHONPATH=$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages oslopolicy-sample-generator \
		--output-file $(CURDIR)/debian/mistral-common/usr/share/mistral-common/policy.json \
		--namespace mistral

	pkgos-fix-config-default $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf keystone_authtoken auth_protocol http

	# Without the lock_path, mistral is broken.
	pkgos-fix-config-default $(CURDIR)/debian/mistral-common/usr/share/mistral-common/mistral.conf oslo_concurrency lock_path /var/lock/mistral

	dh_install
	dh_missing --fail-missing

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