#!/usr/bin/make -f

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

CFLAGS += $(CPPFLAGS)

%:
	dh $@ --without python2 \
	      --with python3 \
	      --buildsystem=pybuild

yorick/Makefile.orig:
	cp -n yorick/Makefile yorick/Makefile.orig
yorick-configure: yorick/Makefile.orig
	cd yorick; yorick -batch make.i
override_dh_auto_configure: yorick-configure
	dh_auto_configure

override_dh_auto_build:
	dh_auto_build
	set -ex; for python in $(shell py3versions -r); do \
	  $$python setup.py build; \
	done;
	cd yorick; make COPT_DEFAULT="" \
	                Y_CFLAGS="$(CFLAGS)" \
	                Y_LDFLAGS="$(LDFLAGS)" \
	                PKG_CFLAGS="-I ../common"

override_dh_auto_install:
	dh_auto_install
	dh_numpy3 -ppython3-svipc
	set -ex; for python in $(shell py3versions -r); do \
	  $$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
	done;
	dh_installyorick --no-make-install

override_dh_auto_clean: yorick-configure
	dh_auto_clean
	rm -Rf build
	cd yorick; make distclean; mv Makefile.orig Makefile
