#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

# Used by debian/libndpi-wireshark.install. Evaluated when referenced.
WIRESHARK_PLUGINDIR = $(shell pkg-config --variable=plugindir wireshark)

%:
	dh $@

override_dh_auto_configure:
	./autogen.sh
	dh_auto_configure -- --prefix=/usr

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# disable tests with a broken pcap file
	rm -f tests/pcap/nintendo.pcap
	rm -f tests/pcap/skype-conference-call.pcap
	# disable tests that have inconsistent behavior across architecture due
	# to broken sorting in the test code
	rm -f tests/pcap/skype.pcap
	rm -f tests/pcap/skype_no_unknown.pcap
	rm -f tests/pcap/1kxun.pcap
	cd tests && LD_LIBRARY_PATH=$(CURDIR)/src/lib ./do.sh
endif

override_dh_install:
	# Used by debian/libndpi-wireshark.install.
	WIRESHARK_PLUGINDIR=$(WIRESHARK_PLUGINDIR) dh_install

override_dh_strip:
	dh_strip --dbgsym-migration='libndpi-dbg (<< 1.8-1~)'


PACKAGE = ndpi
GIT_COMMIT := $(shell echo $(DEB_VERSION_UPSTREAM) | grep -E -o '[~+]git[0-9]+\..*' | cut -d . -f 2 )
TARBALL = $(PACKAGE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz
UPSTREAM_GIT_REPO = https://github.com/ntop/nDPI

get-orig-source:
	@echo DEB_VERSION_UPSTREAM $(DEB_VERSION_UPSTREAM)
	@echo GIT_COMMIT $(GIT_COMMIT)
ifeq ($(findstring git,$(DEB_VERSION_UPSTREAM)),)
	# Download and use upstream vanilla tarball
	uscan --verbose --force-download --download-version $(DEB_VERSION_UPSTREAM)
else
	wget $(UPSTREAM_GIT_REPO)/archive/$(GIT_COMMIT).tar.gz -O ../$(TARBALL)
endif

.PHONY: override_dh_auto_configure override_dh_strip get-orig-source
