#!/usr/bin/make -f

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

POM_VERSION          := 1.0-SNAPSHOT
POM_URL              := http://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/pom.xml

# Extract everything after "svn" in DEB_UPSTREAM_VERSION
SVN_EXPORT_DATE      := $(shell echo $(DEB_UPSTREAM_VERSION) | sed 's/.*svn//')

JAVA_HOME            := /usr/lib/jvm/default-java
ANT_HOME             := /usr/share/ant

DEB_JARS             := commons-logging commons-jci-core bcel asm2 asm2-commons asm2-util asm2-tree asm2-analysis

DEB_ANT_BUILD_TARGET := jar javadoc
DEB_ANT_CLEAN_TARGET := clean
DEB_ANT_BUILDFILE    := debian/build.xml
DEB_ANT_ARGS         := -Ddeb.package=$(DEB_SOURCE_PACKAGE) -Ddeb.version=$(DEB_UPSTREAM_VERSION)

binary-post-install/libcommons-javaflow-java::
	mh_installpoms -plibcommons-javaflow-java
	mh_installjar -plibcommons-javaflow-java -l debian/pom.xml build/$(DEB_SOURCE_PACKAGE)-$(DEB_UPSTREAM_VERSION).jar

# Export from SVN and remove externals JAR in lib/
get-orig-source:
	mkdir orig_tmp
	(cd orig_tmp && \
	svn export -r {${SVN_EXPORT_DATE}} \
	http://svn.apache.org/repos/asf/commons/sandbox/javaflow/trunk/ \
	commons-javaflow-$(DEB_UPSTREAM_VERSION) && \
	rm -rf commons-javaflow-$(DEB_UPSTREAM_VERSION)/lib && \
	tar -czf ../../${DEB_SOURCE_PACKAGE}_$(DEB_UPSTREAM_VERSION).orig.tar.gz commons-javaflow-$(DEB_UPSTREAM_VERSION))
	rm -rf orig_tmp

get-orig-pom:
	wget -O debian/pom.xml $(POM_URL)
	perl -p -i -e 's/<version>$(POM_VERSION)/<version>$(DEB_UPSTREAM_VERSION)/' debian/pom.xml
	perl -p -i -e 's/<artifactId>javaflow/<artifactId>$(DEB_SOURCE_PACKAGE)/' debian/pom.xml

