#!/usr/bin/make -f

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

# need gcc 12.1 for mold to be able to process --gdb-index
export CC=gcc-12
export CXX=g++-12

include /usr/share/dpkg/default.mk

export PYBUILD_NAME=pyside6
export PYBUILD_SYSTEM=distutils
#export PYBUILD_BUILD_ARGS=
export PYBUILD_INSTALL_ARGS=--relwithdebinfo --verbose --build-tests --doc-build-online --ignore-git --qtpaths=/usr/lib/qt6/bin/qtpaths6 $(OPTION_JOBS) --root=build/pyside6_install

export MAIN_VERSION_UPSTREAM := $(shell echo $(DEB_VERSION_UPSTREAM))
# As per https://wiki.debian.org/HardeningWalkthrough as arm64 has strncpy warnings  
# To enable all, uncomment following lines
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
# Add CPPFLAGS to CXXFLAGS as CMake ignores CPPFLAGS by default
CXXFLAGS+=$(CPPFLAGS)

# Work around buildd bug (https://bugs.debian.org/842565)
undefine XDG_RUNTIME_DIR

override_dh_auto_clean:
	rm -r /usr/lib/python3/dist-packages/setuptools/
	python3 -m pip install -U --upgrade-strategy eager -r requirements.txt
	python3 -m pip install -U --upgrade-strategy eager -r requirements-doc.txt
	dh_auto_clean -O--buildsystem=pybuild --

override_dh_auto_build:
	# Skip build step as install step will force build again
	true

override_dh_auto_install:
	# DO NOT USE pybuild INSTALL to packaging dir as it skips some files that is required in the package
	# Instead install to some other dir and update the .install files as required
	dh_auto_install -O--buildsystem=pybuild --

	# List the files to be able to update *.install files
	echo "PySide/Shiboken files to package"
	echo "--------------------------------"
	-find build/qfp-*-relwithdebinfo/package
	echo "--------------------------------"
	-find build/qfp-*-relwithdebinfo/install
	echo "--------------------------------"
	-find build/pyside6_install
	echo "--------------------------------"

override_dh_dwz:
	true

#override_dh_shlibdeps:
#	ln -s python3/dist-packages/shiboken6/libshiboken6.abi3.so.6.5 debian/python3-pyside6/usr/lib/libshiboken6.abi3.so.6.5
#	dh_shlibdeps -a -O--buildsystem=pybuild -l$(CURDIR)/debian/python3-pyside6/usr/lib/python3/dist-packages/shiboken6/

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