#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

export JAVA_HOME=/usr/lib/jvm/default-java
export LC_ALL=C.UTF-8

%:
	dh $@

override_dh_clean:
	dh_clean
	# Removing the help/ folder that was put into resources/
	$(RM) -rf resources/help/
	# Putting gradle file back in place, removing Maven's pom.
	if [ -e buildUpstream.gradle ] ; then mv buildUpstream.gradle build.gradle ; fi
	$(RM) pom.xml

override_dh_auto_configure:
	# Putting help folder inside resources so that it enters the jar.
	cp -a help/help/ resources/
	# Putting gradle stuff out of the way and placing pom.xml at root, with a
	# hack to put the package version number inside the pom.
	mv build.gradle buildUpstream.gradle
	sed 's/\(VERSION_PACKAGE\)/\1$(DEB_VERSION_UPSTREAM)/; s/VERSION_PACKAGE\(.*\)+dfsg[0-9]*/\1/' debian/pom.xml > pom.xml
	dh_auto_configure

override_dh_auto_install:
	dh_auto_install
	# Using imagemagick to resize the icon.
	mkdir -p debian/$(DEB_SOURCE)/usr/share/icons/hicolor/64x64/apps/
	convert resources/images/JalviewLogo_big.png -resize 64x64\! debian/$(DEB_SOURCE)/usr/share/icons/hicolor/64x64/apps/jalview-icon.png
	# Calling javahelper to put the built jar in the right place.
	jh_installlibs
	jh_manifest
	jh_depends

override_dh_fixperms:
	# Setting the packaged example file as not executable.
	chmod a-x debian/$(DEB_SOURCE)/usr/share/doc/jalview/examples/uniref50.fa
	dh_fixperms
