#!/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/
	# Removing the file to create .build_properties, and .build_properties itself.
	if [ -e write_build_properties_file.sh ]; then $(RM) write_build_properties_file.sh ; fi
	if [ -e resources/.buildbuild_properties ]; then $(RM) resources/.build_properties ; fi
	# 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 the .build_properties file needed by upstream in the resources.
	sed 's/\(VERSION_NUMBER\)/$(DEB_VERSION)/' debian/write_build_properties_file.sh.in > write_build_properties_file.sh && \
	        chmod a+x write_build_properties_file.sh && \
	        ./write_build_properties_file.sh
	# 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_installexamples:
	dh_installexamples
	# Providing an example at startup instead of having to load it from the Internet.
	cp examples/exampleFile_2_7.jar debian/$(DEB_SOURCE)/usr/share/doc/jalview/examples/exampleFile_2_7.jvp

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
