#!/usr/bin/make -f

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

# DEB_MAKE_CHECK_TARGET=check

DEB_DH_INSTALL_SOURCEDIR=debian/tmp
DEB_DESTDIR=$(CURDIR)/debian/tmp

DEB_DH_STRIP_ARGS=--dbg-package=librtcom-eventlogger1-async --dbg-package=rtcom-eventlogger-async

ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	DEB_CONFIGURE_EXTRA_FLAGS+=--enable-debug
endif

ifneq (,$(findstring cast-checks,$(DEB_BUILD_OPTIONS)))
	SBOX_USE_CCACHE := no
	DEB_CONFIGURE_EXTRA_FLAGS+=--disable-coverage
endif

ifneq (,$(findstring asserts,$(DEB_BUILD_OPTIONS)))
	SBOX_USE_CCACHE := no
	DEB_CONFIGURE_EXTRA_FLAGS+=--disable-asserts
endif

ifneq (,$(findstring checks,$(DEB_BUILD_OPTIONS)))
	SBOX_USE_CCACHE := no
	DEB_CONFIGURE_EXTRA_FLAGS+=--disable-checks
endif

# Disable cast checks
ifeq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
    CFLAGS += -DG_DISABLE_CAST_CHECKS
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
DEB_MAKE_ENVVARS := MAKEFLAGS=$(NJOBS)

makebuilddir/librtcom-eventlogger1-async::
	ACLOCAL=aclocal-1.9 AUTOMAKE=automake-1.9 ./autogen.sh
