#!/usr/bin/make -f

export DH_VERBOSE=1

# dh_python3 needs DEB_HOST_ARCH, so ... sledge hammer:
include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export LIBS="pthread"
export DESTDIR=debian/tmp
export PYBUILD_NAME=cppkin

DH_FLAGS += --max-parallel=1

%:
	dh $@ --without python2 --with python3 --buildsystem=pybuild --buildsystem=cmake+ninja ${DH_FLAGS}

# ON or OFF
BUILD_TESTS=OFF

override_dh_auto_configure:
	dh_auto_configure --buildsystem=pybuild
	dh_auto_configure --buildsystem=cmake+ninja -- \
		-DBUILD_CLI_EXECUTABLES=ON \
		-DBUILD_PYTHON_BINDINGS=ON \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
		-DCORE_INCLUDE_DIR:STRING=/usr/include/libcore \
		-DCORE_LIBRARY_DIR:STRING=/usr/lib/$(shell uname -m)-$(shell uname -s | tr '[A-Z]' '[a-z]')-gnu \
		-DDEBUG=ON \
		-DDISABLE_DOWNLOADS=ON \
		-DPROFILE=OFF \
		-DPYTHON_EXECUTABLE=/usr/bin/python3 \
		-DWITH_EXAMPLES=OFF \
		-DWITH_TESTS=$(BUILD_TESTS) \
		-DPRE_COMPILE_STEP=ON \
	       	-D3RD_PARTY_INSTALL_STEP=ON \
		-DCOMPILATION_STEP=ON \
		-DCMAKE_BUILD_TYPE=Release \
	       	-DOUTPUT_DIR:STRING=\/usr \
		-DPYTHON_BINDING:STRING=pyBind \
		-DSPDLOG_INCLUDE_DIR:STRING=/usr/include/spdlog \
		-DBOTTLE_INCLUDE_DIR:STRING=/usr/lib/python3/dist-packages

override_dh_auto_build:
	dh_auto_build --buildsystem=pybuild
	dh_auto_build --buildsystem=cmake+ninja

override_dh_auto_install:
	dh_auto_install --buildsystem=pybuild
	dh_auto_install --buildsystem=cmake+ninja

ifeq ($(BUILD_TESTS),OFF)
override_dh_auto_test:
	@echo "Build time testing disabled."
endif

execute_after_dh_install:
	@echo "remove byte-compiled python files per policy"
	-find debian/python-cppkin  -name '*.pyc' -ls -delete || true
	-find debian/python3-cppkin -name '*.pyc' -ls -delete || true

override_dh_installdocs:
	dh_installdocs -plibcppkin-doc --doc-main-package libcppkin-doc
	dh_installdocs -Nlibcppkin-doc

override_dh_installexamples:
	dh_installexamples -plibcppkin-doc --doc-main-package libcppkin-doc
	dh_installexamples -Nlibcppkin-doc

execute_after_dh_installexamples:
	@echo "Search and destroy stray VCS support files"
	-find debian/libcppkin-doc -name .gitignore -ls -delete || true
