#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

override_dh_auto_configure:
	./autogen.sh CFLAGS=-DMAKE_WITH_IGNORE_SIGPIPE \
	--prefix=/usr --bindir=/usr/sbin --libdir=/usr/lib/ntop \
	--sysconfdir=/usr/share --localstatedir=/var/lib


override_dh_auto_install:
	dh_auto_install
	chmod -x $(CURDIR)/debian/tmp/usr/share/ntop/python/templates/rrdAlarmStart.tmpl
	find $(CURDIR)/debian/tmp/usr/share/ntop/html -type f -exec chmod -x '{}' \;

	mkdir -p $(CURDIR)/debian/tmp/etc/ntop
	cp debian/protocol.list $(CURDIR)/debian/tmp/etc/ntop
	gunzip $(CURDIR)/debian/tmp/usr/share/ntop/*.gz

	#logcheck
	mkdir -p $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.server
	mkdir -p $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.workstation
	mkdir -p $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.paranoid
	cp debian/logcheck $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.server/ntop
	cp debian/logcheck $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.workstation/ntop
	cp debian/logcheck.paranoid $(CURDIR)/debian/tmp/etc/logcheck/ignore.d.paranoid/ntop

	#logrotate
	mkdir -p $(CURDIR)/debian/tmp/etc/logrotate.d
	cp debian/logrotate $(CURDIR)/debian/tmp/etc/logrotate.d/ntop

	# remove development files
	find $(CURDIR)/debian/tmp/usr/lib -name "*.a" -exec rm '{}' \;
	find $(CURDIR)/debian/tmp/usr/lib -name "*.la" -exec rm '{}' \;
	find $(CURDIR)/debian/tmp/usr/lib -name "lib*Plugin*.so" -exec rm '{}' \;

	# link to GeoIP databases
	ln -s /usr/share/GeoIP/GeoLiteCity.dat $(CURDIR)/debian/tmp/usr/share/ntop/GeoLiteCity.dat
	ln -s /usr/share/GeoIP/GeoIPASNum.dat $(CURDIR)/debian/tmp/usr/share/ntop/GeoIPASNum.dat

# avoid useless call to ldconfig for private libraries (see bug #205142)
override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/ntop

override_dh_strip:
	        dh_strip --dbg-package=ntop-dbg

override_dh_auto_clean:
	dh_auto_clean
	./autogen.sh -p || true
	rm -f etter.finger.os.gz \
		oui.txt.gz \
		specialMAC.txt.gz \
		version.c \
		faq.html \
		html/faq.html
	rm -fr m4
	debconf-updatepo

%:
	dh $@

DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]+:)?(.*)\+ndpi[0-9]+\+dfsg.*,\2,p')
DEB_DFSG_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]+:)?(.*\+dfsg[0-9]+).*,\2,p')
NDPI_REV=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]+:)?.*\+ndpi([0-9]+)\+dfsg.*,\2,p')

get-orig-source:
	sh debian/get-orig-source.sh $(DEB_UPSTREAM_VERSION) $(DEB_DFSG_VERSION) $(NDPI_REV)
