#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export GEM2DEB_TEST_RUNNER = --check-dependencies
# export DH_RUBY = --gem-install

%:
	dh $@ --buildsystem=ruby --with ruby

override_dh_auto_build-indep:
	JRUBY_HOME=/usr/share/jruby jruby -S rake compile

override_dh_auto_install-arch:
	dh_auto_install
	cd ./debian/ruby-psych/usr && rm -rf ./bin

override_dh_auto_install-indep:
	jh_classpath --indep --verbose
	# to-do: remove --upstream-version flag once a final release is uploaded
	jh_installlibs \
		--upstream-version="$$(echo $(DEB_VERSION_UPSTREAM) | sed 's/\(~\)\(pre\)\([0-9]\)/.\2\3/')"

override_dh_auto_test-indep:
	# ignore failures with jruby, unfortunately upstream is failing in
	# similar way and this is expected.
	# (e.g. https://travis-ci.org/ruby/psych/jobs/208654321)
	RUBYLIB=$$RUBYLIB:$$PWD/lib jruby -S rake test || true

override_dh_auto_clean-indep:
	-jruby -S rake clean
	-rm -r ./pkg/ ./lib/psych.jar ./tmp/
