#!/usr/bin/make -f


include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

DEB_DH_INSTALL_SOURCEDIR=debian/tmp
DEB_CONFIGURE_PREFIX=/usr
DEB_CONFIGURE_SYSCONFDIR=/etc
DEB_DH_STRIP_ARGS=--dbg-package=libmissioncontrol-client0 --dbg-package=libmissioncontrol-server1
#DEB_CONFIGURE_EXTRA_FLAGS := --disable-cast-checks --enable-gtk-doc
DEB_CONFIGURE_EXTRA_FLAGS := --disable-cast-checks \
			     --disable-server \
			     --enable-gtk-doc \
			     --with-profiles-dir=/usr/share/osso-rtcom \
			     --with-accounts-dir="~/.osso/accounts"

DEB_INSTALL_DOCS_libmissioncontrol-doc := doc/reference/libmissioncontrol/html doc/reference/libmissioncontrol-server/html

CFLAGS=-Wall -Werror -g -fPIC -DNO_NEW_PRESENCE_SIGNALS
ifneq (,$(findstring coverage,$(DEB_BUILD_OPTIONS)))
       DEB_CONFIGURE_EXTRA_FLAGS += --enable-coverage
endif
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
# Use soft-float and thumb mode if it enabled.
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
       CFLAGS += -mthumb
endif
CXXFLAGS=$(CFLAGS)

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
DEB_MAKE_ENVVARS := MAKEFLAGS=$(NJOBS)

ifneq (,$(findstring coverage,$(DEB_BUILD_OPTIONS)))
configure/libmissioncontrol-client0::
	sed -e "s/CC -shared/CC -fprofile-arcs -ftest-coverage -shared/g" libtool > libtool.patched
	mv libtool.patched libtool
endif

debian/stamp-autotools-files:
	gtkdocize
	autoreconf -v --install
	touch debian/stamp-autotools-files

#install/libmissioncontrol-client0::
#	mkdir -p $(DEB_DH_INSTALL_SOURCEDIR)/usr/share/doc/libmissioncontrol/libmissioncontrol
#	mkdir -p $(DEB_DH_INSTALL_SOURCEDIR)/usr/share/doc/libmissioncontrol/libmissioncontrol-server
#	install doc/reference/libmissioncontrol/html/* $(DEB_DH_INSTALL_SOURCEDIR)/usr/share/doc/libmissioncontrol/libmissioncontrol
#	install doc/reference/libmissioncontrol-server/html/* $(DEB_DH_INSTALL_SOURCEDIR)/usr/share/doc/libmissioncontrol/libmissioncontrol-server
#	install doc/mc-dbus-iface.html $(DEB_DH_INSTALL_SOURCEDIR)/usr/share/doc/libmissioncontrol/
