#!/usr/bin/make -f

#DH_VERBOSE = 1
include /usr/share/dpkg/default.mk

export HDF5_INC = /usr/include/hdf5/serial
export HDF5_LIB = /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial
export GTEST_INC = /usr/include
export GTEST_SRCDIR = /usr/src/gtest

export DEB_CFLAGS_MAINT_APPEND=-O3
export DEB_CXXFLAGS_MAINT_APPEND=-O3

export LDLIBS += -lpbbam

# Needed for patch hdf5-1.10.1-support.patch
HDF5_VERSION := $(shell grep 'HDF5 Version' $(HDF5_LIB)/libhdf5.settings | awk '{print $$3}')
ifeq (yes,$(shell dpkg --compare-versions $(HDF5_VERSION) '>=' 1.10.1 && echo yes))
export DEB_CPPFLAGS_MAINT_APPEND=-DHAVE_HDF5_1_10_1
endif

%:
	dh $@

override_dh_auto_configure:
	./configure.py PREFIX=/usr/

override_dh_auto_test:
# Ignore the return code because some tests
# require data that is not available in the source distribution.
	-$(MAKE) -k gtest

override_dh_auto_install:
	mkdir -p debian/libpbdata-dev/usr/include/pbseq
	cp -r pbdata debian/libpbdata-dev/usr/include/pbseq/
	mkdir -p debian/libpbihdf-dev/usr/include/pbseq/
	cp -r hdf debian/libpbihdf-dev/usr/include/pbseq/
	mkdir -p debian/libblasr-dev/usr/include/pbseq/
	cp -r alignment debian/libblasr-dev/usr/include/pbseq/
	find -L debian/*/usr/include/ -type f -regextype posix-egrep -not -regex '.*(hpp|h)$$' -delete
# defines.mk and build.mk files are symlinks and don't
# get removed by the previous command
	find debian/*/usr/include/ -name "*.mk" -delete
	dh_auto_install

override_dh_auto_clean:
	dh_auto_clean
	find -name defines.mk -delete
	$(RM) pbdata/libconfig.h
