#!/usr/bin/make -f

export LC_ALL=C.UTF-8

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

ifeq (alpha,$(DEB_HOST_ARCH))
	export DEB_CFLAGS_MAINT_APPEND=-O1
endif


%:
	dh $@

ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
 test := OFF
else
 test := ON
endif

# -DCMAKE_BUILD_RPATH_USE_ORIGIN=ON can be dropped with debhelper compat 14+
override_dh_auto_configure:
	dh_auto_configure -- \
		-DLIBDEFLATE_USE_SHARED_LIB=ON \
		-DLIBDEFLATE_BUILD_TESTS=$(test) \
		-DCMAKE_BUILD_RPATH_USE_ORIGIN=ON

execute_after_dh_auto_test:
	scripts/run_tests.sh regular

override_dh_installman:
ifeq ($(filter nodoc cross,$(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)),)
	LD_LIBRARY_PATH=$(CURDIR)/debian/libdeflate0/usr/lib/$(DEB_HOST_MULTIARCH) \
		help2man --no-info --help-option=-h --version-option=-V \
		-n "Compress the specified FILEs" \
		debian/libdeflate-tools/usr/bin/libdeflate-gzip --output debian/libdeflate-gzip.1
	LD_LIBRARY_PATH=$(CURDIR)/debian/libdeflate0/usr/lib/$(DEB_HOST_MULTIARCH) \
		help2man --no-info --help-option=-h --version-option=-V \
		-n "Decompress the specified FILEs" \
		debian/libdeflate-tools/usr/bin/libdeflate-gunzip --output debian/libdeflate-gunzip.1
	dh_installman
endif
