#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/ant.mk

JAVA_HOME            := /usr/lib/jvm/java-1.6.0-openjdk-amd64
DEB_ANT_CLEAN_TARGET := clean-all
DEB_ANT_BUILD_TARGET := -Ddev.gems=false -DdocsNotNeeded=true \
    -Dshared.lib.dir=/usr/share/java test dist-bin
DEB_JARS             := ant-junit junit4

# must be set to avoid test failures
export BUILDING_JRUBY := true

clean::
	$(RM) lib/ruby/site_ruby/shared/yecht.jar debian/stamp-yecht
	# strange workaround for dpkg-source
	$(RM) bin/jruby

pre-build:: debian/stamp-yecht
debian/stamp-yecht:
	# symlink system yecht-ruby jar into shared directory
	ln -s /usr/share/java/yecht-ruby.jar lib/ruby/site_ruby/shared/yecht.jar
	touch $@

JRUBY_LIB_DIR := $(DEB_DESTDIR)/usr/lib/jruby

install/jruby::
	tar -z -x -f dist/jruby-bin-*.tar.gz --strip 1 -C $(JRUBY_LIB_DIR)
	# Remove all of the VCS directories
	find $(JRUBY_LIB_DIR) -name '.svn'  -delete
	find $(JRUBY_LIB_DIR) -name '.git*' -delete
	find $(JRUBY_LIB_DIR) -name '*.bat' -delete
	# remove extra docs
	$(RM) -r $(JRUBY_LIB_DIR)/docs $(JRUBY_LIB_DIR)/COPYING* $(JRUBY_LIB_DIR)/LICENSE.RUBY
	# remove libjnidispatch.so, to keep the package 
	# architecture-independent; will put it in itw own
	# separate package later on, if need be.
	$(RM) -r $(JRUBY_LIB_DIR)/lib/native
	# Remove all empty directories
	find $(DEB_DESTDIR) -depth -follow -type d -empty -delete

