#!/usr/bin/make -f

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

PYVERS=$(shell pyversions -vr)

build: build-arch build-indep

build-arch: 

build-indep: build-stamp

build-stamp: build-prereq $(PYVERS:%=build-python%)
# This is to force building of the sixpack script without an explicit 
# python version in the #! line.
	python setup.py build_scripts --build-dir=build/scripts || exit 1 ; 
	touch $@
 
build-prereq:
# Rename main program to the Debian name.  This is to avoid a naming conflict
# with a command line program in the EMBOSS suite.  Not the optimal solution 
# but acceptable. (CUS)
	cp -a sixpack.py SIXpack

build-python%:
	dh_testdir
	python$* setup.py build || exit 1;
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp build-python*

	# Clean up after the build process.
	/usr/bin/python setup.py clean
	rm -f *.pyc
# Remove the copied file.
	rm -f SIXpack
	rm -rf build

	dh_clean 

install: build install-prereq install-all-pythons

install-prereq:
	dh_testdir
	dh_testroot
	dh_prep 
	dh_installdirs

install-all-pythons: $(PYVERS:%=install-python%)
# This is to force installation of the sixpack script without a specific
# version of python explicitly names in the #! line (Debian idiosyncracy).
# It actually overwrites the scripts installed by each of the install-python% 
# rules below...
	python setup.py install_scripts --force \
	 --install-dir=$(CURDIR)/debian/sixpack/usr/bin \
	 --build-dir=build/scripts || exit 1 ;
	cp -a xbms/* $(CURDIR)/debian/sixpack/usr/share/SIXpack/
	cp -a splogo.gif $(CURDIR)/debian/sixpack/usr/share/SIXpack/splogo.gif
	cp -a test.inp $(CURDIR)/debian/sixpack/usr/share/SIXpack/
	cp -a mnexafsfit.iff $(CURDIR)/debian/sixpack/usr/share/SIXpack/
	dh_install debian/SIXpack.xpm usr/share/pixmaps
	dh_install debian/SIXpack.desktop usr/share/applications

install-python%:
	# Install the package into debian/sixpack.
	dh_installdirs usr/lib/python$* usr/lib/python$*/site-packages
	python$* setup.py install \
	 --prefix=$(CURDIR)/debian/sixpack/usr || exit 1;
	-find $(CURDIR)/debian/ -name '*.py[co]' | xargs rm -f

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installdocs -i 
	dh_installexamples -i
	dh_installmenu -i
#	dh_desktop -i
	dh_installman -i
	dh_installinfo -i
	dh_installchangelogs -i
	dh_python2
	dh_link -i
	dh_strip -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_shlibdeps -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

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