#!/usr/bin/make -f

export PYBUILD_NAME=memray
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Disabled tests that has ModuleNotFoundError for import memray, need further investigation.
# 3rd from the last is timeout failure.
# Last two are 10s timeout failure in build i386.
export PYBUILD_TEST_ARGS = \
	-v -k 'not test_sys_manipulations_when_running_script \
	and not test_suppressing_sys_manipulations_when_running_script[-I] \
	and not test_suppressing_sys_manipulations_when_running_script[-P] \
	and not test_suppressing_sys_manipulations_when_running_module[-I] \
	and not test_suppressing_sys_manipulations_when_running_module[-P] \
	and not test_sys_manipulations_when_running_cmd \
	and not test_suppressing_sys_manipulations_when_running_cmd[-I] \
	and not test_suppressing_sys_manipulations_when_running_cmd[-P] \
	and not test_multithreaded_extension_with_native_tracking \
	and not test_simple_call_chain_with_native_tracking \
	and not test_inlined_call_chain_with_native_tracking \
	and not test_deep_call_chain_with_native_tracking \
	and not test_hybrid_stack_in_pure_python \
	and not test_hybrid_stack_in_pure_python_with_callbacks \
	and not test_hybrid_stack_of_allocations_inside_ceval \
	and not test_hybrid_stack_in_recursive_python_c_call \
	and not test_hybrid_stack_in_a_thread \
	and not test_hybrid_stack_of_python_thread_starts_with_native_frames \
	and not test_allocations_with_multiprocessing \
	and not test_allocations_with_multiprocessing_following_fork \
	and not test_pymalloc_allocations_after_fork \
	and not test_stack_cleanup_after_fork \
	and not test_aggregation_same_python_stack_but_different_native_stack[ALL_ALLOCATIONS] \
	and not test_aggregation_same_python_stack_but_different_native_stack[AGGREGATED_ALLOCATIONS] \
	and not test_reading_allocations_while_reading_stack_traces \
	and not test_live_tracking_waits_for_client \
	and not test_live_tracking'

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

override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--warnings=9

override_dh_auto_install:
	dh_auto_install
	# Strip unneeded symbols and notes from shared libraries
	find debian/python3-memray -name "*.so*" -exec strip --strip-unneeded --remove-section=.note.gnu.build-id {} +

override_dh_install:
	dh_install
	mkdir -p debian/python3-memray/usr/lib/python3/dist-packages/
	mv debian/python3-memray/usr/lib/python3.12/dist-packages/memray-*.egg-info debian/python3-memray/usr/lib/python3/dist-packages/
	rm -rf debian/python3-memray/usr/lib/python3.11/dist-packages/memray-*.egg-info
	rm -f debian/python3-memray/usr/bin/memray3.11
	rm -f debian/python3-memray/usr/bin/memray3.12

override_dh_installdocs:
	https_proxy='127.0.0.1:9' sphinx-build -b html docs build/sphinx/html
	dh_installdocs -ppython-memray-doc --doc-main-package=python-memray-doc build/sphinx/html
	dh_installdocs
