#!/usr/bin/make -f
# -*- makefile -*-

# Build for multiarch.
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Avoid overlinking and reduce library dependencies.
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Harden SML executables.  Do not build position-independent executables,
# though; urweb depends on the MLton runtime, which is not built position-
# independent in Debian (#837567).
export DEB_BUILD_MAINT_OPTIONS := hardening=+all,-pie
export MLTONARGS := \
	-cc-opt "$(shell dpkg-buildflags --get CPPFLAGS) \
		$(shell dpkg-buildflags --get CFLAGS) \
		-no-pie" \
	-link-opt "$(shell dpkg-buildflags --get LDFLAGS) \
		-no-pie"

%:
	dh $@ --parallel --with autoreconf

.PHONY: override_dh_auto_configure
override_dh_auto_configure:
	LIB=/usr/lib/$(DEB_HOST_MULTIARCH) \
		SRCLIB=/usr/share/urweb dh_auto_configure --

.PHONY: override_dh_auto_build-indep
override_dh_auto_build-indep:
	cd doc && make manual.pdf

# Tests require a working urweb binary, so don't run them on
# architecture-independent builds.
.PHONY: override_dh_auto_test-indep
override_dh_auto_test-indep:
	:

.PHONY: override_dh_auto_install-indep
override_dh_auto_install-indep:
	DESTDIR=${CURDIR}/debian/tmp make install-exec-emacs
