#!/usr/bin/make -f


include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/rules/simple-patchsys.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-server6 --dbg-package=libmcclient6
#DEB_CONFIGURE_EXTRA_FLAGS := --disable-cast-checks --enable-gtk-doc
DEB_CONFIGURE_EXTRA_FLAGS := --disable-server \
			     --disable-legacy \
			     --disable-gtk-doc \
			     --enable-mcclient-so6 \
			     --enable-mcserver-so6 \
			     --with-accounts-cache-dir=/tmp \
			     --with-profiles-dir=/usr/share/osso-rtcom \
			     --with-accounts-dir="~/.rtcom-accounts" \
			     --enable-plugins

#DEB_INSTALL_DOCS_libmissioncontrol-doc := doc/reference/libmissioncontrol-server/html
#DEB_INSTALL_DOCS_libmcclient-doc := doc/reference/libmcclient/html

CFLAGS=-fPIC
ifneq (,$(findstring coverage,$(DEB_BUILD_OPTIONS)))
       DEB_CONFIGURE_EXTRA_FLAGS += --enable-coverage
endif
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0 -g
else
	CFLAGS += -O2
	DEB_CONFIGURE_EXTRA_FLAGS += --disable-cast-checks
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-client5::
	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
	ACLOCAL=aclocal-1.9 AUTOMAKE=automake-1.9 autoreconf -v --install
	touch debian/stamp-autotools-files

# As a Maemo-specific alteration, the mc-wait-for-name utility (which is needed
# in order to wait for notification-ui to appear - NB#115971) is installed in
# the libmcclient6 binary package. Accordingly, we need to rename it to
# be parallel-installable with a hypothetical future libmcclient7, so we
# embed the SONAME version in its name.
common-install-arch:: mc-rename-wait-for-name
mc-rename-wait-for-name:
	install -d $(DEB_DH_INSTALL_SOURCEDIR)/usr/lib/mission-control
	mv $(DEB_DH_INSTALL_SOURCEDIR)/usr/bin/mc-wait-for-name \
		$(DEB_DH_INSTALL_SOURCEDIR)/usr/lib/mission-control/mcclient6-wait-for-name

#install/libmissioncontrol-client5::
#	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/
