#!/usr/bin/make -f

DH_OPTIONS = -O--builddir=build

# optimize linking
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1

# TODO: disallow undefined symbols
#export DEB_LDFLAGS_MAINT_APPEND += -Wl,-z,defs

# link only when needed
export DEB_LDFLAGS_MAINT_APPEND += -Wl,--as-needed

override_dh_auto_configure:
	dh_auto_configure --builddir=build-python2 -- --with-python2
	dh_auto_configure -- --with-python3

override_dh_auto_make:
	dh_auto_make --builddir=build-python2
	dh_auto_make

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install --builddir=build-python2
	dh_auto_install

override_dh_install-arch:
	dh_install
# Let d-shlibs calculate development package dependencies
#  and handle shared library install
	d-shlibmove --commit \
		--multiarch \
		--exclude-la --exclude-a \
		--devunversioned --ignorelibdep \
		--movedev debian/tmp/usr/share/gir-1.0 usr/share/ \
		--extralib debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libsugar-eventcontroller.so \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libsugarext.so
# Ensure proper hash-bang in Python script (Python Policy 0.9 §3.1)
	perl -pi -e 's,^#! ?/usr/bin/(env )?python[[:print:]]*$$,#!/usr/bin/python2,' \
		debian/*/usr/bin/sugar-activity
	perl -pi -e 's,^#! ?/usr/bin/(env )?python[[:print:]]*$$,#!/usr/bin/python3,' \
		debian/*/usr/bin/sugar-activity3

override_dh_install-indep:
	dh_install --indep
# Drop virtually empty translations
# see <https://github.com/sugarlabs/sugar-toolkit-gtk3/issues/429>
	find debian/*/usr/share/locale -type f -name '*.mo' -size -440c -delete
# Drop created dir if empty to please lintian
	find debian/*/usr/share/locale -empty -type d -delete

override_dh_installdocs:
	dh_installdocs --all -- AUTHORS

override_dh_strip:
	dh_strip --dbgsym-migration='libsugarext-dbg (<< 0.116-5~)'

%:
	dh $@ --with gir,python2,python3 $(DH_OPTIONS:-O%=%)
