#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export PYBUILD_NAME = slepc4py

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

SLEPC_BASE_VERSION=3.7

SLEPC_MAJOR_VERSION=$(shell echo $(SLEPC_BASE_VERSION) | sed "s/\..*//")
SLEPC_MINOR_VERSION=$(shell echo $(SLEPC_BASE_VERSION) | sed "s/.*\.//")
SLEPC_NEXT_VERSION=$(shell echo $(SLEPC_MAJOR_VERSION).$$(( $(SLEPC_MINOR_VERSION) + 1 )) )

PETSC_DIR=/usr/lib/petscdir/$(SLEPC_BASE_VERSION)
SLEPC_DIR=/usr/lib/slepcdir/$(SLEPC_BASE_VERSION)

# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


# main packaging script based on dh7 syntax
%:
	dh $@ --with python2

override_dh_clean:
	dh_clean
	rm -rf .eggs

override_dh_auto_build:
	SLEPC_DIR=$(SLEPC_DIR)  PETSC_DIR=$(PETSC_DIR)  dh_auto_build
	# slepc4py embeds the deep PETSC_DIR path as RPATH in its library.
	# Swap it out for a standard path, or else dh_shlibsdep gets confused
	chrpath -d build/lib.*-*/slepc4py/lib/SLEPc.so

override_dh_auto_install:
	SLEPC_DIR=$(SLEPC_DIR)  PETSC_DIR=$(PETSC_DIR)  dh_auto_install

override_dh_python2:
	dh_python2
	dh_numpy

override_dh_compress:
	dh_compress -Xpdf

override_dh_gencontrol:
	dh_gencontrol -- -Vpetsc4py:Depends="python-petsc4py (>= $(SLEPC_BASE_VERSION)), python-petsc4py (<< $(SLEPC_NEXT_VERSION))"
