#!/usr/bin/make -f

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 FORCE_SOURCE_DATE = 1

MUTABLE_FILES := build.h $(wildcard locale/*.po) \
	documentation/config/version.tex

%:
	dh $@

override_dh_auto_configure:
	for f in $(MUTABLE_FILES); do \
		cp -an $$f $$f.orig; \
	done
	dh_auto_configure -- \
		--localedir=\$${prefix}/share/locale \
		--docdir=\$${prefix}share/doc \
		--docsubdir=dvdisaster-doc \
		--with-embedded-src-path=no

override_dh_clean:
	dh_clean -X.orig
	for f in $(MUTABLE_FILES); do \
		test ! -f $$f.orig || mv -f $$f.orig $$f; \
	done

override_dh_auto_build-arch:
	make all

# For the time being, we'll just package the upstream-generated
# manual.pdf, since we can't build the PDF reproducibly ourselves.
# The reason we can't is most probably due to the fact that the
# LaTeX document embeds other PDF documents and PNG images.
# Although we are able to reproduce the PDF's creation and mod
# dates, as well as its PDF IDs, the stream elements representing
# the embedded images are always what seem to differ each time we
# try to generate the PDF.
override_dh_auto_build-indep:
	# make manual
	true

override_dh_auto_install-arch:
	dh_auto_install -a -- BUILDROOT=$(CURDIR)/debian/tmp

override_dh_auto_install-indep:
	true

# Ensure that none of the text files that the application
# tries to display directly are not compressed, as it doesn't
# automatically decompress text files.
override_dh_compress:
	dh_compress -p dvdisaster \
		-XCHANGELOG -XCREDITS -XREADME.MODIFYING -XTODO
	dh_compress --remaining-packages
