#!/usr/bin/make -f

# DH_VERBOSE := 1
include /usr/share/dpkg/architecture.mk
export LC_ALL=C.UTF-8

export INCLUDE=/usr/include
export LIB=/usr/lib/$(DEB_HOST_MULTIARCH)

# Even though these are passed directly to cmake (for ccs) in dh_auto_configure,
# they also need to be environment variables for setup.py to work.
export pbcopper_INCLUDE_DIRS=$(INCLUDE)
export pbcopper_LIBRARIES=$(LIB)/libpbcopper.a

export PYBUILD_NAME=consensuscore2
# Don't let pybuild consider using cmake
export PYBUILD_SYSTEM=distutils

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

docs = $(addprefix doc/,\
 JULIET.html \
 PBCCS.html \
)

binary-arch: $(docs)
%:
	dh $@ \
	--package=unanimity \
	--no-package=python-consensuscore2 \
	--buildsystem=cmake \
	--builddirectory=build
	dh $@ \
	--package=python-consensuscore2 \
	--no-package=unanimity \
	--with python2 \
	--buildsystem=pybuild

# We only want to run the configure step once. If we do not do this,
# cmake attempts to run (from the second dh invocation) in the pybuild
# build directory (which cannot be changed; pybuild ignores --builddirectory)
# and fails.
override_dh_auto_configure: config-main;

config-main:
	dh_auto_configure -- \
	-DCMAKE_EXE_LINKER_FLAGS=-pthread \
	-DUNY_build_tests=OFF \
	-DPYTHON_SWIG=ON \
	-DZLIB_INCLUDE_DIRS=$(INCLUDE) \
	-DBoost_INCLUDE_DIRS=$(INCLUDE) \
	-DPacBioBAM_INCLUDE_DIRS=$(INCLUDE) \
	-DPacBioBAM_LIBRARIES=$(LIB)/libpbbam.so \
	-DSEQAN_INCLUDE_DIRS=$(INCLUDE) \
	-Dpbcopper_INCLUDE_DIRS=$(pbcopper_INCLUDE_DIRS) \
	-Dpbcopper_LIBRARIES=$(pbcopper_LIBRARIES)
	touch $@

override_dh_python2:
	dh_python2
	dh_numpy

override_dh_auto_clean:
	dh_auto_clean
	$(RM) config-main
	$(RM) $(docs)

%.html: %.md
	pandoc --standalone --from markdown --to html $< -o $@
