#!/usr/bin/make -f

REDIS   = $(shell [ -e /usr/bin/redis-server ] && echo 1 || echo 0)

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
DPKG_EXPORT_BUILDFLAGS=1
include /usr/share/dpkg/buildflags.mk

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@

override_dh_auto_build:
	dh_auto_build -- DEBUG="-g" ARCH=

override_dh_auto_install:
	dh_auto_install -- LIBRARY_PATH="lib/$(DEB_HOST_MULTIARCH)" \
		PREFIX=/usr

override_dh_fixperms:
	dh_fixperms
	chmod 644 debian/libhiredis-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/*.pc
	chmod 644 debian/libhiredis-dev/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Hiredis/*.cmake

override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.md

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq ($(REDIS), 1)
	make check || [ "$(DEB_BUILD_ARCH_OS)" = "mipsel64" ]
endif
endif
