#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

ifeq ($(DEB_HOST_ARCH_OS),linux)
    extra_confflags += --enable-nflog
    extra_confflags += --enable-ebpf
endif

ifeq ($(DEB_HOST_ARCH_OS),linux)
ifneq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH),s390x))
    extra_confflags += --enable-ndpi
endif
endif


override_dh_auto_configure:
	export CFLAGS=-fcommon; dh_auto_configure -- \
		--with-pgsql-includes=`pg_config --includedir` \
		--enable-avro         \
		--enable-l2           \
		--enable-ipv6         \
		--enable-plabel       \
		--enable-mysql        \
		--enable-pgsql        \
		--enable-sqlite3      \
		--enable-rabbitmq     \
		--enable-zmq          \
		--enable-kafka        \
		--enable-geoipv2      \
		--enable-jansson      \
		--enable-64bit        \
		--enable-threads      \
		--enable-traffic-bins \
		--enable-bgp-bins     \
		--enable-bmp-bins     \
		--enable-st-bins      \
		$(extra_confflags)

		# does not support the current version
		# --enable-mongodb      \

override_dh_installinit:
	dh_installinit --name pmacctd --no-start
	dh_installinit --name nfacctd --no-start
	dh_installinit --name sfacctd --no-start
	dh_installinit --name uacctd --no-start

override_dh_installsystemd:
	dh_installsystemd --name pmacctd --no-start --no-enable
	dh_installsystemd --name nfacctd --no-start --no-enable
	dh_installsystemd --name sfacctd --no-start --no-enable
	dh_installsystemd --name uacctd --no-start --no-enable

execute_after_dh_auto_install:
	# Drop .la files
	rm -fv debian/*/usr/lib/*/pmacct/examples/custom/libcustom.la

%:
	dh $@
