#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess. 

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

#export DEB_BUILD_ARCH = i386-linux
#export DEB_BUILD_GNU_SYSTEM = i386-linux

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

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -DOSSOLOG_COMPILE
endif


# Use soft-float and thumb mode if it enabled.
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -mthumb
endif


ifneq (,$(findstring parallel,$(DEB_BUILD_OPTIONS)))
    PARALLEL_JOBS := $(shell echo $(DEB_BUILD_OPTIONS) | \
                sed -e 's/.*parallel=\([0-9]\+\).*/\1/')
    ifeq ($(DEB_BUILD_OPTIONS),$(PARALLEL_JOBS))
        PARALLEL_JOBS := $(shell if [ -f /proc/cpuinfo ]; \
	                    then echo `cat /proc/cpuinfo | grep 'processor' | wc -l`; \
			                                    else echo 1; fi)
    endif
    NJOBS := -j$(PARALLEL_JOBS)
endif


libpath=src/common/dbus/.libs:src/engine/common/.libs:src/smime/.libs

configure: configure-stamp
configure-stamp:
	$(CURDIR)/autogen.sh
	CFLAGS="$(CFLAGS)" $(CURDIR)/configure --prefix=/usr
	touch configure-stamp

build: configure build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) $(NJOBS) \
		LD_LIBRARY_PATH=$(libpath):$(LD_LIBRARY_PATH)
		

	touch build-stamp

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

	# Add here commands to clean up after the build process.
	#$(MAKE) clean
	-$(MAKE) dist-clean

	-rm -rf ${PACKAGE}

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs -a

	# Add here commands to install the package into debian/<packagename>
	#$(MAKE) prefix=debian/`dh_listpackages` install
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	dh_install --sourcedir=debian/tmp

	# Clean up some stuff
	#find $(CURDIR)/debian/tmp/usr/lib/ -type f -name '*.*a' -print0 \
	#	                                 | \xargs -0 rm -f
	                                  	
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_strip --dbg-package="libossoemailcommon" --dbg-package="libossoemaildbusutils" --dbg-package="libossoemailsmime" --dbg-package="libossoemailcl"
	dh_compress
	dh_fixperms
	dh_makeshlibs -V
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol -- $(LAUNCHER_DEPENDS)
	dh_builddeb

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