#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.

export MESON_PRINT_TEST_OUTPUT=1

export QT_SELECT=qt5

# We're not in 1963 anymore, Toto!
export LC_ALL=C.UTF-8

export PYBUILD_NAME=meson

#export DH_VERBOSE = 1


# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --with python3 --buildsystem=pybuild


# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
#	dh_auto_configure -- #	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	./run_tests.py
endif

override_dh_clean:
	dh_clean
	rm -f meson-test-run.txt meson-test-run.xml
	rm -rf __pycache__
	rm -rf mesonbuild/__pycache__
	rm -rf mesonbuild/*/__pycache__

override_dh_install:
# Helper script to autogenerate cross files.
	dh_install
	mkdir -p $$(pwd)/debian/meson/usr/share/meson
	cp debian/debcrossgen $$(pwd)/debian/meson/usr/share/meson
	rm -rf $$(pwd)/debian/meson/usr/lib/python*/dist-packages/mesonbuild/__pycache__
	rm -rf $$(pwd)/debian/meson/usr/lib/python*/dist-packages/mesonbuild/*/__pycache__
# For some reason Debian helpers install the files in the wrong directory,
# i.e. /usr/lib/python3.6 instead of /usr/lib/python3. I don't know why
# or how to fix it, since we just call to the default tools with default
# parameters. Fix manually.
	mv $$(pwd)/debian/meson/usr/lib/python3.* $$(pwd)/debian/meson/usr/lib/python3