#!/usr/bin/make -f

export DH_RUBY_GEMSPEC=rjb.gemspec

export JAVA_HOME=/usr/lib/jvm/default-java

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

TEST_CLASSES = \
	test/jp/co/infoseek/hp/arton/rjb/Test.class \
	test/jp/co/infoseek/hp/arton/rjb/IBase.class \
	test/jp/co/infoseek/hp/arton/rjb/Base.class \
	test/jp/co/infoseek/hp/arton/rjb/ExtBase.class \
        test/jp/co/infoseek/hp/arton/rjb/Two.class \
        test/jp/co/infoseek/hp/arton/rjb/TwoCaller.class \
        test/jp/co/infoseek/hp/arton/rjb/CallbackTest.class \

override_dh_auto_build: $(TEST_CLASSES) test/jartest.jar test/jartest2.jar
	dh_auto_build -O--buildsystem=ruby

test/jp/co/infoseek/hp/arton/rjb/%.class: test/%.java
	mkdir -p $$(dirname $@)
	LC_ALL=C.UTF-8 javac -classpath test -d test $<

test/jartest.jar: test/JarTest.java
	mkdir -p test/jartest
	LC_ALL=C.UTF-8 javac -d test/jartest $<
	jar -cvf $@ -C test/jartest jp/co/infoseek/hp/arton/rjb/JarTest.class

test/jartest2.jar: test/JarTest2.java
	mkdir -p test/jartest2
	LC_ALL=C.UTF-8 javac -classpath test/jartest -d test/jartest2 $<
	jar -cvf $@ -C test/jartest2 jp/co/infoseek/hp/arton/rjb/JarTest2.class

rjb-global.rake: rjb.rake
	sed -e '$$i $$spec = spec' $< > $@

rjb.gemspec: rjb-global.rake
	ruby -e 'load "rjb-global.rake"; File.open("rjb.gemspec", "w") { |f| f.write $$spec.to_ruby };'

override_dh_auto_install: rjb.gemspec
	LC_ALL=C.UTF-8 dh_auto_install -O--buildsystem=ruby

override_dh_clean:
	dh_clean -O--buildsystem=ruby
	rm -rf test/jp test/jartest test/jartest2
	rm -f rjb-global.rake rjb.gemspec
