#!/usr/bin/make -f
# -*- makefile -*-

NULL =

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

include /usr/share/dpkg/architecture.mk

export DPKG_GENSYMBOLS_CHECK_LEVEL=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# http://ccache.samba.org/manual.html#_precompiled_headers
export CCACHE_SLOPPINESS=time_macros

export QT_SELECT=qt5

%:
	dh $@ --with pkgkde_symbolshelper

distro=$(shell lsb_release -c -s)
ifeq ($(distro), focal)
	# GlibC 2.31 in Ubuntu Focal has a bug which tries to use static-TLS area
	# to optimize TLS access in dynamically-loaded libraries, but end up not
	# having enough static-TLS area for the library that need it. See CMakeLists.txt
	# in the root. The issue is fixed in Glibc 2.32, but GlibC 2.31 in Debian seems
	# to be patched, thus this is not needed for Debian.
	ifneq ($(filter arm64 ppc64el, $(DEB_HOST_ARCH)),)
		ARCH_OPT := -DWORKAROUND_LIBGOMP_STATIC_TLS=ON
	endif
endif

override_dh_auto_configure:
	dh_auto_configure -- -DCMAKE_INSTALL_SYSCONFDIR=/etc \
	                     -DENABLE_UBUNTU_COMPAT=ON $(ARCH_OPT) \
	                     $(NULL)

# Tests are not written to be run in parallel.
# We ignore failing tests on PPC because the thumbnailer is irrelevant there,
# and gstreamer has bugs in the plugins for PPC.
test_args = --max-parallel=1 -- ARGS=\"--verbose\"
override_dh_auto_test:
#ifneq (,$(filter powerpc ppc64el s390x,$(DEB_HOST_ARCH)))
#	dh_auto_test $(test_args) || :
#else
	dh_auto_test $(test_args)
#endif

override_dh_install:
	rm debian/tmp/usr/lib/*/qt5/qml/Ubuntu/Thumbnailer.0.1/LomiriThumbnailerLoader.qml
	rm -Rv debian/tmp/usr/lib/*/qt5/qml/Ubuntu/Thumbnailer.0.1/qmldir
	dh_install

override_dh_missing:
	dh_missing --fail-missing

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=..
