#!/usr/bin/make -f

DH_VERBOSE := 1

pkg     := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')
version := $(shell dpkg-parsechangelog -ldebian/changelog | grep Version: | cut -f2 -d' ' | cut -f1 -d- )
bindir  := $(CURDIR)/debian/$(pkg)/usr/bin
mandir  := $(CURDIR)/debian/$(pkg)/usr/share/man/man1

#UVER := $(shell LC_ALL=C dpkg-parsechangelog | awk '/^Version:/{print $$2;}' | sed -e 's,-[^-]*$$,,g')
#CYTHONVER := $(shell dpkg -l cython | awk '/^ii/{print $$3;}' || echo 0)
#MIN_CYTHONVER := 0.17~beta1-2
#NO_CYTHON := $(shell if dpkg --compare-versions $(CYTHONVER) lt $(MIN_CYTHONVER) ; then echo 0 ; else echo 1 ; fi)

# linux-x86_64
pybuilddir := $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)-$(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)

%:
	dh $@ --with python2 --with linktree

override_dh_auto_build:
	dh_auto_build
	cd doc && make singlehtml
	env PYTHONPATH=. pyqi make-bash-completion \
	    --command-config-module biom.interfaces.optparse.config \
	    --driver-name biom -o debian/bash-completion

override_dh_installman:
	cd doc && make man
	dh_installman

override_dh_auto_clean:
	rm -rf build/tests
	dh_auto_clean
	find -name "._*" -delete  #Remove any Mac metadata files
	cd doc && make clean
	rm -f debian/bash-completion
	rm -f python-code/support-code/_*.cpp

override_dh_install:
	dh_install
	dh_bash-completion
	# All *.py scripts simply say
	#   "This script no longer exists. ..."
	rm -f $(bindir)/*.py

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e -x;\
	for pyv in `pyversions -dv` ; do \
	    cd build/; \
	    ln -s ../python-code/tests; \
	    env PYTHONPATH=lib.$(pybuilddir)-$${pyv} nosetests ; \
	done
endif

get-orig-source:
	# . debian/get-orig-source
	mkdir -p ../tarballs
	uscan --verbose --force-download --repack --repack-compression xz --destdir=../tarballs
