#!/usr/bin/make -f

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

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

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# Build qt5 UI
export QMAKE=qmake6

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NJOBS := -j $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

%:
	dh $@ --with python3

override_dh_auto_configure:
	dh_auto_configure --buildsystem=meson -- -Drecollq=true -Dxadump=true \
	-Dwebkit=false -Dwebengine=true -Dsystemd=false \
	-Dpython.platlibdir=/usr/lib/python3/dist-packages

override_dh_auto_install:
	dh_auto_install
	# Cleanup
	find $(CURDIR) -type f -name '*.la' -exec rm -f '{}' \;
	find $(CURDIR) -type f -name '*.pyc' -exec rm -f '{}' \;
	rm -rf $(CURDIR)/debian/tmp/usr/lib/python*/*/*/__pycache__
	# Remove legacy format appdata.xml
	rm -f $(CURDIR)/debian/tmp/usr/share/metainfo/recoll.appdata.xml
	# Remove python2 filter
	rm -f $(CURDIR)/debian/tmp/usr/share/recoll/filters/hotrecoll.py

	# Older versions of meson don't take the platlibdir parameter above.
	# Move the Python modules to the right place here.
	mkdir -p $(CURDIR)/debian/tmp/usr/lib/python3/dist-packages
	if test -d $(CURDIR)/debian/tmp/usr/lib/python*/site-packages ; then \
		mv -f $(CURDIR)/debian/tmp/usr/lib/python*/site-packages/* \
		$(CURDIR)/debian/tmp/usr/lib/python3/dist-packages/;fi

	# Fix permissions
	chmod -x $(CURDIR)/debian/tmp/usr/share/recoll/filters/*.xsl

override_dh_auto_clean:
	dh_auto_clean
	rm -rf $(CURDIR)/qtqui/.qm
