#!/usr/bin/make -f

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

# magic debhelper rule
%:
	dh  $@  --with python3 --buildsystem=pybuild

PYTHON3=$(shell py3versions -vr)


DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR:=/usr/lib/$(DEB_HOST_MULTIARCH)

LD_LIBRARY_PATH:=$(CURDIR)/Src:$(LD_LIBRARY_PATH)
export LD_LIBRARY_PATH

override_dh_auto_build:
	cp debian/aliases.ld Src/aliases.ld
	$(MAKE) -C Src all
	dh_auto_build
	# For some reason, dh_strip isn't stripping this properly, according to lintian
	strip Src/libsphere.a

override_dh_auto_install: $(PYTHON3:%=install-python%)
	$(MAKE) -C Src install DESTDIR=`pwd`/debian/tmp PREFIX=/usr LIBDIR=$(LIBDIR)
	dh_auto_install
	dh_link -p libsphere-dev $(LIBDIR)/libsphere.so.0d $(LIBDIR)/libsphere.so
	dh_numpy3

override_dh_auto_clean:
	dh_clean
	$(MAKE) -C Src clean || echo "No clean target in original Makefile"
	rm -rf build Src/aliases.ld

build-python%:
	python$* setup.py build

install-python%:
	python$* setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb

