#!/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

# Workaround linking issue on Ubuntu 26.04, where QArrayData::shared_null gets
# included in the binary instead of being referred from libQt5Core5.so, breaking
# QByteArray::isNull().
export DEB_BUILD_MAINT_OPTIONS += optimize=-lto

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)

override_dh_auto_test:
	dh_auto_test -- ARGS=\"--verbose\"

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=..
