#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

export BUILD_TLS = yes
export CFLAGS CPPFLAGS LDFLAGS
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = 
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-no-as-needed -ldl

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

%:
	dh $@

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

override_dh_auto_build:
	# Build dependencies with explicit targets
	$(MAKE) -C deps hiredis hdr_histogram fpconv lua
	$(MAKE) -C deps/fast_float libfast_float
	$(MAKE) -C deps jemalloc
	dh_auto_build -- V=1 USE_SYSTEM_JEMALLOC=no USE_SYSTEMD=yes USE_JEMALLOC=yes BUILD_WITH_RUST_MODULES=no

override_dh_auto_test:
	# Tests disabled to speed up build process
	@echo "Skipping tests for faster build"

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

override_dh_compress:
	dh_compress -Xredis-trib.rb

override_dh_installchangelogs:
	dh_installchangelogs --keep 00-RELEASENOTES
