#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed -Wl,-z,defs
export DEB_CFLAGS_MAINT_APPEND := -Wall
export DEB_CXXFLAGS_MAINT_APPEND := -Wall
export DEB_BUILD_MAINT_OPTIONS := hardening=+all
# Default python version.
PYTHONDEFVERSION := $(shell py3versions -d | sed -e 's/python\([0-9.]\+\)/\1/')

include /usr/share/dpkg/pkg-info.mk

# Upstream version can be overriden so as to fetch newer revisions
# without having to modify the top-most changelog entry
UVERSION ?= $(subst +dfsg,,$(DEB_VERSION_UPSTREAM))

override_dh_makeshlibs:
	dh_makeshlibs --noscripts

override_dh_auto_install:
	dh_auto_install --verbose
	rm -vf debian/tmp/usr/share/hugin/xrc/data/help_en_EN/LICENCE.manual

	find debian/tmp/usr/share/hugin/data/plugins \
		debian/tmp/usr/share/hugin/data/plugins-templates \
		-name '*.py' -exec \
		sed -i -e 's:^#! */usr/bin/env python$$:#! /usr/bin/python3:' \
		{} +
	rm -v debian/tmp/usr/share/hugin/xrc/data/COPYING.txt

override_dh_auto_configure:
	dh_auto_configure --verbose --\
		-DUSE_GDKBACKEND_X11=on \
		-DBUILD_HSI:BOOL=ON \
		-DPython_ADDITIONAL_VERSIONS=$(PYTHONDEFVERSION)

override_dh_python3:
	dh_python3 -i /usr/share/hugin/data/plugins
	dh_python3 -a

%:
	dh $@ --with python3