#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/pkg-info.mk

%:
	dh $@ --builddirectory=build

override_dh_auto_clean:
	rm -f *.1
	dh_auto_clean --

override_dh_install:
	dh_install
	find debian -name "LICENSE*.rst" -delete

override_dh_installman:
	./build/bin/lambda --export-help man \
	  | sed -r 's/(number of threads.*) Default:.*/\1/g' \
	  | sed -r 's/\(Git commit +\)//g' > lambda.1
	./build/bin/lambda_indexer --export-help man \
	  | sed -r 's/(number of threads.*) Default:.*/\1/g' \
	  | sed -r 's/(defaults to working directory.*) Default:.*/\1/g' \
	  | sed -r 's/\(Git commit +\)//g' > lambda_indexer.1
	dh_installman --

override_dh_auto_configure:
	dh_auto_configure -- -DLAMBDA_NATIVE_BUILD=OFF -DLAMBDA_MMAPPED_DB=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifneq (,$(filter amd64 arm64 mips64el ppc64el,$(DEB_BUILD_ARCH)))
	cd build/tests && ctest $(shell nproc)
endif
endif
