#!/usr/bin/make -f

include /usr/share/dpkg/buildflags.mk

export CFLAGS CPPFLAGS LDFLAGS
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -ldl -latomic

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
	export MAKEFLAGS
endif

%:
	dh $@

override_dh_auto_install:
	debian/bin/generate-systemd-service-files

override_dh_auto_build:
	dh_auto_build --parallel -- V=1

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Avoid race conditions in upstream testsuite. (#830500)
ifneq (,$(findstring $(DEB_BUILD_ARCH),"mipsel"))
	# Ignore test failures on problematic archs
	./runtest --clients 1 || true
else
	./runtest --clients 1
endif
	# Sentinel integration tests use too many timers to be reliable or
	# meaningful.
	./runtest-cluster || true
	./runtest-sentinel || true
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -f src/release.h debian/*.service

override_dh_compress:
	dh_compress -Xredis-trib.rb

override_dh_installchangelogs:
	dh_installchangelogs --keep 00-RELEASENOTES
