#!/usr/bin/make -f

DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

#CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
#CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS)
#CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS)
#LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

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

DEB_DH_INSTALL_ARGS := --sourcedir=debian/tmp

CPPFLAGS += -DRESIP_FIXED_POINT
# this is just temporary, reSIProcate 1.9.x should not need this:
CPPFLAGS += -I/usr/include/sipxtapi
# these are also temporary, should be implemented in reSIProcate's build system, for sipXtapi
# with librecon:
CPPFLAGS += -D__pingtel_on_posix__ -D_linux_ -D_REENTRANT -D_FILE_OFFS
CPPFLAGS += -DDEFAULT_BRIDGE_MAX_IN_OUTPUTS=20
CXXFLAGS += -fpermissive
LDFLAGS += -lcares

CFG_ARGS := --with-ssl \
		--with-mysql \
		--with-apps \
		--enable-ipv6 \
		--with-radius \
		--with-c-ares

# on kfreebsd, sipxtapi is not available and recon can't be built
# upstream hopes to eliminate the dependency on sipxtapi in a future release
# so there is no attempt to port sipxtapi
# on sparc, libsrtp is not available (fails with a bus error during test cases)
ifeq ($(DEB_HOST_ARCH_OS),linux)
CFG_ARGS += --with-recon
endif

override_dh_auto_configure:
	dh_auto_configure -- $(CFG_ARGS)
ifneq ($(DEB_HOST_ARCH_CPU),amd64)
ifneq ($(DEB_HOST_ARCH_CPU),i386)
	echo "all:" > resip/recon/test/Makefile
	echo "install:" >> resip/recon/test/Makefile
	echo "check:" >> resip/recon/test/Makefile
endif
endif
# FIXME - make all of the above build properly on all platforms
# recon tests fail,
# - requires audio hardware (fixed upstream after 1.8.11)
# - pure virtual method issue in sipXtapi dependency on some
#   platforms (see bug #718854)

override_dh_auto_build:
	dh_auto_build --parallel

# don't actually run the test cases, they don't run well
# automatically and require network access
#override_dh_auto_test:
#	true

# force building in the pkgroot or it won't build
%:
	dh $@ --builddirectory=.

#install/repro::
#	cp debian/repro.config-sample debian/repro/etc/repro/repro.config

#install/resiprocate-turn-server::
#	cp debian/reTurnServer.config-sample debian/resiprocate-turn-server/etc/reTurnServer.config

