#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

PYTHON_VERSION=$(shell /usr/bin/python -V 2>&1 | /usr/bin/perl -le 'print "$$1.$$2" if <> =~m/^Python\s+(\d+)\.(\d+)(\.\d+)*/')


build-stamp: debtorrent-client.1 debtorrent-tracker.1
	dh_testdir
	touch build-stamp

%.1:	debian/%.sgml
	/usr/bin/docbook-to-man $< > debian/$@

clean:
	dh_testdir
	dh_testroot
	rm -rf build/ DebTorrent/BT1/*.pyc DebTorrent/*.pyc *.pyc
	rm -f debian/*.1
	rm -f build-stamp
	dh_clean

install: build-stamp


	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	./setup.py install --prefix=$(CURDIR)/debian/debtorrent/usr --install-lib=$(CURDIR)/debian/debtorrent/usr/share/python-support/debtorrent

	# Remove the generated .pyc files
	( cd debian/debtorrent/usr/share/python-support/debtorrent/DebTorrent && \
	  rm -f *.pyc  && \
	  cd BT1 && \
	  rm -f *.pyc )

# Build architecture-independent files here.
binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_installlogrotate
	
	# Remove the .py from the end of each of these and move them out of
	# the path
	for i in test hippy uniquely split_cache_for_all \
		btmakemetafile btcompletedir btreannounce \
		btrename btshowmetainfo btcopyannounce btsetdebmirrors; \
	do mv debian/debtorrent/usr/bin/$$i.py debian/debtorrent/usr/share/debtorrent/$$i || exit 1; done

	# Remove the .py from the end of each of these
	for i in debtorrent-client debtorrent-tracker; \
	do mv debian/debtorrent/usr/bin/$$i.py debian/debtorrent/usr/bin/$$i || exit 1; done

	dh_installchangelogs 
	dh_install
	dh_link
	dh_compress
	dh_fixperms
	dh_pysupport
	dh_installinit --name=debtorrent-client
	dh_installinit --name=debtorrent-tracker
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
