#!/usr/bin/make -f

DEB_MAINT_BUILD_OPTIONS := hardening=+all
DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed
DPKG_EXPORT_BUILDFLAGS = 1
LC_ALL := C.UTF-8
include /usr/share/dpkg/default.mk

export PYBUILD_NAME = segyio
export PYBUILD_BEFORE_TEST = cp -r {dir}/python/test {dir}/test-data {build_dir}
export SEGYIO_NO_GIT_VER=1
export LC_ALL

LIB_DIR = usr/lib/$(DEB_HOST_MULTIARCH)
STATIC = static-$(DEB_HOST_MULTIARCH)
DTMPLIB := $(CURDIR)/debian/tmp/$(LIB_DIR)

%:
	dh $@ --with python3 --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure \
		-- -DBUILD_SHARED_LIBS=ON -DBUILD_PYTHON=OFF
	dh_auto_configure --builddirectory=$(STATIC) \
		-- -DBUILD_SHARED_LIBS=OFF -DBUILD_PYTHON=OFF -DBUILD_TESTING=OFF

override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean --builddirectory=$(STATIC)
	dh_auto_clean --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	dh_auto_build --builddirectory=$(STATIC)

override_dh_auto_install:
	dh_auto_install --builddirectory=$(STATIC)
	dh_auto_install
	dh_auto_build --buildsystem=pybuild -- \
		--build-args="build_ext --library-dirs $(DTMPLIB)"
	dh_auto_install --buildsystem=pybuild
	LD_LIBRARY_PATH=$(DTMPLIB):$(LD_LIBRARY_PATH) \
		dh_auto_test --buildsystem=pybuild -- --test-args=test/*

override_dh_python3:
	dh_python3 --requires=requirements.txt

override_dh_missing:
	dh_missing --list-missing
