#!/usr/bin/make -f

include $(CURDIR)/debian/update-patches.mk

STAMP_DIR := debian/stampdir

FLAVOURS := gnome maemo

builddir = $(buildbasedir)/$*
buildbasedir = $(CURDIR)/debian/build

installdir = $(installbasedir)/$*
installbasedir = $(CURDIR)/debian/install

common_configure_flags := --prefix=/usr \
	--enable-gnome \
	--disable-tp \
	--with-html-component=gtkhtml \
	--disable-rpath \
	--with-ssl=openssl \
	--enable-tests=no \
	--enable-unit-tests=no \
	--enable-demoui=no \
	--with-krb5=/usr/include

gnome_configure_flags := $(common_configure_flags) \
	--with-platform=gnome-desktop
maemo_configure_flags := $(common_configure_flags) \
	--with-platform=maemo

$(STAMP_DIR)/autogen-stamp:
	NOCONFIGURE=1 ./autogen.sh
	-mkdir -p $(STAMP_DIR)
	touch $@

$(STAMP_DIR)/configure-stamp-%: $(STAMP_DIR)/autogen-stamp
	dh_testdir
	mkdir -p $(builddir)
	cd $(builddir) && \
		$(CURDIR)/configure $($*_configure_flags)
	touch $@

$(STAMP_DIR)/build-stamp-%: $(STAMP_DIR)/configure-stamp-%
	dh_testdir
	$(MAKE) -C $(builddir)
	touch $@

build: $(addprefix $(STAMP_DIR)/build-stamp-, $(FLAVOURS))

clean:
	dh_testdir
	dh_testroot
	rm -rf $(installbasedir)
	rm -rf $(buildbasedir)
	[ ! -f Makefile ] || $(MAKE) distclean
	-rm -rf $(STAMP_DIR)
	dh_clean

$(STAMP_DIR)/install-stamp-%: $(STAMP_DIR)/build-stamp-%
	mkdir -p $(installdir)
	$(MAKE) -C $(builddir) install DESTDIR=$(installdir)
	(cd $(installdir)/usr/lib && find -name "*.la" -delete)
	touch $@

install: $(addprefix $(STAMP_DIR)/install-stamp-, $(FLAVOURS))

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs -a
	dh_installchangelogs ChangeLog
	dh_install --sourcedir=debian/install
	dh_link -a
	dh_strip -a --dbg-package=libtinymail-1.0-0-dbg
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -V -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
