#!/usr/bin/make -f
# -*- makefile -*-

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CPPFLAGS_MAINT_APPEND  = -DMAKE_WITH_IGNORE_SIGPIPE

override_dh_auto_configure:
	./autogen.sh \
	--prefix=/usr --bindir=/usr/sbin --libdir=/usr/lib/ntop \
	--sysconfdir=/usr/share --localstatedir=/var/lib \
	--without-ssl \
	$(shell dpkg-buildflags --export=configure) 


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 $@ --with autotools_dev

DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([0-9]+:)?([^+]+).*,\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)
