#!/usr/bin/make -f

SHLIBS_VERSION = "libetpan13 (>= 0.55-1)"

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

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
       CFLAGS += -O0
else
       CFLAGS += -O2
endif

config: config-stamp
config-stamp: patch-stamp
	dh_testdir
	# Patches could touch autotools-related files.
	# Ensure that 'config.h.in' and 'configure' are more recent than
	# 'configure.in', to avoid attempts to run autotools at build time
	sleep 1
	touch config.h.in configure
	CFLAGS="$(CFLAGS)" ./configure \
	  --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
	  --prefix=/usr 
	# HACK to avoid rpath in library
	sed 's/^hardcode_into_libs=yes$$/hardcode_into_libs=no/' < libtool > libtool.tmp
	rm -f libtool && mv libtool.tmp libtool && chmod 755 libtool
	# End HACK
	touch config-stamp

build: build-stamp
build-stamp: config-stamp
	dh_testdir
	$(MAKE)
	touch build-stamp

install: install-stamp
install-stamp: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) install prefix=$(CURDIR)/debian/tmp/usr
	touch install-stamp

binary: binary-arch

binary-arch: build-stamp install-stamp
	dh_testdir
	dh_testroot
	dh_installchangelogs -plibetpan13 ChangeLog
	dh_movefiles -a
	dh_installman -a
	dh_link -a
	dh_strip -a --dbg-package=libetpan-dbg
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -plibetpan13 -V$(SHLIBS_VERSION)
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

clean:
	dh_testdir
	dh_testroot
	rm -f config-stamp build-stamp install-stamp
	-$(MAKE) distclean
	debian/rules unpatch
	dh_clean

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

include /usr/share/dpatch/dpatch.make
