#!/usr/bin/make -f

pkg := bowtie2

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)
export LANG=C
export LC_ALL=C.UTF-8

include /usr/share/dpkg/architecture.mk

EXTRA_OPTIONS =
ifneq ($(DEB_HOST_ARCH),amd64)
        EXTRA_OPTIONS = NO_TBB=1
endif
export EXTRA_OPTIONS

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- EXTRA_FLAGS="-std=c++98 $(LDFLAGS)" $(EXTRA_OPTIONS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	$(MAKE) EXTRA_FLAGS="-std=c++98 $(LDFLAGS)" $(EXTRA_OPTIONS) \
	  bowtie2-build-s-debug \
	  bowtie2-build-l-debug \
	  bowtie2-align-s-debug \
	  bowtie2-align-l-debug \
	  bowtie2-inspect-s-debug \
	  bowtie2-inspect-l-debug \
	  bowtie2-align-s-sanitized \
	  bowtie2-align-l-sanitized \
	  bowtie2-build-s-sanitized \
	  bowtie2-build-l-sanitized
	make -j1 test
endif

override_dh_auto_install:
	dh_auto_install

override_dh_install:
	dh_install -X.gitignore

override_dh_installman:
	mkdir -p $(CURDIR)/debian/$(pkg)/usr/share/man/man1/
	debian/help2man-wrapper $(pkg) "wrapper for $(pkg)-align-*"
	debian/help2man-wrapper $(pkg)-build "wrapper for $(pkg)-build-*"
	debian/help2man-wrapper $(pkg)-build-l "building a colorspace index for $(pkg)"
	debian/help2man-wrapper $(pkg)-build-s "building a colorspace index for $(pkg)"
	debian/help2man-wrapper $(pkg)-inspect "wrapper for $(pkg)-inspect-* index"
	debian/help2man-wrapper $(pkg)-inspect-l "extracts information from a $(pkg) index"
	debian/help2man-wrapper $(pkg)-inspect-s "extracts information from a $(pkg) index"
	debian/help2man-wrapper $(pkg)-align-l "ultrafast and memory-efficient backend tool for aligning sequencing reads to long reference sequences"
	debian/help2man-wrapper $(pkg)-align-s "ultrafast and memory-efficient backend tool for aligning sequencing reads to long reference sequences"
	rm -f $(CURDIR)/debian/$(pkg)/usr/bin/bowtie2-buildc

override_dh_installchangelogs:
	dh_installchangelogs NEWS
