#!/usr/bin/make -f

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

export PYBUILD_NAME=pycbf

# CBFlib makefile configuration vars
export INSTALL_LIB := lib/$(DEB_HOST_MULTIARCH)
export CBFLIB_DONT_USE_LOCAL_HDF5=yes
export CBFLIB_DONT_USE_LOCAL_REGEX=yes
export CBFLIB_DONT_USE_LOCAL_TIFF=yes
export CBFLIB_DONT_USE_LZ4=yes
export CBFLIB_DONT_USE_BSHUF=yes
export CBFLIB_DONT_USE_PYCIFRW=yes
export NOPYCBF=yes
export NOLIBIMG=yes
export NOFORTRAN=yes


create_setup.py=$(MAKE) 'C++:=$$(CXX)' $(CURDIR)/pycbf/setup.py

# Parallel builds do not work
%:
	dh $@ --no-parallel

override_dh_auto_clean:
	dh_auto_clean

	$(create_setup.py)
	dh_auto_clean --buildsystem=pybuild --sourcedirectory=pycbf
	rm -f pycbf/setup.py

override_dh_auto_configure:
	dh_auto_configure

	$(create_setup.py)
	dh_auto_configure --buildsystem=pybuild --sourcedirectory=pycbf

override_dh_auto_build:
	# build the C/C++ library
	dh_auto_build -- 'C++:=$$(CXX)' all

	# build the python extension.
	$(create_setup.py)
	dh_auto_build --buildsystem=pybuild --sourcedirectory=pycbf

# do not run test since we do not have the test data.
override_dh_auto_test:

override_dh_auto_install:
	# install the C/C++ library
	dh_auto_install

	# install the python extension
	$(create_setup.py)
	dh_auto_install --buildsystem=pybuild --sourcedirectory=pycbf

override_dh_install:
	# cbflib-bin
	dh_install -p cbflib-bin usr/bin/cbf2nexus
	dh_install -p cbflib-bin usr/bin/cif2cbf
	dh_install -p cbflib-bin usr/bin/convert_image
	dh_install -p cbflib-bin usr/bin/img2cif
	dh_install -p cbflib-bin usr/bin/makecbf

	# libcbf-dev
	dh_install -p libcbf-dev usr/include/cbflib/*
	dh_install -p libcbf-dev usr/lib/*/lib*.a
	dh_install -p libcbf-dev usr/lib/*/lib*.so

	# libcbf1
	dh_install -p libcbf1 usr/lib/*/libcbf.so.*

	# Exclude duplicates (lintian check duplicate-files)
	dh_install -Xcif_img_1.3.2_22Jun05.html -Xcif_img_1.3.1.html

override_dh_installdocs:
	# cbflib-doc
	dh_install     -p cbflib-doc doc/*.html      usr/share/doc/cbflib-doc/html
	dh_installdocs -p cbflib-doc html_graphics

	# libcbf-dev
	dh_installdocs -p libcbf-dev README

	dh_installdocs

override_dh_installman:
	dh_installman -p cbflib-bin debian/manpages/*
