#!/usr/bin/make -f

DH_VERBOSE := 1
export LC_ALL=C.UTF-8
export HOME=/tmp

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/default.mk

%:
	dh $@

override_dh_auto_build:
	nim c -p:/usr/share/nimble/unicodeplus  -p:/usr/share/nimble/unicodedb  -p:/usr/share/nimble/regex  -p:/usr/share/nimble/docopt -p:/usr/share/nimble/hts --nimcache:$(CURDIR)/tests/nimcache mosdepth.nim
	help2man --no-info --no-discard-stderr --help-option="-h" ./mosdepth > debian/mosdepth.1

override_dh_auto_test:
	rm -f tests/missing.bed
	for f in debian/missing-sources/*; do \
		outp=tests/`echo $$f | sed -e 's/sam/bam/' -e 's/debian\/missing\-sources\///'` ; \
		cat $$f | samtools view -Sb - > $$outp ; \
		if [ "$$outp" = "tests/big.bam" ] ; then \
			samtools index $$outp -c ; \
			continue ; \
		fi ; \
		samtools index $$outp ; \
	done
	dh_auto_test

override_dh_auto_clean:
	rm -f debian/mosdepth.1
	rm -f mosdepth
