#!/usr/bin/make -f
# -*- makefile -*-

VERSION_STRING=12.1
VERSION_SHORT_STRING=12_1
CONTENT_DIR="Umlet"

JAVADIR=/usr/share/java
export CLASSPATH=$(JAVADIR)/ecj.jar:$(JAVADIR)/batik-all.jar:$(JAVADIR)/fop.jar:$(JAVADIR)/log4j-1.2.jar:$(JAVADIR)/net.sourceforge.jlibeps.jar:$(JAVADIR)/gnumail.jar:$(JAVADIR)/itext5.jar:$(JAVADIR)/jsyntaxpane.jar:$(JAVADIR)/rsyntaxtextarea.jar:$(JAVADIR)/autocomplete.jar:$(JAVADIR)/javaparser.jar:$(JAVADIR)/commons-io-java
export JAVA_HOME=/usr/lib/jvm/default-java

#export DH_VERBOSE=1
get-orig-source:
	wget http://www.umlet.com/umlet_$(VERSION_SHORT_STRING)/umlet_$(VERSION_STRING).zip
	unzip umlet_$(VERSION_STRING).zip
		cd $(CONTENT_DIR) ; \
		rm -f umlet.jar Umlet.exe sourcefiles/exe/Umlet/Umlet.exe; \
		# remove jar files in lib \
		rm -f lib/*.jar; \
		# _begin_ for version 12.1 additionally run \
		cd sourcefiles ; \
		svn export --force  "http://umlet.googlecode.com/svn/tags/2013-08-29 UMLet v12.1/BaseletElements/src" ; \
		# _end_ for version 12.1 
	mv $(CONTENT_DIR) umlet-$(VERSION_STRING).orig
	tar -c umlet-$(VERSION_STRING).orig | gzip --best > umlet_$(VERSION_STRING).orig.tar.gz
	rm -rf umlet-$(VERSION_STRING).orig


build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	test -d eclipse-plugin-source || mkdir eclipse-plugin-source
	# move unused source code out of the way
	mv sourcefiles/src/com/baselet/plugin/ eclipse-plugin-source/ || true
	mv sourcefiles/src/com/baselet/gui/eclipse/ eclipse-plugin-source/ || true
	jh_build --no-javadoc -o"-encoding utf8"  --main=com.baselet.control.Main umlet.jar sourcefiles/src

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	# move unused source code back in
	mv eclipse-plugin-source/plugin/ sourcefiles/src/com/baselet/ || true
	mv eclipse-plugin-source/eclipse/ sourcefiles/src/com/baselet/gui/ || true
	rmdir eclipse-plugin-source  || true
	rm -f umlet.jar
	jh_build --clean
	jh_clean
	dh_clean 

binary-indep: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples
	dh_install -XThumbs.db
	dh_installmenu
	dh_installman debian/umlet.1
	jh_manifest
	# comment - currently jarwrapper does not work
	# dh_link usr/share/java/umlet.jar usr/bin/umlet
	jh_depends
	# comment - currently jarwrapper does not work
	# jh_exec -v
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: build
# We have nothing to do

binary: binary-indep binary-arch
.PHONY: build build-arch build-indep clean clean1 binary-indep binary-arch binary install orig get-orig-source

