#!/usr/bin/make -f

DEB_PYTHON_SYSTEM=pysupport

include /usr/share/cdbs/1/rules/debhelper.mk

# Variables for the get-orig-source rule
VERSION=$(shell dpkg-parsechangelog | sed -n -e'/^ / { s/.*(\(.*\)).*/\1/; s/-[^-]*$$//; p; q }')
BTMPDIR=/tmp/pyclamd-pkg-source
STMPDIR=$(BTMPDIR)/pyclamd-$(VERSION)

install/python-pyclamd::
	dh_install pyclamd.py /usr/share/python-support/python-pyclamd/
	#dh_installchangelogs CHANGELOG

binary-install/python-pyclamd::
	dh_pysupport -ppython-pyclamd

clean::
	rm -f pyclamd.pyc
	rm -rf $(BTMPDIR)

get-orig-source:
	rm -rf $(BTMPDIR); mkdir -p $(STMPDIR)
	wget --quiet -O $(BTMPDIR)/pyclamd.py http://xael.org/norman/python/pyclamd/pyclamd.py
	unexpand --first-only --tabs=4 $(BTMPDIR)/pyclamd.py > $(STMPDIR)/pyclamd.py
	sed -i "s/#!\/usr\/bin\/env python//g" $(STMPDIR)/pyclamd.py
	sed -i "s/\/var\/run\/clamd/\/var\/run\/clamav\/clamd.ctl/g" $(STMPDIR)/pyclamd.py
	#wget --quiet -O $(BTMPDIR)/CHANGELOG http://xael.org/norman/python/pyclamd/CHANGELOG
	#grep -A99999 "CHANGELOG" $(BTMPDIR)/CHANGELOG > $(STMPDIR)/CHANGELOG
	if grep -qs 'GNU Lesser General Public License' $(STMPDIR)/pyclamd.py; then \
		cp /usr/share/common-licenses/LGPL-3 $(STMPDIR)/COPYING.LGPL; \
		cp /usr/share/common-licenses/GPL-3 $(STMPDIR)/COPYING; \
	else \
		echo "Possible licence change detected, aborting...";\
		rm -rf $(BTMPDIR);\
		exit 1;\
	fi
	cd $(BTMPDIR); tar -czvf $(CURDIR)/../pyclamd_$(VERSION).orig.tar.gz pyclamd-$(VERSION)
	rm -r $(BTMPDIR)
	# Tarball generated successfully.
