#!/usr/bin/make -f
export DH_VERBOSE=1
include /usr/share/dpkg/buildflags.mk
PREFIX := /opt/percona-python3.14t
PYBIN := $(PREFIX)/bin/python3.14t
TMP := $(CURDIR)/debian/tmp

%:
	dh $@

# noble autoconf is too old for configure.ac, use the shipped configure
override_dh_autoreconf:

override_dh_auto_configure:
	./configure --prefix=$(PREFIX) --disable-gil --enable-shared \
	  --without-static-libpython --with-ensurepip=install \
	  CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" LDFLAGS="$(LDFLAGS) -Wl,-rpath,$(PREFIX)/lib"

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(TMP)
	cd $(TMP)$(PREFIX)/lib/python3.14t && rm -rf test idlelib tkinter turtledemo turtle.py
	rm -f $(TMP)$(PREFIX)/bin/idle3.14t $(TMP)$(PREFIX)/bin/idle3
	rm -f $(TMP)$(PREFIX)/lib/python3.14t/lib-dynload/_test*.so \
	  $(TMP)$(PREFIX)/lib/python3.14t/lib-dynload/_ctypes_test*.so \
	  $(TMP)$(PREFIX)/lib/python3.14t/lib-dynload/_xxtestfuzz*.so
	ln -sf python3.14t $(TMP)$(PREFIX)/bin/python3
	ln -sf python3.14t $(TMP)$(PREFIX)/bin/python
	LD_LIBRARY_PATH=$(TMP)$(PREFIX)/lib PYTHONHOME=$(TMP)$(PREFIX) $(TMP)$(PYBIN) -c \
	  'import sys, ssl, hashlib, sqlite3, zlib, ctypes, bz2, lzma, readline, uuid, _uuid, curses, dbm.gnu, dbm.ndbm; assert not sys._is_gil_enabled(); print("free-threaded", sys.version)'

# upstream test suite is not run here, the import check above is the gate
override_dh_auto_test:

# stdlib shebangs and .pyc files stay as CPython installed them
override_dh_python3:
override_dh_strip_nondeterminism:

override_dh_builddeb:
	dh_builddeb -- -Zgzip
