#!/usr/bin/make -f
export DH_VERBOSE = 1
# Suppress __pycache__ pollution
export PYTHONDONTWRITEBYTECODE = 1
# Don't install to /usr/local
export DEB_PYTHON_INSTALL_LAYOUT = deb_system

%:
	dh $@ --with python3

# Upstream's CMakeLists.txt is a leftover from the Conan-based build and
# depends on cmake modules that no longer exist in the source tree.  Uranium
# is pure Python, so do the (small) amount of work by hand.
override_dh_auto_configure:
	:

override_dh_auto_build:
	set -e; for po in $$(find resources/i18n -name '*.po'); do \
	    d=$$(dirname "$$po"); \
	    mkdir -p "$$d/LC_MESSAGES"; \
	    msgfmt "$$po" -o "$$d/LC_MESSAGES/$$(basename "$$po" .po).mo" -f; \
	done

override_dh_auto_install:
	install -d debian/python3-uranium/usr/lib/python3/dist-packages
	cp -a UM debian/python3-uranium/usr/lib/python3/dist-packages/
	install -d debian/python3-uranium/usr/share/uranium
	cp -a resources debian/python3-uranium/usr/share/uranium/
	install -d debian/uranium-plugins/usr/lib/uranium
	cp -a plugins debian/uranium-plugins/usr/lib/uranium/
	# Upstream ships one executable .qml file; it is not a script.
	find debian/uranium-plugins -name '*.qml' -exec chmod 0644 {} +
	install -d debian/uranium-tools/usr/share/uranium
	cp -a scripts debian/uranium-tools/usr/share/uranium/

override_dh_auto_clean:
	dh_clean
	rm -rf .cache
	find . -name __pycache__ -print0 | xargs -0 rm -rf
	find resources/i18n -name '*.mo' -delete

override_dh_auto_test:
	# Upstream's test suite is not suitable for the Debian build.
