#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
MULTIARCH=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DESTDIR=/usr
export LIBDIR=$(DESTDIR)/lib/$(MULTIARCH)/
export INCDIR=$(DESTDIR)/include/
TESTBINS = highwayhash_test nanobenchmark_example profiler_example sip_hash_test vector_test

ifeq (arm64,$(BUILD_ARCH))
export HH_AARCH64=1
endif
ifeq (ppc64,$(BUILD_ARCH))
export HH_POWER=1
endif
ifeq (ppc64el,$(BUILD_ARCH))
export HH_POWER=1
endif

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	-$(RM) deps.mk

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test
	for ITEM in $(TESTBINS); do \
		./bin/$$ITEM; \
	done
endif

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/libhighwayhash0/usr/lib/$(MULTIARCH)
	rename 's/.so/.so.0/' debian/tmp/usr/lib/$(MULTIARCH)/*.so
	install -m0755 debian/tmp/usr/lib/$(MULTIARCH)/*.so.0 \
		debian/libhighwayhash0/usr/lib/$(MULTIARCH)/
	mkdir -p debian/libhighwayhash-dev/usr/lib/$(MULTIARCH)
	install -m0755 debian/tmp/usr/lib/$(MULTIARCH)/*.a \
		debian/libhighwayhash-dev/usr/lib/$(MULTIARCH)/
	set -e; cd debian/libhighwayhash-dev/usr/lib/$(MULTIARCH)/; \
		ln -s libhighwayhash.so.0 libhighwayhash.so
