#!/usr/bin/make -f

export GEM2DEB_TEST_RUNNER = --check-dependencies

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

EXTRA_DEB_BUILD_OPTIONS := bootstrap
bootstrap-psych-jar:
	./debian/bootstrap-psych-jar
	ls -ld lib/psych.jar

ifeq (,$(findstring bootstrap,$(EXTRA_DEB_BUILD_OPTIONS)))
override_dh_auto_build:
	dh_auto_build
	jruby -S rake compile
else
override_dh_auto_build: bootstrap-psych-jar
	dh_auto_build
	RUBYLIB=$$RUBYLIB:$$PWD/lib jruby -S rake compile
endif

override_dh_auto_install:
	dh_auto_install
	cd ./debian/ruby-psych/usr && rm -rf ./bin ./lib/ruby/vendor_ruby/psych.jar
	jh_installlibs

override_dh_auto_test:
	dh_auto_test
	# 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:
	dh_auto_clean
	-jruby -S rake clean
	-rm -r ./pkg/ ./lib/psych.jar ./tmp/
