#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1
#
# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Try to export buildflags. No guarantee to be useful yet
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
include /usr/share/dpkg/buildflags.mk

# https://bugs.debian.org/1123686
ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
export _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata__$(DEB_HOST_ARCH_OS)_$(DEB_HOST_MULTIARCH)
endif


%:
	dh $@ --with python3

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
TEST_FLAG := ON
else
TEST_FLAG := OFF
endif

# PYTHON_EXECUTABLE: force selection of default python version
#
# UNIT_TESTS: should only be used in debug builds, disable it
# following upstream recommendation.
#
# ZXING_WRITERS: old writer backend may be needed by system
# software (e.g., libreoffice).
#
override_dh_auto_configure:
	dh_auto_configure -- \
	        -DZXING_BLACKBOX_TESTS=$(TEST_FLAG)  \
	        -DZXING_UNIT_TESTS=OFF               \
	        -DZXING_PYTHON_MODULE=ON             \
	        -DZXING_C_API=ON                     \
	        -DZXING_WRITERS=BOTH                 \
	        -DZXING_EXAMPLES=ON                  \
	        -DZXING_USE_BUNDLED_ZINT=ON          \
	        -DZXING_DEPENDENCIES=LOCAL           \
	        -DPYTHON_EXECUTABLE:FILEPATH=$(shell command -v $$(py3versions -d))

override_dh_auto_test:
	# Exclude tests that needs samples directory
	dh_auto_test -- \
	        ARGS\+=-E \
	        ARGS\+=ReaderTest\\\|ZXingCTest \
	        $(NULL)

# For importing the new upstream release:
#
# uscan --verbose --force-download ; gbp import-orig --pristine-tar --uscan --component=zint
