#!/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
export DEB_CFLAGS_MAINT_APPEND += -DSIMDE_ENABLE_OPENMP -fopenmp-simd -O3
export DEB_CXXFLAGS_MAINT_APPEND += -DSIMDE_ENABLE_OPENMP -fopenmp-simd -O3

EXTRA_OPTIONS =
ifneq ($(DEB_TARGET_ARCH),amd64)
        EXTRA_OPTIONS += NO_TBB=1 POPCNT_CAPABILITY=
else
        EXTRA_OPTIONS += POPCNT_CAPABILITY=1
endif

export EXTRA_OPTIONS

%:
	dh $@

override_dh_auto_build:
	LD_PRELOAD= dh_auto_build -- EXTRA_FLAGS="-std=c++98 $(LDFLAGS)" $(EXTRA_OPTIONS) HOSTNAME=reproducible-hostname
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	dh_auto_build -- doc/manual.html
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	LD_PRELOAD= $(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
	LD_PRELOAD= make -j1 test
endif

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

override_dh_gencontrol:
	dh_gencontrol -- -Vsimde:Built-Using="$(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W "libsimde-dev")"
