#!/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)

%:
	dh $@ --with python2 # ,sphinxdoc

manpages:
	debian/create-manpages

override_dh_auto_clean:
	dh_auto_clean
	find -name "._*" -exec rm -f '{}' ';'  #Needed if you try to build from pristine tarball
	rm -rf python-code/support-code/_sparsemat.cpp

override_dh_install:
	dh_install
	# remove language extension
	rename 's/\.py$$//;' $(bindir)/*

override_dh_installman:
	# try to create man pages whereever possible
	mkdir -p $(mandir)
	export PYTHONPATH=$(CURDIR)/python-code ; \
	    help2man --no-info --version-string="$(version)" \
		 --name="Script to add sample and/or observation metadata to BIOM-formatted files." \
		$(bindir)/add_metadata > $(mandir)/add_metadata.1 ; \
	    help2man --no-info --version-string="$(version)" \
		--name='Test a biom file for adherence to the format specification' \
		$(bindir)/biom_validator > $(mandir)/biom_validator.1 ; \
	    help2man --no-info --name='Script to convert biom formatted files' \
		$(bindir)/convert_biom > $(mandir)/convert_biom.1 ; \
	    help2man --no-info --version-string="$(version)" \
		--name='summarize sample or observation data in BIOM-formatted files' \
		$(bindir)/print_biom_table_summary > $(mandir)/print_biom_table_summary.1 ; \
	    help2man --no-info --version-string="$(version)" \
		--name='subset a BIOM file, over either the observations or samples' \
		$(bindir)/subset_biom > $(mandir)/subset_biom.1

get-orig-source:
	. debian/get-orig-source
