#!/usr/bin/make -f
export JAVA_HOME=/usr/lib/jvm/default-java

UURL = https://github.com/fusesource/hawtjni.git
PKD := $(abspath $(dir $(MAKEFILE_LIST)))
PKG := hawtjni
VER := $(shell dpkg-parsechangelog -l$(PKD)/changelog -SVersion | cut -d- -f1)


%:
	dh $@ --with javahelper --with maven-repo-helper

override_dh_auto_build:
	jh_build hawtjni-runtime.jar hawtjni-runtime/src/main/java


.PHONY: get-orig-source
## http://wiki.debian.org/onlyjob/get-orig-source
get-orig-source: $(PKG)_$(VER).orig.tar.xz
	@

$(PKG)_$(VER).orig.tar.xz:
	@echo "# Cloning upstream git repository..."
	git clone $(UURL) $(PKG)-$(VER)
	@echo "# Clean-up..."
	cd $(PKG)-$(VER) \
	&& git checkout -b debiansource hawtjni-project-$(VER) \
	&& echo "# Setting times..." \
	&& for F in $$(git ls-tree -r --name-only HEAD); \
	do touch --no-dereference -d "$$(git log -1 --format="%ai" -- "$$F")" "$$F"; done \
	&& $(RM) -r \
		.git
	@echo "# Packing..."
	find -L "$(PKG)-$(VER)" -xdev -type f -print | sort \
	| XZ_OPT="-6v" tar -caf "$(PKG)_$(VER)$(DTYPE).orig.tar.xz" -T- --owner=root --group=root --mode=a+rX \
	&& $(RM) -r "$(PKG)-$(VER)"
