#!/usr/bin/make -f

# Hardening
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# Program build options
MYPAINT_SCONSOPTS = enable_openmp=true

%:
	dh $@ --with python2

override_dh_clean:
	scons -c
	rm -f lib/mypaintlib_wrap.cpp options.cache .sconsign.dblite \
	      tests/test_brushPaint.png tests/test_directPaint.png
	find . -type f -name "*.pyc" -delete
	dh_clean

override_dh_auto_build:
	scons $(MYPAINT_SCONSOPTS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Max-RSS: ~74000 kbytes
	MPLCONFIGDIR=`mktemp -d` python tests/test_mypaintlib.py
	# Max-RSS: ~2800000 kbytes - ouch!
	# MPLCONFIGDIR=`mktemp -d` python tests/test_brushlib.py
	# Commented out because it'll FTBFS on 512M Debian ARM buildbots.
endif

override_dh_install:
	# Install to debian/tmp, then cut up.
	scons prefix=/usr $(MYPAINT_SCONSOPTS) --install-sandbox=$(CURDIR)/debian/tmp
	# Headers and a static lib are installed by the above, but are not
	# required at runtime. It's probably counterproductive to ship just a
	# static lib in a dev package (see mailing list thread).
	rm -fr $(CURDIR)/debian/tmp/usr/include
	rm -f $(CURDIR)/debian/tmp/usr/lib/*.a
	rm -fr $(CURDIR)/debian/tmp/usr/lib/pkgconfig
	# When the ABI settles a bit more, let's consider dynamic libs.
	# https://mail.gna.org/public/mypaint-discuss/2013-01/msg00021.html
	dh_install --fail-missing -X prev-template.xcf.gz -X FX_blender_prev.png -X label-brush-mypaint.sh -X generate.py

override_dh_installchangelogs:
	dh_installchangelogs Changelog.md
