#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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

# Program build options
MYPAINT_SCONSOPTS = enable_openmp=true


build: build-arch build-indep

build-arch: build-stamp

build-indep: build-stamp


build-stamp:
	dh_testdir
	scons $(MYPAINT_SCONSOPTS)
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
	touch $@


clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp
	scons -c
	rm -f lib/mypaintlib_wrap.cpp options.cache .sconsign.dblite debian/*.debhelper debian/*.log
	find . -type f -name "*.pyc" -exec rm -vf {} \;
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	# 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
	dh_installchangelogs Changelog.md
	dh_installdocs
	dh_installmenu
	dh_python2
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_icons
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums


binary-indep: install
	dh_builddeb --indep


binary-arch: install
	dh_builddeb --arch


binary: install
	dh_builddeb


.PHONY: build clean binary-indep binary-arch binary install
