#!/usr/bin/make -f

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

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --with-system-json-c --enable-examples-dynamic-linking

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


# Adapted from http://wiki.debian.org/SandroTosi/Svn_get-orig-source
DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog \
		     | sed -rne 's/^Version: ([^-]+).*/\1/p')
PACKAGE = ndpi
SRC_VERSION := $(shell dpkg-parsechangelog | sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')
GIT_COMMIT := $(shell echo $(SRC_VERSION) | grep -E -o '[~+]git[0-9]+\..*' | cut -d . -f 2 )
TARBALL = $(PACKAGE)_$(SRC_VERSION).orig.tar.gz
UPSTREAM_GIT_REPO = https://github.com/ntop/nDPI

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

.PHONY: override_dh_auto_configure override_dh_strip get-orig-source
