#!/usr/bin/make -f
#export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic

# Don't build excessive SIMD variants which never made it on 32bit x86.
ifeq ($(DEB_HOST_ARCH), i386)
SIMD_FLAGS = --disable-avx512 --disable-avx2 --disable-sse4_1
endif

# FIXME: Arm platforms FTBFS when Neon support is enabled, so disable for now.
ifneq ($(filter $(DEB_HOST_ARCH),armel armhf arm64),)
SIMD_FLAGS = --disable-neon
endif

%:
	dh $@

override_dh_auto_configure:
	@ echo 'blhc: ignore-line-regexp:     C(C|XX) : \.+ .*'
	dh_auto_configure -- $(SIMD_FLAGS) \
                --enable-shared \
		--disable-static

override_dh_install:
	dh_install
	cp `find .libs -name "libparasail*.a" | head -n1` \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libparasail.a
	d-shlibmove --commit \
		    --multiarch \
		    --devunversioned \
		    --exclude-la \
		    --movedev debian/tmp/usr/include usr \
		    --movedev "debian/tmp/usr/lib/*/pkgconfig/*.pc" \
	                      usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig \
		    debian/tmp/usr/lib/*/*.so
	rm debian/libparasail-dev/usr/lib/$(DEB_HOST_MULTIARCH)/libparasail.a
	dh_install -p libparasail-dev .libs/*.a usr/lib/$(DEB_HOST_MULTIARCH)
	find debian -name "lib*.la" -delete

override_dh_fixperms:
	dh_fixperms
	find debian -name "*.c" -exec chmod -x \{\} \;
