#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/makefile.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

HEAPSIZE := $(shell . debian/heap-size)
	
# MLton compiles optimized, debug, and pic versions on its own.
DEB_MAKE_INVOKE = $(DEB_MAKE_ENVVARS) make -C $(DEB_BUILDDIR)

# The MLton guide is html. Don't compress example .sml files.
DEB_COMPRESS_EXCLUDE_ALL = mlton/guide .sml

DEB_MAKE_CLEAN_TARGET   = clean clean-svn
DEB_MAKE_BUILD_TARGET   = all RUNTIME_ARGS="$(HEAPSIZE)"
DEB_MAKE_INSTALL_TARGET = install-no-strip DESTDIR=$(CURDIR)/debian/tmp/ PREFIX=/usr MAN_PREFIX_EXTRA=/share
DEB_MAKE_CHECK_TARGET   = check

# Useful when inspecting build logs
common-configure-arch::
	free

# Move MLton target to per-architecture path
common-install-arch::
	mv $(CURDIR)/debian/tmp/usr/lib/mlton/targets/self $(CURDIR)/debian/tmp/usr/lib/mlton/targets/$(DEB_HOST_GNU_TYPE)
	ln -s $(DEB_HOST_GNU_TYPE) $(CURDIR)/debian/tmp/usr/lib/mlton/targets/self

# Remove licenses and empty directories to appease lintian
common-install-indep::
	find $(CURDIR)/debian/tmp -type d -empty -delete
	rm -rf $(CURDIR)/debian/tmp/usr/share/doc/mlton/license
	if test -n "$(DEB_ISNATIVE)"; then mv \
		$(CURDIR)/debian/tmp/usr/share/doc/mlton/changelog \
		$(CURDIR)/debian/tmp/usr/share/doc/mlton/changelog.PreviousRelease; \
	fi
