#!/usr/bin/make -f

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

export SWIFT_TEST_CONFIG_FILE=$(CURDIR)/debian/swift-test.conf

export PYBUILD_TEST_ARGS=\
	test/unit \
	--exclude-test=test.unit.common.test_utils.TestUtils.test_get_logger_sysloghandler_plumbing
	# --processes=-1

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

override_dh_auto_build:
	dh_auto_build

	/usr/share/openstack-pkg-tools/pkgos_insert_include pkgos_func python3-swift.postinst

	set -e ; set -x ; \
	for i in $(sort $(wildcard debian/*.init.in)) ; do \
		debian/gen-init $$i ; \
	done

override_dh_auto_install:
	dh_auto_install

	rm debian/tmp/usr/bin/swift-init

override_dh_installinit:
	set -e ; set -x ; \
	for FILE in $(sort $(patsubst debian/%,%,$(wildcard debian/*.init))) ; do \
		PKG=`echo $$FILE | cut -d. -f1` ; \
		NAME=`echo $$FILE | cut -d. -f2` ; \
		dh_installinit --error-handler=true -p$$PKG --name=$$NAME ;\
	done

override_dh_installsystemd:
	set -e ; set -x ; \
	for FILE in $(sort $(patsubst debian/%,%,$(wildcard debian/*.service))) ; do \
		PKG=`echo $$FILE | cut -d. -f1` ; \
		NAME=`echo $$FILE | cut -d. -f2` ; \
		dh_installsystemd -p$$PKG --name=$$NAME ;\
	done

override_dh_systemd_enable:
	echo "Do nothing"

gen-init-configurations:
	echo "Do nothing"

# build with sphinx documentation
override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	LC_ALL=C.UTF-8 PYTHONPATH=. python3 -m sphinx doc/source $(CURDIR)/debian/swift-doc/usr/share/doc/swift-doc/base
	LC_ALL=C.UTF-8 PYTHONPATH=. python3 -m sphinx api-ref/source $(CURDIR)/debian/swift-doc/usr/share/doc/swift-doc/api-ref
	dh_sphinxdoc
endif

override_dh_installdocs:
	dh_installdocs

	dh_installdocs -A AUTHORS

override_dh_missing:
	dh_missing --fail-missing
