#!/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
export WIRESHARK_VERSION = 2.4.3

%:
	dh $@

override_dh_auto_configure:
	cp $(CURDIR)/src/lib/third_party/include/libcache.h $(CURDIR)/src/include/
	./autogen.sh
	dh_auto_configure -- --with-system-json-c --enable-examples-dynamic-linking

override_dh_auto_test:
	for f in nintendo.pcap skype-conference-call.pcap; do \
	    if ! [ -f $(CURDIR)/tests/pcap/$$f.orig ]; then \
		cp $(CURDIR)/tests/pcap/$$f $(CURDIR)/tests/pcap/$$f.orig; \
		xdelta patch $(CURDIR)/debian/patches/$$f.xdelta $(CURDIR)/tests/pcap/$$f.orig $(CURDIR)/tests/pcap/$$f; \
	    fi; \
	done
	dh_auto_test

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
