#!/usr/bin/make -f

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8

include /usr/share/dpkg/default.mk

# for hardening you might like to uncomment this:
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --with python3,sphinxdoc

override_dh_auto_configure:
	dh_auto_configure -- -DBUILD_ID=${DEB_VERSION_UPSTREAM}

override_dh_auto_build: export http_proxy=127.0.0.1:9
override_dh_auto_build: export https_proxy=127.0.0.1:9
override_dh_auto_build:
	dh_auto_build
	# Move shared library into sphinx documentation folder for doc generation
	find . -name "shasta.so" -exec cp {} docs/PythonApi/ \;
	PYTHONPATH=docs/PythonApi/ python3 -m sphinx -N -bhtml docs/PythonApi/ build/html # HTML generator

override_dh_install:
	dh_install
	# Rename shastaDynamic to shasta for ease
	mv debian/shasta/usr/bin/shastaDynamic debian/shasta/usr/bin/shasta
	# The library is in a more unusual place (nested within /usr/lib), so modify
	# the ELF
	chrpath -d debian/shasta/usr/bin/shasta
	patchelf --replace-needed shasta.so /usr/lib/python3/dist-packages/shasta.cpython-38-${DEB_HOST_MULTIARCH}.so \
		debian/shasta/usr/bin/shasta

override_dh_shlibdeps:
	# With the library being installed in an unusual place, and -l not having an effect,
	# simply exclude shasta binary from this
	dh_shlibdeps -Xdebian/shasta/usr/bin/shasta

override_dh_missing:
