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

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

# parallel build by default on linux
ifeq ($(DEB_HOST_ARCH_OS),linux)
	export DEB_BUILD_OPTIONS+=parallel=$(shell grep -c ^processor /proc/cpuinfo)
endif

#: see http://lists.debian.org/debian-devel-announce/2011/09/msg00001.html
#: Also it does hardening by default, see http://wiki.debian.org/Hardening
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/default.mk
#: disabling format hardening due to build problems in some plugins
export DEB_BUILD_MAINT_OPTIONS=hardening=-format

LDFLAGS+= -Wl,--as-needed

series := 2.9
plugins := aiksaurus applix babelfish bmp clarisworks collab command docbook \
	   eml epub freetranslation garble gdict gimp google grammar hancom \
	   hrtext iscii kword latex loadbindings mathview mht mif mswrite \
	   opendocument openwriter openxml opml ots paint passepartout pdb \
	   pdf presentation s5 sdw t602 urldict wikipedia wmf wml \
	   wordperfect wpg xslfo
# goffice
# plugin 'rsvg' deliberately not used due to build problems. Is it deprecated?

%:
	dh $@ --parallel --with autoreconf

override_dh_autoreconf:
	dh_autoreconf -v --as-needed

#: Build instructions http://www.abisource.com/~fjf/BUILD.phtml
#: configure options reference: http://www.abisource.com/wiki/Compiling_AbiWord
override_dh_auto_configure:
	# clean file only if possible to regenerate
	[ ! -x "$(which flex)" ] || $(RM) plugins/mathview/itex2mml/lex.yy.c
	# arch-dependent patching
	cat debian/patches/series.$(DEB_HOST_ARCH_OS) >> debian/patches/series \
	&& $(RM) debian/patches/series.$(DEB_HOST_ARCH_OS) \
	&& dh_quilt_patch || return 0
	dh_auto_configure -- \
		--without-gnomevfs \
		--with-gio \
		--with-libtidy \
		--enable-shared \
		--enable-clipart \
		--enable-templates \
		--enable-collab-backend-tcp \
		--enable-collab-backend-xmpp \
		--enable-collab-backend-service \
		--enable-collab-backend-telepathy \
		--enable-silent-rules \
		--enable-dependency-tracking \
		--enable-plugins="$(plugins)"
## --with-goffice

override_dh_makeshlibs:
	$(RM) debian/abiword/usr/lib/abiword-$(series)/plugins/grammar.*
	$(RM) debian/abiword/usr/lib/abiword-$(series)/plugins/mathview.*
	dh_makeshlibs -V

override_dh_strip:
	dh_strip --dbg-package=abiword-dbg

get-orig-source:
	uscan --noconf --force-download --repack --rename --download-current-version --verbose --destdir=.
