#!/usr/bin/make -f

%:
	dh $@ --with python2

override_dh_install:
	dh_install --exclude=generateSources.sh --exclude=generateTranslations.sh \
	           --exclude=BeautifulSoup.py --exclude=httplib2 --exclude includes/js
	# install the two used JavaScript files (excluded above)
	install -d $(CURDIR)/debian/wapiti/usr/share/wapiti/report_template/includes/js
	install -D -p -m 0644 \
	  -t $(CURDIR)/debian/wapiti/usr/share/wapiti/report_template/includes/js \
	  src/report_template/includes/js/report.js
	find $(CURDIR)/debian/wapiti -type d -empty -delete

override_dh_link:
	dh_link
	chmod a+rx $(CURDIR)/debian/wapiti/usr/bin/*

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog_Wapiti

DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
                               | sed -rne 's,^Version: ([^+-]+).*,\1,p')
get-orig-source:
	# download and unpack upstream tarball
	uscan --noconf --force-download --rename --download-current-version --destdir=. $(DEB_DEBIAN_DIR)/..
	rm -rf wapiti-$(DEB_UPSTREAM_VERSION)
	tar -xf wapiti_$(DEB_UPSTREAM_VERSION).orig.tar.bz2
	rm wapiti_$(DEB_UPSTREAM_VERSION).orig.tar.bz2
	# remove non-free json.js
	rm wapiti-$(DEB_UPSTREAM_VERSION)/src/report_template/includes/js/json.js
	# create a new tarball
	GZIP=--best tar -cz --owner root --group root --mode a+rX \
	  -f wapiti_$(DEB_UPSTREAM_VERSION)+dfsg.orig.tar.gz \
	  wapiti-$(DEB_UPSTREAM_VERSION)
	rm -rf wapiti-$(DEB_UPSTREAM_VERSION)
