#!/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 --debuginfo:on -d:release -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)/nimcache mosdepth.nim
	help2man --no-info --no-discard-stderr --help-option="-h" ./mosdepth > debian/mosdepth.1
	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

override_dh_auto_clean:
	rm -f debian/mosdepth.1
	rm -f mosdepth
	rm -rf nimcache
	rm -f tests/big.bam.csi
	rm -f tests/ovl.bam tests/ovl.bam.bai tests/overlapping-pairs.bam.bai tests/overlapping-pairs.bam tests/overlapping-pairs.bam  tests/empty-tids.bam.bai tests/empty-tids.bam tests/big.bam tests/nanopore.bam tests/nanopore.bam.bai

override_dh_dwz:
	dh_dwz || true
