#!/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_DESTDIR=$(CURDIR)/debian/tmp
DEB_DH_MAKESHLIBS_ARGS := --exclude=plugin --exclude=applet --exclude=glade

ifeq (,$(findstring nolauncher,$(DEB_BUILD_OPTIONS)))
	DEB_CONFIGURE_EXTRA_FLAGS += --enable-maemo-launcher
endif
ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	DEB_CONFIGURE_EXTRA_FLAGS += --enable-debug
else
	DEB_CONFIGURE_EXTRA_FLAGS += --disable-cast-checks
endif
ifneq (,$(findstring coverage,$(DEB_BUILD_OPTIONS)))
	SBOX_USE_CCACHE := no
	DEB_CONFIGURE_EXTRA_FLAGS += --enable-coverage
endif
# do not generate docs if gcov is enabled
ifeq (,$(findstring coverage,$(DEB_BUILD_OPTIONS)))
	DEB_CONFIGURE_EXTRA_FLAGS += --enable-gtk-doc
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)

debian/stamp-autotools-files:
	autoreconf -v --install
	intltoolize --copy --force --automake
	touch debian/stamp-autotools-files

binary-predeb/tweakr::
	# set the Setuid bit
	chmod 4755 $(CURDIR)/debian/tweakr/usr/bin/tweakr-desktop-save
	chmod 4755 $(CURDIR)/debian/tweakr/usr/bin/tweakr-mce-save
