#!/usr/bin/make -f
# ekg2 package rules file
# Copyright 2002-2011 Marcin Owsiany <porridge@debian.org>

# As recommended by "current Debian best practice" prescribed by autotools-dev, we:

# * set configure flags appropriately to help cross-compiling:
# These are set automatically by dpkg-buildpackage, but we cannot depend on
# them being available, because caller might not be using dpkg-buildpackage
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  confflags += --build $(DEB_HOST_GNU_TYPE)
else
  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

# * specify an explicit automake version
export AUTOMAKE=automake-1.11

-include /usr/share/topgit/tg2quilt.mk
/usr/share/topgit/tg2quilt.mk:

%:
	dh $@ --with autoreconf,python-central --parallel

# Remember to update README.Debian as well...
override_dh_auto_configure:
	dh_auto_configure -- \
		$(confflags) \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--libexecdir=\$${prefix}/lib/ekg2 \
		--enable-autoresponder \
		--enable-gg \
		--enable-gpg \
		--enable-gtk \
		--enable-icq \
		--enable-irc \
		--enable-jabber \
		--enable-jogger \
		--enable-logs \
		--enable-logsqlite \
		--enable-mail \
		--enable-ncurses \
		--enable-nntp \
		--enable-perl \
		--enable-polchat \
		--enable-python \
		--enable-rivchat \
		--enable-rss \
		--enable-sim \
		--enable-sms \
		--with-aspell \
		--with-expat \
		--with-gnutls \
		--with-gpgme \
		--with-gpm \
		--with-gtk \
		--with-libgadu \
		--with-ncurses \
		--with-openssl \
		--with-perl \
		--with-python \
		--with-sqlite3 \
		--with-zlib
# Reasons for disabling some features are in README.Debian
# Remember to update README.Debian as well...

override_dh_auto_build:
	@echo 'Building with MAKEFLAGS=$(MAKEFLAGS) and CFLAGS=$(CFLAGS)'
	dh_auto_build -- PERL_MM_OPT=INSTALLDIRS=vendor
	cd docs/ && XSLTRANSFORMER='xsltproc --nonet' sh generate-ekg2book.sh pl generate
	cd docs/ && XSLTRANSFORMER='xsltproc --nonet' sh generate-ekg2book.sh en generate
# dh_installman gets confused with the ".en" part and either chooses wrong directory or extension
	cp docs/ekg2.en.1 docs/ekg2.1
ifneq (,$(findstring ekg2-api-docs, $(shell dh_listpackages)))
	cd docs/ && ./generate-doc.sh
endif

override_dh_auto_clean:
	cd docs && sh generate-ekg2book.sh pl clean
	cd docs && sh generate-ekg2book.sh en clean
	rm -rf docs/doxygen
	rm -f docs/ekg2.1
	dh_auto_clean

override_dh_strip:
	dh_strip --dbg-package=ekg2-dbg

override_dh_auto_install:
	perl_install_args="DESTDIR=$(CURDIR)/debian/tmp INSTALLDIRS=vendor" $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

override_dh_installdocs:
	dh_installdocs --link-doc=ekg2-core -pekg2 -pekg2-dbg -pekg2-gnupg -pekg2-jabber \
	  -pekg2-scripting-python -pekg2-scripting-perl
	dh_installdocs --remaining-packages
	cp -a docs/ekg2book/book    $(CURDIR)/debian/ekg2-core/usr/share/doc/ekg2-core/book-pl
	cp -a docs/ekg2book-en/book $(CURDIR)/debian/ekg2-core/usr/share/doc/ekg2-core/book-en
ifneq (,$(findstring ekg2-api-docs, $(shell dh_listpackages)))
	cp -a docs/doxygen          $(CURDIR)/debian/ekg2-api-docs/usr/share/doc/ekg2-api-docs/
endif
