#!/usr/bin/make -f

# note: see 
# - http://perso.duckcorp.org/duck/cdbs-doc/cdbs-doc.xhtml

DEB_CONFIGURE_SCRIPT_ENV += LDFLAGS="-Wl,-z,defs,--as-needed"
DEB_DH_INSTALL_SOURCEDIR=debian/tmp


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

DEB_DH_STRIP_ARGS := --dbg-package=libsofia-sip-ua0 --dbg-package=libsofia-sip-ua-glib3 --dbg-package=libsofia-tools0 --dbg-package=sofia-sip-bin
ifeq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
       DEB_INSTALL_DOCS_sofia-sip-doc := libsofia-sip-ua/docs/html
endif

DEB_CONFIGURE_PREFIX=/usr
DEB_CONFIGURE_SYSCONFDIR=/etc
DEB_CONFIGURE_EXTRA_FLAGS = --disable-stun --disable-nth

DEB_AUTO_UPDATE_AUTOCONF=2.50
DEB_AUTO_UPDATE_AUTOHEADER=2.50
DEB_AUTO_UPDATE_ACLOCAL=1.9
DEB_AUTO_UPDATE_AUTOMAKE=1.9
# DEB_AUTO_UPDATE_LIBTOOL=pre

# do not include the changelog (takes too much space
# in the runtime packages)
DEB_INSTALL_CHANGELOGS_ALL=

# Use soft-float and thumb mode if it enabled.
ifneq (,$(findstring thumb,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -mthumb
	CXXFLAGS += -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)

pre-build:: aclocal.m4
aclocal.m4:
	autoreconf$(DEB_AUTO_UPDATE_AUTOCONF) -i

build/sofia-sip-doc:: debian/stamp-doxygen

debian/stamp-doxygen:
ifeq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
	+$(DEB_MAKE_INVOKE) doxygen
	touch $@
endif

clean::
	rm -f debian/stamp-doxygen

cleanbuilddir/sofia-sip-bin::
	rm -f libsofia-sip-ua/nta/nta_tag_ref.c
	rm -f libsofia-sip-ua/soa/soa_tag_ref.c
	rm -f libsofia-sip-ua/nua/nua_tag_ref.c

# XXX: doesn't work :( -> see the DEB_INSTALL_CHANGELOGS_ALL hack above
#binary-post-install/libsofia-tools0::
#	rm -vf debian/libsofia-tools0/usr/share/doc/libsofia-tools0/changelog.gz
