#!/usr/bin/make -f
#
# Sample debian/rules that uses javahelper.
# This file was generated by jh_makepkg and may be used
# without restriction. It was inspired by the dh-make
# sample debian/rules

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
#include /usr/share/cdbs/1/rules/debhelper.mk

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

VER_FULL = $(shell dpkg-parsechangelog | grep '^Version' | cut -d' ' -f2 | cut -f1 -d-)

UPSTREAM_SRC = jmdns-$(VER_FULL)
DEBIAN_SRC_DIR = jmdns-$(VER_FULL)
DEBIAN_SRC_TAR = jmdns_$(VER_FULL).orig.tar.gz
PACKAGE = jmdns

# Put depended upon jars in here
export CLASSPATH=/usr/share/java/junit4.jar:/usr/share/java/easymock.jar

build: build-arch-stamp build-indep-stamp
build-arch: build-arch-stamp
build-arch-stamp:
	dh_testdir
	touch $@

build-indep: build-indep-stamp
build-indep-stamp:
	dh_testdir
	# Build the package
	jh_build jmdns.jar src
	touch $@

clean:
	dh_testdir
	dh_testroot
	jh_build --clean
	dh_clean
	mh_clean
	rm -f build-arch-stamp build-indep-stamp jmdns*.jar

install-indep: build-indep
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

binary-arch: build-arch
	# Java packages are arch: all, nothing to do here

binary-indep: build-indep install-indep
	# Create the package here
	dh_testdir
	dh_testroot
	dh_prep
	dh_install -i
	dh_installdocs -i
	dh_installchangelogs -i CHANGELOG.txt
	dh_javadoc -Nlibjmdns-java -plibjmdns-java-doc -i --sourcedir=src 
	jh_manifest -i
	jh_depends -i
	mh_installpoms -plib$(PACKAGE)-java
	mh_installjar -plib$(PACKAGE)-java -l debian/poms/$(PACKAGE).pom $(PACKAGE).jar 
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

$(UPSTREAM_SRC).zip:
	wget http://voxel.dl.sourceforge.net/sourceforge/jmdns/$@

get-orig-source: $(UPSTREAM_SRC).zip
	unzip -q $(UPSTREAM_SRC).zip -d $(DEBIAN_SRC_DIR)
	# Also remove pre-generated Javadoc
	rm -rf $(UPSTREAM_SRC)/docs/
	# Remove pre-generated jar file:
	rm -rf $(UPSTREAM_SRC)/lib/jmdns.jar
	GZIP="--best --no-name" tar czf $(DEBIAN_SRC_TAR) $(DEBIAN_SRC_DIR)
	rm -rf $(UPSTREAM_SRC)
	rm $(UPSTREAM_SRC).zip

get-orig-pom:
	mkdir -p debian/poms
	wget -O debian/poms/jmdns.pom -U NoAgent-1.0 \
		http://repo1.maven.org/maven2/javax/jmdns/jmdns/$(VER_FULL)/jmdns-$(VER_FULL).pom

binary: binary-indep binary-arch
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install-indep
