#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# Verbose test output
export VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

UPSTREAM_VERSION=$(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/\+(debian|dfsg|ds|deb)[0-9]*.*//')

BUILD_DATE=$(shell LC_ALL=C date -u "+%d %B %Y" -d "@$(SOURCE_DATE_EPOCH)")

MANPAGES := $(wildcard debian/man/*.*.xml)

DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)

CHECK = check
ifneq (,$(filter $(DEB_BUILD_ARCH),mips s390x sparc hppa ppc64))
	CHECK = nocheck
endif

%:
	dh $@

override_dh_clean:
	dh_clean debian/man/*.1

override_dh_auto_configure:
	dh_auto_configure -- --disable-charls

override_dh_auto_build:
	# Create man page from DocBook XML
	for x in $(MANPAGES) ; do \
	    docbook2x-man --string-param header-3="$(BUILD_DATE)" $$x ; \
	    mv `basename $$x | sed 's/.xml$$//'` `dirname $$x` ; \
	done

	dh_auto_build

override_dh_auto_test:
ifeq ($(CHECK), "check")
	dh_auto_test --max-parallel=1 || echo "Ignoring test failures"
endif

override_dh_install:
	find debian/tmp/usr/lib/ -type f -name "*.la" -delete
	dh_install

override_dh_makeshlibs:
	dh_makeshlibs -- -v$(UPSTREAM_VERSION)