#!/usr/bin/make -f
DH_VERBOSE = 1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

TIME_VER=$(shell dpkg-parsechangelog --show-field Version | cut -d. -f 4 | cut -d- -f 1)

ORIG_TIME_VER=date \+\.%Y%m%d
NEW_TIME_VER=echo .${TIME_VER}

export V=1
export NOCONFIGURE=yes # for ./autogen.sh

%:
	dh $@ --with autoreconf,python2

override_dh_autoreconf:
	# Upstream uses current timestamp as part of version string, so we need
	# to change it to actual version string here.
	perl -pi -e 's/${ORIG_TIME_VER}/${NEW_TIME_VER}/' configure.ac
	dh_autoreconf $(CURDIR)/autogen.sh

override_dh_auto_configure:
	dh_auto_configure -- --libexecdir=/usr/lib/ibus

override_dh_clean:
	perl -pi -e 's/${NEW_TIME_VER}/${ORIG_TIME_VER}/' configure.ac
	dh_clean

override_dh_strip:
	dh_strip --dbg-package=ibus-libzhuyin-dbg

override_dh_auto_install:
	dh_auto_install
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/ibus-libzhuyin/COPYING
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/ibus-libzhuyin/INSTALL
	rm -f $(CURDIR)/debian/tmp/usr/share/doc/ibus-libzhuyin/NEWS

override_dh_install:
	dh_install --fail-missing \
		$(NULL)
