#!/usr/bin/make -f
# export DH_VERBOSE=1
export JAVA_HOME=/usr/lib/jvm/default-java
export CLASSPATH=/usr/share/java/bcel.jar
PKD  = $(abspath $(dir $(MAKEFILE_LIST)))
VER = $(shell dpkg-parsechangelog -l$(PKD)/changelog -SVersion | cut -d- -f1)
PKG = libcodesize-java
UURL =  https://github.com/robo-code/codesize.git
COMMIT = 2d99a8bbcda84cc5e87bfb58fc98f36ffb6269f7

%:
	dh $@ --parallel --with javahelper,jh_maven_repo_helper

override_jh_installlibs:
	jh_installlibs codesize.jar --upstream-version=1.2-SNAPSHOT

.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 $(COMMIT) \
	&& for F in $$(git ls-tree -r --name-only HEAD); \
	do touch --no-dereference -d "$$(git log -1 --format="%ai" -- "$$F")" "$$F"; done \
	&& git log --pretty --numstat --summary | git2cl > ChangeLog \
	&& $(RM) -r -v \
		.git/
	@echo "# Packing..."
	find -L "$(PKG)-$(VER)" -xdev -type f -print | sort \
	| XZ_OPT="-6v" tar -caf "$(PKG)_$(VER).orig.tar.xz" -T- --owner=root --group=root --mode=a+rX \
	&& $(RM) -r "$(PKG)-$(VER)"

