#!/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 $@

override_dh_auto_configure:
ifneq ($(filter nocheck,$(DEB_BUILD_PROFILES)),)
	dh_auto_configure -- -DLIBDEFLATE_USE_SHARED_LIB=1
else
	dh_auto_configure -- -DLIBDEFLATE_USE_SHARED_LIB=1 -DLIBDEFLATE_BUILD_TESTS=1
endif

execute_after_dh_auto_test:
	scripts/run_tests.sh regular

execute_after_dh_install:
	d-shlibmove --commit \
		    --multiarch \
		    --devunversioned \
		    --exclude-la \
		    --movedev "debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/*.pc" usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig \
		    --movedev "debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/cmake" usr/lib/$(DEB_HOST_MULTIARCH)/ \
		    debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*.so

ifeq ($(filter nodoc,$(DEB_BUILD_PROFILES)),)
execute_before_dh_installman:
	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
endif
