#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

SRC_TMP=$(CURDIR)/SRC_TMP
debtmp := $(CURDIR)/debian/tmp

pkg := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
VERSION := $(shell dpkg-parsechangelog | grep Version | cut -d\  -f2 | cut -d- -f1)
UVERSION := $(shell dpkg-parsechangelog | grep Version | cut -d\  -f2 | cut -d- -f1 | sed 's/\./_/g')

%:
	dh $@ --with python2

override_dh_install-indep:
	dh_install
	rm -rf debian/$(pkg)/usr/share/cain/help/* debian/$(pkg)/usr/share/cain/gui/help.htm*
	cd help && zip ../debian/$(pkg)/usr/share/cain/help/cain.htb * -r -q -x *.htb *.htd
	if [ -d debian/$(pkg)/usr/share/cain/ ] ; then \
	    find debian/$(pkg)/usr/share/cain/ -type f -executable -exec chmod 644 {} + ; \
	fi

override_dh_auto_test:
	echo "no tests implemented"

override_dh_builddeb:
	dh_builddeb -- -Z xz

get-orig-source:
	rm -rf $(SRC_TMP) && mkdir $(SRC_TMP)
	#[ -f ../cain_$(VERSION).zip ] || wget -O ../cain_$(VERSION).zip http://sf.net/cain/Cain-$(UVERSION).zip # URL did not work
	[ -f ../cain_$(VERSION).zip ] ||  wget -O ../cain_$(VERSION).zip http://qa.debian.org/watch/sf.php/cain/Cain-$(UVERSION).zip
	cd $(SRC_TMP) && unzip ../../cain_$(VERSION).zip
	mv $(SRC_TMP)/Cain $(SRC_TMP)/cain-$(VERSION)
	find $(SRC_TMP) -name __MACOSX -type d | xargs -r rm -rf
	find $(SRC_TMP) -iname .DS_Store -exec rm -f {} +
	find $(SRC_TMP) -iname .scons* -exec rm -f {} +
	rm -f $(SRC_TMP)/cain-$(VERSION)/solvers/*
	rm -rf $(SRC_TMP)/cain-$(VERSION)/src/third-party/*
	cd $(SRC_TMP) && tar cvzf ../../cain_$(VERSION).orig.tar.gz cain-$(VERSION)
	rm -rf $(SRC_TMP)
