#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

SOURCE_DIRECTORY := build/linux

CONFIGURE_FLAGS_PYTHON := --prefix=/usr --with-cuda --with-python=/usr/bin/python3 --with-install-type=module
BUILD_DIRECTORY_PYTHON := build-python

CONFIGURE_FLAGS_OCTAVE := --prefix=/usr --with-cuda --enable-octave --with-install-type=module
BUILD_DIRECTORY_OCTAVE := build-octave

%:
	dh $@ --sourcedirectory=$(SOURCE_DIRECTORY)

override_dh_auto_clean:
	dh_auto_clean --builddirectory $(BUILD_DIRECTORY_PYTHON)
	dh_auto_clean --builddirectory $(BUILD_DIRECTORY_OCTAVE)
	rm -f $(SOURCE_DIRECTORY)/config.sub  $(SOURCE_DIRECTORY)/config.guess  $(SOURCE_DIRECTORY)/install-sh
	rm -f python/astra/*.cpp  python/astra/config.pxi

override_dh_auto_configure:
	cd $(SOURCE_DIRECTORY) ; ./autogen.sh

# 	python package
	mkdir -p $(BUILD_DIRECTORY_PYTHON)
	dh_auto_configure --builddirectory $(BUILD_DIRECTORY_PYTHON) --sourcedirectory=$(SOURCE_DIRECTORY) -- $(CONFIGURE_FLAGS_PYTHON)

# 	octave package
	mkdir -p $(BUILD_DIRECTORY_OCTAVE)
	dh_auto_configure --builddirectory $(BUILD_DIRECTORY_OCTAVE) --sourcedirectory=$(SOURCE_DIRECTORY) -- $(CONFIGURE_FLAGS_OCTAVE)

override_dh_auto_build:
	dh_auto_build --builddirectory $(BUILD_DIRECTORY_PYTHON)
	dh_auto_build --builddirectory $(BUILD_DIRECTORY_OCTAVE)

override_dh_auto_test:
#	dh_auto_test --builddirectory $(BUILD_DIRECTORY_PYTHON)
#	dh_auto_test --builddirectory $(BUILD_DIRECTORY_OCTAVE)

override_dh_auto_install:
	dh_auto_install --builddirectory $(BUILD_DIRECTORY_PYTHON) --destdir debian/python3-astra-toolbox
	dh_auto_install --builddirectory $(BUILD_DIRECTORY_OCTAVE) --destdir debian/octave-astra-toolbox
