#!/usr/bin/make -f
#export DH_VERBOSE = 1

include /usr/share/dpkg/pkg-info.mk

export PYBUILD_NAME=debugpy

# This is related to #1040062; see
# https://lists.debian.org/debian-alpha/2023/10/msg00007.html
ifneq (,$(filter $(DEB_HOST_ARCH), alpha ia64 x32))
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie
else
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
endif

CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

%:
	dh $@ --buildsystem=pybuild

execute_before_dh_auto_build:
	# This shared library is Python-version agnostic
	cd src/debugpy/_vendored/pydevd/pydevd_attach_to_process/linux_and_mac && \
	    g++ $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -shared \
	      -o ../attach.so -fPIC -nostartfiles attach.cpp

override_dh_python3:
	dh_python3 --no-ext-rename

ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	# * The http_proxy setting is to disable the proxies that pybuild
	# introduces; the tests might set up and use a local http server.
	# (See https://bugs.debian.org/1022188)
	#export http_proxy=""; \
	#export PYBUILD_SYSTEM=custom; \
	#PYBUILD_TEST_ARGS="\
	#	cd {build_dir}; \
	#	$(CURDIR)/debian/run_tests $(CURDIR)/debian/get_test_exclusions {interpreter} -m pytest" dh_auto_test
endif

execute_after_dh_installdocs:
	# dh_installdocs cannot handle a filename with spaces (bug #1016596)
	cp -p doc/Subprocess\ debugging.md debian/python3-debugpy/usr/share/doc/python3-debugpy
