#!/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 \{\} \;

override_dh_fixperms:
	dh_fixperms
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/getmlst.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/scores_vs_expected.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/slurm_srst2.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/srst2.py
	chmod -x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/database_clustering/align_plot_tree_min3.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/database_clustering/VFDB*.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/database_clustering/csv_to_gene_db.py
	chmod +x debian/$(DEBPKGNAME)/usr/share/$(DEBPKGNAME)/database_clustering/*.sh

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
