#!/usr/bin/make -f

# export DH_VERBOSE=1

# DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
# DPKG_EXPORT_BUILDFLAGS = 1
# include /usr/share/dpkg/buildflags.mk

UPSTREAM_GIT := https://github.com/apache/qpid-proton
include /usr/share/openstack-pkg-tools/pkgos.make

export DEB_CXXFLAGS_MAINT_APPEND = -Wno-error=unused-but-set-variable

# This has to be exported to make some magic below work.
export DH_OPTIONS
export DH_ALWAYS_EXCLUDE=LICENSE

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# CMake no longer installs the Python binding: build the C and C++
# libraries only, then build the CFFI-based Python binding (setuptools)
# against the C library installed in debian/tmp.
export PYBUILD_SYSTEM=cmake
export PYBUILD_CONFIGURE_ARGS=-DBUILD_BINDINGS=cpp \
	-DCMAKE_INSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH)
export PYBUILD_BUILD_ARGS=all docs

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

override_dh_auto_install:
	dh_auto_install
	set -e ; cd python && \
		QPID_PYTHON_UNBUNDLING=unbundled \
		CFLAGS="$$CFLAGS -I$(CURDIR)/debian/tmp/usr/include" \
		LDFLAGS="$$LDFLAGS -L$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)" \
		PKG_CONFIG_PATH=$(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig \
		python3 setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb

override_dh_auto_test:
	# TODO enable them when they work again

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. python3 -m sphinx -b html python/docs $(CURDIR)/debian/python-qpid-proton-doc/usr/share/doc/python-qpid-proton-doc/html
	dh_sphinxdoc
endif
