#!/usr/bin/make -f

# DH_VERBOSE := 1
export LC_ALL=C.UTF-8
export TZ=UTC

include /usr/share/dpkg/default.mk

# for hardening you might like to uncomment this:
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export DEB_CFLAGS_MAINT_APPEND += -DSIMDE_ENABLE_OPENMP -fopenmp-simd -O3
export DEB_CXXFLAGS_MAINT_APPEND += -DSIMDE_ENABLE_OPENMP -fopenmp-simd -O3

ifneq (,$(filter arm64 armhf armel ppc64el s390x,$(DEB_HOST_ARCH)))
export DEB_CFLAGS_MAINT_APPEND += -Wno-narrowing
export DEB_CXXFLAGS_MAINT_APPEND += -Wno-narrowing
endif

ifneq (,$(filter amd64,$(DEB_HOST_ARCH)))
export DEB_CFLAGS_MAINT_APPEND += -DPOPCNT_CAPABILITY
export DEB_CXXFLAGS_MAINT_APPEND += -DPOPCNT_CAPABILITY
endif


DATE=$(shell date --date=@$(SOURCE_DATE_EPOCH) '+%d %B %Y')

%:
	dh $@

override_dh_auto_build:
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	dh_auto_build --  BUILD_HOST='Debian' BUILD_TIME="$(DATE)" all doc
	help2man ./hisat2 --no-info --name \
		'graph-based alignment of short nucleotide reads to many genomes, wrapper script' \
		> debian/hisat2.1
	help2man ./hisat2-align-l --name 'HISAT2 graph-based alignment of short nucleotide reads to many genomes, large index binary' \
		--no-info > debian/hisat2-align-l.1
	help2man ./hisat2-align-s --name 'HISAT2 graph-based alignment of short nucleotide reads to many genomes, small index binary' \
		--no-info > debian/hisat2-align-s.1
	help2man ./hisat2-build --name 'HISAT2 indexer, wrapper script' \
		--no-info > debian/hisat2-build.1
	#rm hisat2-buildc
	help2man ./hisat2-build-l --name 'HISAT2 indexer, large index binary' \
		--no-info > debian/hisat2-build-l.1
	help2man ./hisat2-build-s --name 'HISAT2 indexer, small index binary' \
		--no-info > debian/hisat2-build-s.1
	help2man ./hisat2-inspect --name 'HISAT2 index inspector, wrapper script' \
		--no-info > debian/hisat2-inspect.1
	help2man ./hisat2-inspect-l --name 'HISAT2 index inspector, large index binary' \
		--no-info > debian/hisat2-inspect-l.1
	help2man ./hisat2-inspect-s --name 'HISAT2 index inspector, small index binary' \
		--no-info > debian/hisat2-inspect-s.1
else
	dh_auto_build --  BUILD_HOST='Debian' BUILD_TIME="$(DATE)" all
endif

override_dh_install:
	dh_install
	for pl in `grep -Rl '#!/usr/bin/env[[:space:]]\+perl' debian/*/usr/*` ; do \
	    sed -i '1s?^#!/usr/bin/env[[:space:]]\+perl?#!/usr/bin/perl?' $${pl} ; \
	done
