#!/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_NUWEB=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_PY2CIFRW=yes
export CBFLIB_DONT_USE_PY3CIFRW=yes
export NOPYCBF=yes
export NOLIBIMG=yes
export NOFORTRAN=yes


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

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

execute_after_dh_auto_clean-arch: pycbf/setup.py
	dh_auto_clean --buildsystem=pybuild --sourcedirectory=pycbf
	rm -f pycbf/setup.py
	rm -rf pycbf/pycbf.egg-info

execute_after_dh_auto_configure-arch: pycbf/setup.py
	dh_auto_configure --buildsystem=pybuild --sourcedirectory=pycbf

override_dh_auto_build-arch: pycbf/setup.py
	# build the C/C++ library
	dh_auto_build -- 'C++:=$$(CXX)' shared all

	# build the python extension.
	dh_auto_build --buildsystem=pybuild --sourcedirectory=pycbf

override_dh_auto_build-indep:
	# nothing to build here

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

override_dh_auto_install-arch: pycbf/setup.py
	# install the C/C++ library
	dh_auto_install

	# install the python extension
	dh_auto_install --buildsystem=pybuild --sourcedirectory=pycbf

override_dh_auto_install-indep:
	# nothing to install here

override_dh_install-arch:
	# 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

	# libcbf1t64
	dh_install -p libcbf1t64 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_install-indep:
	# cbflib-doc
	dh_install     -p cbflib-doc doc/*.html      usr/share/doc/cbflib-doc/html

override_dh_installdocs:
	# cbflib-doc
	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/*
