#!/usr/bin/make -f

%:
	dh $@ --with autoreconf

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

override_dh_strip:
	dh_strip --dbg-package=libndpi-dbg


# 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')
SVN_REVISION := $(shell echo $(SRC_VERSION) | cut -d + -f 2 | sed 's/svn//' )
UPSTREAM_VERSION := $(shell echo $(SRC_VERSION) | cut -d + -f 1)
TARBALL = $(PACKAGE)_$(SRC_VERSION).orig.tar.gz
UPSTREAM_SVN_REPO = https://svn.ntop.org/svn/ntop/trunk/nDPI/

get-orig-source:
	@echo DEB_UPSTREAM_VERSION $(DEB_UPSTREAM_VERSION)
	@echo SRC_VERSION $(SRC_VERSION)
	@echo SVN_REVISION $(SVN_REVISION)
	@echo UPSTREAM_VERSION $(UPSTREAM_VERSION)
ifeq ($(findstring svn,$(SRC_VERSION)),)
	# Download and use upstream vanilla tarball
	uscan --verbose --force-download --download-version $(UPSTREAM_VERSION)
else
	rm -rf get-orig-source ../$(TARBALL)
	mkdir get-orig-source
	svn export -r $(SVN_REVISION) $(UPSTREAM_SVN_REPO) get-orig-source/$(PACKAGE)-$(SRC_VERSION)
	# Remove binaries without source.
	rm -fr get-orig-source/$(PACKAGE)-$(SRC_VERSION)/docs/nDPI_QuickStartGuide.p*
	rm -fr get-orig-source/$(PACKAGE)-$(SRC_VERSION)/example/third-party/json-c
	GZIP='--best --no-name' tar czf ../$(TARBALL) -C get-orig-source $(PACKAGE)-$(SRC_VERSION)
	rm -rf get-orig-source
endif

.PHONY: override_dh_auto_configure override_dh_strip get-orig-source
