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

#export DH_VERBOSE=1
export JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF8 # otherwise build fails in pbuilder

%:
	dh $@ --with=javahelper

override_dh_auto_clean:
	mkdir --parents build
	quilt push -a || true
	dh_auto_clean
	quilt pop -a || true
	set -e; for i in Jmol/tools; do \
	  test ! -e $$i || find $$i -type l -delete; \
	done
	rm -rf build
	rm -f src/org/jmol/translation/translations.tgz

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

override_dh_installdocs:
	# Run javadoc target manually
	# don't know why, but in June 2022, the package was built *without*
	# applying debian patches, which results in FTBFS by the debian build
	# farm. So, I must enforce the application and removal of patches.
	quilt push -a || true
	ant -Duser.name debian javadoc
	quilt pop -a || true
	mkdir -p debian/libjmol-java-doc/usr/share/doc/libjmol-java/api
	cp -a build/javadoc/* debian/libjmol-java-doc/usr/share/doc/libjmol-java/api
	dh_installdocs

override_dh_auto_build-indep:
	# don't know why, but in June 2022, the package was built *without*
	# applying debian patches, which results in FTBFS by the debian build
	# farm. So, I must enforce the application and removal of patches.
	quilt push -a || true
	dh_auto_build -i
	quilt pop -a || true
