#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DPKG_EXPORT_BUILDFLAGS	 = yes
include /usr/share/dpkg/buildflags.mk

# Upstream does not use CPPFLAGS
CFLAGS	+= $(CPPFLAGS)

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

PYTHON2=$(shell pyversions -vr)

# Prevent setuptools/distribute from accessing the internet.
export http_proxy = http://127.0.0.1:9

%:
	dh  $@ --with python2

#ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
#test-python%:
#	cd python && python$* setup.py test -vv
#
#override_dh_auto_test: $(PYTHON2:%=test-python%) $(PYTHON3:%=test-python%)
#endif

.PHONY: override_dh_auto_build
override_dh_auto_build:
	dh_auto_build -- $(if $(filter i386,$(DEB_HOST_ARCH)),ARCH=i386)
	LDFLAGS="$(filter-out -pie,$(LDFLAGS))" \
	dh_auto_build --sourcedirectory=python --buildsystem=python_distutils

.PHONY: override_dh_auto_install
override_dh_auto_install:
	make install \
		DESTDIR=$(CURDIR)/debian/tmp \
		PREFIX=/usr \
		LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
		LDCONFIG=true
	dh_auto_install --sourcedirectory=python --buildsystem=python_distutils

.PHONY: override_dh_auto_clean
override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean --sourcedirectory=python --buildsystem=python_distutils
	dh_auto_clean --sourcedirectory=python --buildsystem=makefile

.PHONY: override_dh_makeshlibs
override_dh_makeshlibs:
	dh_makeshlibs -a -- -c4

.PHONY: override_dh_shlibdeps
override_dh_shlibdeps:
	dh_shlibdeps -a -- --warnings=7

.PHONY: override_dh_install
override_dh_install:
	dh_install --list-missing -X.pyc
