#!/usr/bin/make -f

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

RANLIB ?= ranlib

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	cd tex && make clean
	rm -f MT-human.mmi
	rm -f tex/minimap2.aux tex/minimap2.bbl tex/minimap2.blg tex/minimap2.log tex/minimap2.out tex/minimap2.pdf
	rm -f libminimap2.a

ifeq (,$(filter $(DEB_HOST_ARCH_CPU),amd64 i386))
build_vars = -f Makefile.simde
export DEB_CFLAGS_MAINT_APPEND += -fopenmp-simd -O3 -DSIMDE_ENABLE_OPENMP
endif
# ifneq (,$(filter $(DEB_HOST_ARCH_CPU),arm64))
# build_vars += aarch64=1
# endif

override_dh_auto_build:
	dh_auto_build -- $(build_vars)
	cd tex && make
	dh_auto_build --buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	debian/test_script
	rm test.sam
endif

override_dh_auto_install:
	dh_auto_install
	dh_auto_install --buildsystem=pybuild

override_dh_compress:
	dh_compress --exclude=.pdf

# No idea why, but the stipping ruined the index of the .a file as spotted by nanopolish
# as its reverse dependency
override_dh_strip:
	dh_strip
	$(RANLIB) $(CURDIR)/debian/libminimap2-dev/usr/lib/libminimap2.a

override_dh_installman:
	dh_installman --language=C
