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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PYBUILD_NAME=pygalmesh

export PYBUILD_SYSTEM=distutils

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

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

# some arches (mostly 32 bit) don't provide enough memory to build with debug symbols
ARCH_NO_DEBUG_SYMBOLS := armhf i386 mips mipsel hppa hurd-i386 kfreebsd-i386 powerpcspe x32
ifneq ($(findstring $(DEB_HOST_ARCH),$(ARCH_NO_DEBUG_SYMBOLS)),)
# disable debugging symbols (replace -g with -g0 in build flags) on weak arches
  CFLAGS := $(shell dpkg-buildflags --get CFLAGS | sed 's/-g /-g0 /' )
endif

ifeq ($(DEB_HOST_ARCH),s390x)
  export PYBUILD_TEST_ARGS = -k "not test_from_array_with_subdomain_sizing"
endif

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

# debug symbols (-g) have been switched off (-g0) in CFLAGS for some arches, so no point building dbgsym packages
override_dh_strip:
	case " $(ARCH_NO_DEBUG_SYMBOLS) " in \
	    *\ $(DEB_HOST_ARCH)\ *) dh_strip --no-automatic-dbgsym;; \
	    *) dh_strip;; \
	esac

override_dh_dwz:
	case " $(ARCH_NO_DEBUG_SYMBOLS) " in \
	    *\ $(DEB_HOST_ARCH)\ *) echo "skipping dh_dwz since debug symbols (-g) have been switched off (-g0) for $(DEB_HOST_ARCH)";; \
	    *) dh_dwz;; \
	esac
