#!/usr/bin/make -f

export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
export DEB_CFLAGS_MAINT_APPEND = $(CPPFLAGS) -Wall -Wno-deprecated-declarations -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION
export FORCE_SOURCE_DATE = 1

MUTABLE_FILES := build.h $(wildcard locale/*.po) \
	documentation/config/version.tex \
	documentation/user-manual/manual.pdf
BACKUP_TAR_FILE := debian/backup.tar

BUILDROOT := $(CURDIR)/debian/tmp
ICONS := $(wildcard contrib/dvdisaster*.png)
ICON_SIZES := $(patsubst contrib/dvdisaster%.png,%,$(ICONS))

%:
	dh $@

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

override_dh_clean:
	dh_clean
	test ! -f $(BACKUP_TAR_FILE) || \
		tar xpf $(BACKUP_TAR_FILE) && rm -f $(BACKUP_TAR_FILE)

override_dh_auto_configure:
	./configure \
		--prefix=/usr \
		--mandir=share/man \
		--localedir=share/locale \
		--docdir=share/doc \
		--docsubdir=dvdisaster \
		--with-embedded-src-path=no

override_dh_auto_build-arch:
	dh_auto_build -a -- all

override_dh_auto_build-indep:
	dh_auto_build -i \
		$(if $(findstring nodoc,$(DEB_BUILD_OPTIONS)),--no-act) \
		-- manual

override_dh_auto_install-arch:
	dh_auto_install -a -- BUILDROOT=$(BUILDROOT)
	set -e; \
	for S in $(ICON_SIZES); do \
		D="$(BUILDROOT)/usr/share/icons/hicolor/$${S}x$${S}/apps"; \
		install -d "$${D}"; \
		install -T "contrib/dvdisaster$${S}.png" "$${D}/dvdisaster.png"; \
	done

override_dh_auto_install-indep:
	true

# Ensure that none of the text files that the application
# tries to display directly are compressed, as it doesn't
# automatically decompress text files.
override_dh_compress-arch:
	dh_compress -p dvdisaster \
		-Xchangelog -XCREDITS -XREADME.MODIFYING -XTODO
	gzip -9n debian/dvdisaster/usr/share/doc/dvdisaster/changelog.Debian

override_dh_installchangelogs-arch:
	dh_installchangelogs -p dvdisaster -k
