#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Copied from ubuntu gmime. Commented out lines related with mono and cli

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

# Mono braindeadness?
#export MONO_SHARED_DIR=$(CURDIR)

# shared library versions, option 1
#version=0.4.0
#major=0
# option 2, assuming the library is created as src/.libs/libfoo.so.2.0.5 or so
version=`ls .libs/lib*.so.* | \
 awk '{if (match($$0,/[0-9]+\.[0-9]+\.[0-9]+$$/)) print substr($$0,RSTART)}'`
major=`ls .libs/lib*.so.* | \
 awk '{if (match($$0,/\.so\.[0-9]+$$/)) print substr($$0,RSTART+4)}'`

# Taken from gtk-sharp2-unstable debian/rules
#UPVERSION = $(shell dpkg-parsechangelog | grep ^Vers | cut -d\  -f2 | sed 's,-.*,,')
#NEXT_UPVERSION = $(shell perl -e '$$_=pop; s/(\d+)$$/$$1+1/e; print' $(UPVERSION))

#include /usr/share/dpatch/dpatch.make

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

ifeq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -DG_DISABLE_CAST_CHECKS
endif

configure: configure-stamp
configure-stamp: #patch
	dh_testdir
	
	CFLAGS="$(CFLAGS)" ./configure --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --disable-rpath
	# --disable-gtk-doc

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE)

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) -C docs/reference maintainer-clean-local
	-$(MAKE) distclean
	rm -rf .wapi libgmime gmime.h libgmime.spec

	dh_clean
	rm -rf debian/patched

	# autotools-dev stuff
	cp /usr/share/misc/config.guess config.guess
	cp /usr/share/misc/config.sub config.sub

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install DESTDIR="$(CURDIR)/debian/tmp"


binary-indep: build install
	dh_testdir
	dh_testroot
	# move files to where they supposedly belong
	dh_install -i --sourcedir=debian/tmp
#	chmod 644 debian/libgmime2.2-cil/usr/lib/cli/gmime-sharp-2.2/gmime-sharp.dll

	dh_installdocs -i
	dh_installman -i
	dh_installinfo -i
	dh_installchangelogs -i ChangeLog
	dh_link -i
	dh_strip -i
	dh_compress -i
	dh_fixperms -i
	dh_makeshlibs -i
#	dh_makeclilibs -plibgmime2.2-cil -m $(UPVERSION)
#	dh_installcligac -plibgmime2.2-cil
	dh_installdeb -i
	dh_shlibdeps -i
#	dh_clideps -d -plibgmime2.2-cil
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir
	dh_testroot
	# move files to where they supposedly belong
	dh_install -s --sourcedir=debian/tmp
	rm -f debian/libgmime-2.0-2-dev/usr/bin/uu{decode,encode}

	dh_installdocs -s
	dh_installman -s
	dh_installinfo -s
	dh_installchangelogs -s ChangeLog
	dh_link -s
	dh_strip -s
	dh_compress -s
	dh_fixperms -s
	dh_makeshlibs -s
	dh_installdeb -s
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s

binary: binary-arch 
#binary-indep
.PHONY: build clean binary-indep binary-arch binary install configure patch unpatch
