#!/usr/bin/make -f

export DH_VERBOSE = 1
export QT_SELECT = 5

srcpkg = $(shell LC_ALL=C dpkg-parsechangelog | grep '^Source:' | cut -d ' ' -f 2,2)
debver = $(shell LC_ALL=C dpkg-parsechangelog | grep '^Version:' | cut -d ' ' -f 2,2 )
upstreamver = $(shell echo $(debver) | cut -d '-' -f 1,1 )

# this figures out the last merge point from 'upstream' into the Debian branch
# and then described this commit relative to the last release tag (v...)
# If this should make any sense the local upstream branch must track upstream's
# master or whatever other source branch.
gitver = $(shell [ -x /usr/bin/git ] && git describe --tags --match 'v.[0-9].[0-9]*' $$(git merge-base -a HEAD upstream) | sed -e 's/^v\.//' -e 's/-/+git/' -e 's/\([0-9]\)\([A-Z]\)/\1~\2/g'| tr [A-Z] [a-z])~dfsg.1

%:
	dh $@ --sourcedirectory=$(CURDIR) --builddirectory=$(CURDIR)/build --parallel

# qmake support in dh doesn't manage out of tree builds as intended
# override and pass source dir to qmake manually
override_dh_auto_configure:
	dh_auto_configure -- $(CURDIR)

override_dh_auto_install:
	dh_auto_install
	# remove bits that will come from dependencies
	rm build/Resources/Help/marked.js

override_dh_auto_test:
	# this is likely doing nothing now, but who knows about the future
	dh_auto_test
	# test suite opens interactive pop-up -> gh-1690
	#JASP-Tests/JASPTests
	# R-based tests fail now
	#cd JASP-Tests && R --no-save --no-restore -f run_tests.R

override_dh_shlibdeps:
	dh_shlibdeps -l/usr/lib/R/site-library/RInside/lib/

# make orig tarball from repository content
get-orig-source:
	# orig tarball, turn directory into something nicer
	git archive --format=tar --prefix=$(srcpkg)-$(gitver)/ HEAD | \
		gzip -9 > $(srcpkg)_$(gitver).orig.tar.gz

