#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

PYTHON_MODULES=ivr conf_auth mailbox pin_collect

EXCLUDED_MODULES=gateway mp3 twit

EXCLUDED_DSM_MODULES=mod_aws
EXCLUDED_DSM_PY_MODULES=mod_aws mod_py

CPPFLAGS += -DHAVE_XMLRPCPP_SSL

export USE_SPANDSP=yes LONG_DEBUG_MESSAGE=yes CPPFLAGS="$(CPPFLAGS)"

export APP_NAME=ngcp-sems
export SYSTEM_SAMPLECLOCK_RATE=48000LL
export USE_THREADPOOL=yes

# Enable parallel builds for overrides.
NUMJOBS = 1
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  MAKEFLAGS += -j$(NUMJOBS)
endif

%:
	dh $@

override_dh_auto_build:
	$(MAKE) \
	cfg_target=/etc/$(APP_NAME)/ prefix=/usr \
	exclude_app_modules="$(EXCLUDED_MODULES)" \
	exclude_dsm_modules="$(EXCLUDED_DSM_MODULES)" \
	DESTDIR=$(CURDIR)/debian/$(APP_NAME)

override_dh_auto_install:
	$(MAKE) -C core/ install \
		DESTDIR=$(CURDIR)/debian/$(APP_NAME) \
		prefix=/usr \
		cfg_target=/etc/$(APP_NAME)/

	$(MAKE) -C apps/ install \
		exclude_app_modules="$(EXCLUDED_MODULES) $(PYTHON_MODULES)" \
		exclude_dsm_modules="$(EXCLUDED_DSM_PY_MODULES)" \
		DESTDIR=$(CURDIR)/debian/$(APP_NAME) \
		prefix=/usr \
		cfg_target=/etc/$(APP_NAME)/

	dh_python2
	dh_python2 /usr/lib/$(APP_NAME)

override_dh_strip:
	dh_strip --dbgsym-migration='$(APP_NAME)-dbg (<= 1:1.6.0-1+0~mr6.0.0.0)'
	# MT#7431 those binaries aren't automatically stripped
	test -r $(CURDIR)/debian/ngcp-sems-libsems1-dev/usr/include/sems/compat/getarch && \
	  strip --remove-section=.comment --remove-section=.note --strip-unneeded \
	  $(CURDIR)/debian/ngcp-sems-libsems1-dev/usr/include/sems/compat/getarch
	test -r $(CURDIR)/debian/ngcp-sems-libsems1-dev/usr/include/sems/compat/getos && \
	  strip --remove-section=.comment --remove-section=.note --strip-unneeded \
	  $(CURDIR)/debian/ngcp-sems-libsems1-dev/usr/include/sems/compat/getos

override_dh_dwz:
	# Disable, as dwz cannot cope with the generated binaries.
