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

# 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)

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

%:
	dh --with quilt,python2,autotools_dev --parallel $@

# Remember to update README.Debian as well...
override_dh_auto_configure:
	EKG2_NO_COLOR_CONFIGURE=1 ./configure \
		--host=$(DEB_HOST_GNU_TYPE) \
		--build=$(DEB_BUILD_GNU_TYPE) \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--libexecdir=\$${prefix}/lib/ekg2 \
		--with-ioctld \
		--with-libgadu \
		--with-pthread \
		--with-openssl \
		--with-libgnutls \
		--with-expat \
		--with-ncurses \
		--with-gtk \
		--without-libgsm \
		--with-perl \
		--with-python \
		--with-libxosd \
		--with-sqlite3 \
		--without-logsoracle \
		--with-aspell \
		--without-libjpeg \
		--without-libungif \
		--without-libgif \
		--with-gpm-mouse \
		--with-gpg \
		--with-zlib \
		--without-readline \
		--enable-remote \
		--enable-unicode \
		--enable-skip-relative-plugins-dir
# 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
	cp docs/ekg2-remote.en.1 docs/ekg2-remote.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
	if [ -e Makefile ] ; then $(MAKE) distclean ; fi
	rm -f docs/ekg2.1 docs/ekg2-remote.1

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

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

override_dh_installdocs:
	dh_installdocs --link-doc=ekg2-core -pekg2 -pekg2-dbg -pekg2-gnupg -pekg2-jabber \
	  -pekg2-scripting-python -pekg2-scripting-perl -pekg2-xosd
	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
