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

#export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

# Referencing the Maven coordinates of the dependencies.
NAGA_COORDINATES = <dependency>\n<groupId>com.google.code</groupId>\n<artifactId>naga</artifactId>\n<version>debian</version>\n</dependency>
CLI_COORDINATES = <dependency>\n<groupId>commons-cli</groupId>\n<artifactId>commons-cli</artifactId>\n<version>debian</version>\n</dependency>
INCHI_COORDINATES = <dependency>\n<groupId>net.sf.jni-inchi</groupId>\n<artifactId>jni-inchi</artifactId>\n<version>debian</version>\n</dependency>

%:
	dh $@ --with javahelper --buildsystem=maven

override_dh_install:
	dh_install
	# Using imagemagick to resize the icon
	mkdir -p debian/jmol/usr/share/icons/hicolor/96x96/apps/
	convert src/org/openscience/jmol/app/images/icon.png -resize 96x96\! debian/jmol/usr/share/icons/hicolor/96x96/apps/jmol-icon.png

execute_before_dh_auto_configure:
	# Putting the Maven coordinates of the dependencies in the upstream template
	# pom file.
	# Also putting the dfsg-stripped upstream version number in the pom.
	# Indicating the path to the source, which is not the standard src/main/java.
	# Indicating the path to the resources, excluding .class files, so that
	# icons, images and translation files are included.
	sed -e 's,\(<dependencies>\),\1\n$(NAGA_COORDINATES)\n$(CLI_COORDINATES)\n$(INCHI_COORDINATES),' \
	    -e 's/\(@version@\)/\1$(DEB_VERSION_UPSTREAM)/; s/@version@\(.*\)+dfsg[0-9]*/\1/' \
	    -e 's|\(</project>\)|<build><sourceDirectory>src</sourceDirectory><resources><resource><directory>src</directory><excludes><exclude>**/*.java</exclude></excludes></resource></resources></build>\1|' \
	    tools/pom.xml.template > pom.xml

override_dh_clean:
	dh_clean
	# Removing the pom.xml file we settled there
	-rm pom.xml
