#!/usr/bin/make -f

# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

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

%:
	dh $@


override_dh_auto_configure:
ifeq (amd64,$(DEB_HOST_ARCH))
	for i in "sse2 SEE2" "sse4_1 SEE4" "avx AVX" "avx2 AVX2" "avx512f AVX512" ; do \
		set -- $${i} ; \
		dh_auto_configure --builddirectory build_$${1} -- \
			-DUSE_NATIVE=OFF -DUSE_SHARED=ON -DUSE_$${2}=ON ; \
	done
else
	dh_auto_configure -- \
		-DUSE_NATIVE=OFF -DUSE_SHARED=ON
endif


override_dh_auto_build:
ifeq (amd64,$(DEB_HOST_ARCH))
	for SIMD in avx512f avx2 avx sse4_1 sse2 ; do \
		dh_auto_build --builddirectory build_$${SIMD} && \
		mv build_$${SIMD}/VeryFastTree build_$${SIMD}/VeryFastTree-$${SIMD} ; \
	done
	mkdir -p build_simd
	cp debian/bin/VeryFastTree-simd build_simd/VeryFastTree
else
	dh_auto_build
endif


override_dh_auto_install:
ifeq (amd64,$(DEB_HOST_ARCH))
	dh_install build_*/VeryFastTree-* /usr/libexec/VeryFastTree/
	dh_install build_*/VeryFastTree /usr/bin/
else
	dh_auto_install
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -Rf build_*