#!/usr/bin/make -f

# DH_VERBOSE := 1

DEBPKGNAME     := $(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')

%:
	dh $@ --with python2

override_dh_auto_build:
	dh_auto_build
	markdown_py -f README.html README.md
	markdown_py -f README_database_clustering.html database_clustering/README.md

override_dh_install:
	dh_install
	mv debian/$(DEBPKGNAME)/usr/lib/*/dist-packages/$(DEBPKGNAME)/* debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)
	rm -rf debian/*/usr/bin/*.py debian/$(DEBPKGNAME)/usr/lib/*/dist-packages/
	# fix line endings to make sure Python interpreter will be found
	find debian/*/usr/share -name "VFDB*" -exec dos2unix \{\} \;
	sed -i '1s:^#!/usr/local.*python[.0-9]*$$:#!/usr/bin/python:' debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/qsub_srst2.py

override_dh_fixperms:
	dh_fixperms
	chmod +x debian/$(DEBPKGNAME)/usr/share/srst2/database_clustering/get_genus_vfdb.sh
	chmod +x debian/$(DEBPKGNAME)/usr/share/srst2/database_clustering/get_all_vfdb.sh
	chmod -x debian/$(DEBPKGNAME)/usr/share/srst2/database_clustering/align_plot_tree_min3.py

override_dh_auto_test:
	cd tests && python test_slurm_srst2.py && python test_srst2.py 

override_dh_installdocs:
	dh_installdocs
	sed -i "s?sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__).*scripts.*?sys.path.append(os.path.abspath('/usr/share/$(DEBPKGNAME)'))?" debian/$(DEBPKGNAME)/usr/share/doc/$(DEBPKGNAME)/tests/*.py

# README.html contains a really maintained changelog
#override_dh_installchangelogs:
#	dh_installchangelogs CHANGES.txt
