#!/usr/bin/make -f

export DEB_CFLAGS_MAINT_STRIP = -O2 -g -O3
export DEB_CXXFLAGS_MAINT_STRIP = -O2 -g -O3
export DEB_CFLAGS_MAINT_APPEND = -Ofast -flto -fomit-frame-pointer -pipe
export DEB_CXXFLAGS_MAINT_APPEND = -Ofast -flto -fomit-frame-pointer -pipe

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
# move modsec-rules-check (lib debugging/testing tool) to libexec to avoid
# an extra package while keeping the library package multiarch
CONFIGURE_EXTRA_FLAGS += --bindir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)/libexec 

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

%:
	dh $@ --parallel

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_EXTRA_FLAGS) --with-lmdb --with-pcre2 --disable-dependency-tracking --with-pcre=no --disable-doxygen-doc --disable-doxygen-html

override_dh_auto_install:
	dh_auto_install
	# clean dependency_libs in .la files (Policy 10.2)
	sed -i "/dependency_libs/ s/'.*'/''/" $$(find debian/tmp/ -name '*.la')

