#!/usr/bin/make -f

# Uncomment below to enable verbose build messages.
#export DH_VERBOSE = 1

# Enable all build hardening flags.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Include architecture information.
include /usr/share/dpkg/architecture.mk

# Export the DPKG default build flags.
DPKG_EXPORT_BUILDFLAGS = 1

# Include the default build flags.  <https://wiki.debian.org/Hardening#dpkg-buildflags>
include /usr/share/dpkg/buildflags.mk

# Enable the verbose waf build argument so that blhc can analyze the build flags.  waf is the system that builds the bootloader from C code.
export PYINSTALLER_BOOTLOADER_WAF_ARGS = --verbose

# Run the tests with 8 parallel threads.
# Disable the tests that don't currently work.
# * TestFunctions.test_find_module requires modulegraph, which isn't currently packaged in Debian.  TODO:  Possibly.  Other modulegraph tests succeed.
# * test_user_preferred_locale fails with a locale error, possibly because the build environment might force a default locale.
# * test_scapy3 fails with an import error.  It might be fixed once pyinstaller-hooks-contrib is packaged.
# * test_Qt_QTranslate fails for a currently unknown reason (an assertion error).  It might be fixed when pyinstaller-hooks-contrib is packaged.
export PYBUILD_TEST_ARGS=-n 8 \
  --deselect tests/unit/test_modulegraph/test_modulegraph.py::TestFunctions::test_find_module \
  --deselect tests/functional/test_qt.py::test_Qt_QTranslate \
  --deselect tests/functional/test_libraries.py::test_scapy3 \
  --deselect tests/functional/test_basic.py::test_user_preferred_locale
ifeq (,$(filter amd64 arm64 armhf i386,$(DEB_HOST_ARCH)))
  # QtWebEngine is only available on some architectures.
  PYBUILD_TEST_ARGS += \
    --deselect tests/functional/test_qt.py::test_Qt_QtWebEngineQuick_PySide6 \
    --deselect tests/functional/test_qt.py::test_Qt_QtWebEngineWidgets_PySide6
  # pyinstaller-hooks-contrib is temporarily disabled on architectures without QtWebEngine for bootstrapping.
  # Disable tests that require it.
  PYBUILD_TEST_ARGS += \
    --deselect tests/functional/test_libraries.py::test_zeep \
    --deselect tests/unit/test_pyimodulegraph.py::test_metadata_searching
endif

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_install:
	# Remove the unnecessary library README file.
	rm debian/tmp/usr/lib/python3*/dist-packages/PyInstaller/lib/README.rst
