#!/usr/bin/make -f

#export DH_VERBOSE = 1

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

%:

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

override_dh_auto_build:
	# Fix license format for compatibility with older setuptools
	sed -i 's/license = "Apache-2.0"/license = {text = "Apache-2.0"}/' pyproject.toml
	dh_auto_build
	# Force the build of CFFI bindings
	python3 pywayland/ffi_build.py
	# Generate protocol modules
	python3 -m pywayland.scanner --with-protocols
	# Skip documentation build due to circular import issues in ext_workspace_v1
	#cd doc; $(MAKE) man text
	#use always same id to make the package reproducible
	#sed -i "s/id='[0-9]*'/id='140737181137280'/" doc/_build/text/module/server.txt
	#sed -i "s/aq[0-9]\{9,\}/aq140737181137280/" doc/_build/man/pywayland.1

override_dh_auto_clean:
	find pywayland/protocol/ -mindepth 1 -type d -exec rm -rf {} +
	rm -rf pywayland/_ffi.*
	rm -rf doc/_build
	rm -rf doc/module/protocol
	rm -rf *.egg-info
	dh_auto_clean

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
		export PYTHONPATH=$(pwd)
		PYTHONPATH=$(pwd) python3 -m pytest test/test_client_destroy.py
endif

override_dh_install:
	dh_install
	PYTHONPATH=$(pwd) python3 -m pytest -k 'not test_server_eventloop and not test_event_queue and not test_get_registry and not test_server_display and not test_utils' test/

override_dh_installman:
	# Skip man page installation since documentation is not built
	#mv doc/_build/man/pywayland.1  doc/_build/man/pywayland-scanner.1
	#dh_installman
