#!/usr/bin/make -f

export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all future=+lfs

# Backup and restore mutable files to ensure idempotent builds.
MUTABLE_FILE_LIST := debian/mutable
BACKUP_TAR_FILE := debian/backup.tar

%:
	dh $@

override_dh_update_autotools_config:
	dh_update_autotools_config
	test -f $(BACKUP_TAR_FILE) || \
		tar cpf $(BACKUP_TAR_FILE) -T $(MUTABLE_FILE_LIST)

override_dh_clean:
	dh_clean \
		$(if $(findstring nodoc,$(DEB_BUILD_OPTIONS)),docs/Makefile)
	test ! -f $(BACKUP_TAR_FILE) || \
		tar xpf $(BACKUP_TAR_FILE) && rm -f $(BACKUP_TAR_FILE)

$(patsubst %,override_dh_auto_%,clean build install test):
	$(patsubst override_%,%,$@) -- \
		$(if $(findstring nodoc,$(DEB_BUILD_OPTIONS)),SUBDIRS="src gnu")
