#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

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

# Get the supported Python versions
PYVERS = $(shell pyversions -r -v)
PY3VERS = $(shell py3versions -r -v)

# Callable functions to determine the correct PYTHONPATH
pythonpath = $$(ls -d $(CURDIR)/build/lib.*-$(1))

export PYBUILD_NAME=subvertpy
export HOME=$(CURDIR)/nonexistent

%:
	CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" \
	LDFLAGS="$(LDFLAGS)" dh $* --with python2,python3 --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	PYTHONHASHSEED=0 $(MAKE) pydoctor

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/python3-subvertpy/usr/share/doc/python3-subvertpy \
	         debian/python-subvertpy/usr/share/doc/python-subvertpy
	cp -a apidocs debian/python-subvertpy/usr/share/doc/python-subvertpy/api
	cp -a apidocs debian/python3-subvertpy/usr/share/doc/python3-subvertpy/api
	mv debian/python3-subvertpy/usr/bin/subvertpy-fast-export \
	   debian/python3-subvertpy/usr/bin/subvertpy3-fast-export
	mv debian/python-subvertpy/usr/bin/subvertpy-fast-export \
	   debian/python-subvertpy/usr/bin/subvertpy2-fast-export

override_dh_strip:
	dh_strip -p python-subvertpy --dbgsym-migration='python-subvertpy-dbg (<< 0.9.3-1)'
	dh_strip -p python3-subvertpy
