#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

LDFLAGS+= -Wl,--as-needed

%:
	dh $@ --with autoreconf

override_dh_auto_clean:
	dh_auto_clean
	find . -name Makefile.in -type f -delete \
	&& $(RM) aclocal.m4

override_dh_autoreconf:
	dh_autoreconf -v --as-needed
	##gnulib-tool --add-import --libtool
	intltoolize --copy --force
	aclocal -I m4

override_dh_auto_configure:
	dh_auto_configure -- \
		--prefix=/usr \
		--datadir=/usr/share \
		--mandir=/usr/share/man \
		--libdir=/usr/lib/giggle \
		--infodir=/usr/share/info \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--with-help-dir=/usr/share/help
		# note: --with-help-dir breaks (y|h)elp if it's not '/usr/share/help'

override_dh_auto_install:
	dh_auto_install --destdir=$(CURDIR)/debian/tmp

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_makeshlibs:
	dh_makeshlibs --noscripts --exclude=giggle-personal-details-plugin --exclude=giggle-terminal-view-plugin

override_dh_builddeb:
	dh_builddeb -- -Zxz

## http://wiki.debian.org/onlyjob/get-orig-source
PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
PKG  = $(word 2,$(shell dpkg-parsechangelog -l$(PKD)/changelog | grep ^Source))
VER ?= $(shell dpkg-parsechangelog -l$(PKD)/changelog | perl -ne 'print $$1 if m{Version:\s*([\d\.]+)}')
.PHONY: get-orig-source
get-orig-source:
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --check-dirname-level=0 --force-download --download-version $(VER) $(PKD)
