#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules for Qiime
# Tim Booth <tbooth@ceh.ac.uk>, Andreas Tille <tille@debian.org>
# GPL

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

pkg := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')

#Allowing this to be overridden by environemnt helps with backports
DEB_PYTHON_SUPPORT?=python2

%:
	dh $@ --with $(DEB_PYTHON_SUPPORT)

override_dh_compress:
	dh_compress \
	    --exclude=.js \
	    --exclude=.sff \
	    --exclude=.qual \
	    --exclude=.fna \
	    --exclude=.fna.txt

override_dh_auto_clean:
	#Calling "python setup.py clean -a" actually triggers a
	#rebuild, so don't do it.
	rm -rf build
	rm -rf doc/_build
	( cd $(pkg)/support_files/denoiser/FlowgramAlignment && make clean ) || true
	rm -f $(pkg)/support_files/denoiser/bin/*
	#In case the tarball was not re-packed, remove any .jars
	find -name '*.jar' -delete
	#And in case any Python script was run, remove the .pyc
	find qiime scripts -name '*.pyc' -delete
	# Remove remainings from running the test suite
	rm -f BLAST_temp_db*
	rm -rf jobs

export ROOTDIR=debian/$(pkg)

#Lots of shuffling to be done...
# Python scripts go into /usr/lib/$(pkg)/bin (not /usr/bin)
# Helper script goes into /usr/bin
# Setup scripts go into /usr/lib/$(pkg)/shell
# Default configuration goes into /etc/$(pkg)/default_qiime_config
# ...see debian/*.install files
override_dh_install:
	dh_install
	chmod a+x $(ROOTDIR)/usr/lib/qiime/bin/uclust || true
	chmod a+x $(ROOTDIR)/usr/lib/qiime/bin/usearch* || true
	chmod -R a+rX $(ROOTDIR)/usr/lib/qiime/shell || true
	chmod a-x $(ROOTDIR)/usr/share/qiime/support_files/R/* || true
	chmod a-x $(ROOTDIR)/usr/share/qiime/support_files/js/* || true
	#Fix lintian warning for jquery
	rm $(ROOTDIR)/usr/share/qiime/support_files/js/jquery.js && \
	    ln -s /usr/share/javascript/jquery/jquery.js $(ROOTDIR)/usr/share/qiime/support_files/js
	#Make some symlinks as Qiime assumes a single dir structure
	for path in denoiser/Data css images R js ; do \
		dh_link -pqiime /usr/share/qiime/support_files/"$$path" /usr/lib/qiime/support_files/"$$path" ;\
	done

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog.md

override_dh_builddeb:
	dh_builddeb -- -Z xz

# Remark: The following uscan command requires devscripts > 2.12.4 which is not
#         yet released at the time of this package release.  The code can be obtained
#         via
#   git clone git://tille@git.debian.org/git/users/tille/devscripts.git
#         and then use scripts/uscan.pl
get-orig-source:
	mkdir -p ../tarballs
	uscan --verbose --force-download  --destdir=../tarballs --repack-compression xz
