#!/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: bittorrent-downloader.bittornado.1 bittorrent-multi-downloader.bittornado.1 btcompletedir.bittornado.1 btcompletedirgui.bittornado.1 btcopyannounce.1 btdownloadcurses.bittornado.1 btdownloadgui.bittornado.1 btdownloadheadless.bittornado.1 btlaunchmany.bittornado.1 btlaunchmanycurses.bittornado.1 btmakemetafile.bittornado.1 btmaketorrentgui.1 btreannounce.bittornado.1 btrename.bittornado.1 btsethttpseeds.1 btshowmetainfo.bittornado.1 bttrack.bittornado.1
	dh_testdir
	touch build-stamp

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

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

install: build-stamp


	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/bittornado.
	dh_auto_install -- --root=$(CURDIR)/debian/tmp

	install -d debian/tmp/usr/share/mimelnk/application

	install -D -m644 debian/bittornado.desktop debian/bittornado-gui/usr/share/applications/bittornado.desktop
	install -D -m644 debian/bittornado.xpm debian/tmp/usr/share/pixmaps/bittornado.xpm
	install -d debian/tmp/usr/share/bittorrent


# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installmime
	dh_installman
	
	# create versions with .bittornado suffix so that the alternatives
	# system can work. the .py extensions are not installed.
	# btmakemetafile.py and btcompletedir.py is needed for pyinstall
	( cd debian/tmp/usr/bin && \
	  for i in btdownloadgui btdownloadheadless bttrack btmakemetafile \
	  	   btlaunchmany btcompletedir btcompletedirgui \
		   btdownloadcurses btlaunchmanycurses btreannounce btrename \
		   btshowmetainfo; \
	  do cp $$i.py $$i.bittornado || exit 1 ; done )
	
	# Remove the .py from the end of each of these, the following are not
	# included in bittorrent, so they are not renamed to having the
	# suffix of .bittornado
	( cd debian/tmp/usr/bin && \
	  for i in btcopyannounce btsethttpseeds btmaketorrentgui; \
	  do mv $$i.py $$i || exit 1; done )
	chmod 644 debian/tmp/usr/bin/btmakemetafile.py debian/tmp/usr/bin/btcompletedir.py

	dh_installchangelogs 
	dh_install --sourcedir=debian/tmp
	dh_link
	dh_compress
	dh_fixperms
	dh_python2
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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