#!/usr/bin/make -f

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-arch:
build-indep:

build-stamp: apt-p2p.8 apt-p2p.conf.5
	dh_testdir
	touch build-stamp

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

clean:
	dh_testdir
	dh_testroot
	rm -rf build/ apt_p2p/*.pyc apt_p2p_Khashmir/*.pyc *.pyc
	rm -f debian/*.[58]
	rm -f build-stamp
	dh_clean

install: build-stamp


	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	./setup.py install --prefix=$(CURDIR)/debian/apt-p2p/usr \
		--install-scripts=$(CURDIR)/debian/apt-p2p/usr/sbin

	# Remove the generated .pyc files
	( cd debian/apt-p2p/usr/lib/python2.7/site-packages/apt_p2p_Khashmir && \
	  rm -f *.pyc  && \
	  cd ../apt_p2p && \
	  rm -f *.pyc )

# Build architecture-independent files here.
binary-indep: install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installman
	dh_installlogrotate
	
	# Remove the .py from the end of each of these
	mv debian/apt-p2p/usr/sbin/apt-p2p.py debian/apt-p2p/usr/sbin/apt-p2p

	dh_installchangelogs 
	dh_install
	dh_link
	dh_compress
	dh_fixperms
	dh_python2
	dh_installinit
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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