#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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

DISABLE_INSTRUCTION_SETS = \
	--disable-sse3     \
	--disable-ssse3    \
	--disable-sse41    \
	--disable-sse42    \
	--disable-avx      \
	--disable-avx2     \
	--disable-fma      \
	--disable-fma4

# Disable failing test test-charpoly on mips and mipsel.
# See #797167, #856356 and https://github.com/linbox-team/linbox/issues/37
ifneq (,$(filter mips mipsel, $(DEB_HOST_ARCH_CPU)))
override_dh_autoreconf:
	sed -e '/\s*test-charpoly\s*\\/d' -i tests/Makefile.am
	dh_autoreconf
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		--prefix=/usr \
		--libdir=/usr/lib/$(DEB_HOST_MULTIARCH) \
		--with-gmp \
		--with-m4rie \
		--with-givaro \
		--with-ntl \
		--with-iml \
		--with-m4ri \
		--without-fplll \
		--enable-shared \
		$(DISABLE_INSTRUCTION_SETS)

override_dh_auto_install:
	dh_auto_install --max-parallel=1
	cd debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH); \
		ln -s liblinbox-1.6.3.so.0.0.0 liblinbox-1.6.3.so; \
		sed -e 's|-llinbox|-llinbox-1.6.3|' -i pkgconfig/linbox.pc

override_dh_auto_build-indep:
	dh_testdir
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) docs_dev
	$(MAKE) docs
	rm -f doc/linbox-*html/INSTALL
	rm -f doc/linbox-*html/COPYING
endif

%:
	dh $@
