#!/usr/bin/make -f

export DH_VERBOSE=1

%:
	dh $@ --with python2 --buildsystem pybuild

update-doc:
	if [ ! -d www-doc ] ; then mkdir www-doc ; fi
	cd www-doc && /usr/bin/wget --proxy=off -L -nd -A html,png,gif -k --no-parent -q -m -r -l 1 http://bitconjurer.org/BitTorrent/documentation.html 
	find www-doc -type f -a \( -name "*.gif" -o -name "*.png" \) | \
	while read file ; do cat www-doc/`basename $$file` | uuencode `basename $$file` > www-doc/`basename $$file`.uu ; done
	-rm -f www-doc/robots.txt www-doc/*.gif www-doc/*.png

clean-doc:
	-rm -f www-doc/*

override_dh_auto_build:
	# We do this in order to prevent dpkg-source from breaking
	cd www-doc/ && for i in *.uu; do uudecode $$i; done
	dh_auto_build -O--buildsystem=pybuild

override_dh_install:
	cp debian/tmp/usr/bin/btmakemetafile.py \
	   debian/tmp/usr/bin/btcompletedir.py \
	   debian/tmp/usr/lib/python2.7/dist-packages/BitTorrent
	# .bittorrent for alternatives
	( cd debian/tmp/usr/bin && \
	  for i in btdownloadgui btdownloadheadless bttrack btmakemetafile btlaunchmany btdownloadcurses btlaunchmanycurses btreannounce btrename btshowmetainfo btcompletedir btcompletedirgui; \
	  do mv $$i.py $$i.bittorrent; done )
	dh_install -O--buildsystem=pybuild --fail-missing
