#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
UPSTREAM_VERSION = $(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/.dfsg$$//')

JAVA_HOME := /usr/lib/jvm/default-java

%:
	dh $@ --buildsystem=ant

override_dh_auto_build:
	dh_auto_build
	pod2man --center='SUNFLOW DOCUMENTATION' \
		--release=$(UPSTREAM_VERSION) \
		debian/sunflow.pod -o debian/sunflow.1

override_dh_auto_install:
	#install/libsunflow-java::
	# If case to avoid build failure when resuming the build
	# at the install step
	if [ ! -f release/sunflow-$(UPSTREAM_VERSION).jar ] ; then \
		mv release/sunflow.jar release/sunflow-$(UPSTREAM_VERSION).jar ; \
	fi
	dh_install -plibsunflow-java release/sunflow-$(UPSTREAM_VERSION).jar usr/share/java
	dh_link -plibsunflow-java usr/share/java/sunflow-$(UPSTREAM_VERSION).jar \
		usr/share/java/sunflow.jar

	#install/sunflow::
	# If case to avoid build failure when resuming the build
	# at the install step
	if [ ! -f release/sunflowGUI-$(UPSTREAM_VERSION).jar ] ; then \
		mv release/sunflowGUI.jar release/sunflowGUI-$(UPSTREAM_VERSION).jar ; \
	fi
	dh_install -psunflow release/sunflowGUI-$(UPSTREAM_VERSION).jar usr/share/java
	dh_link -psunflow usr/share/java/sunflowGUI-$(UPSTREAM_VERSION).jar usr/share/java/sunflowGUI.jar

	# Executable (wrapper)
	install -d debian/sunflow/usr/bin
	install debian/sunflow.wrapper debian/sunflow/usr/bin/sunflow

	# Default configuration
	install -d debian/sunflow/etc
	install -m 644 debian/sunflow.conf debian/sunflow/etc/sunflowrc

	# Blender export script
	install -d debian/sunflow/usr/share/blender/scripts/sunflow
	install -m 644 exporters/blender/sunflow_export.py \
		debian/sunflow/usr/share/blender/scripts/sunflow

	# Desktop file and icons
	install -d debian/sunflow/usr/share/applications
	install -m 644 debian/sunflow.desktop \
		debian/sunflow/usr/share/applications
	install -d debian/sunflow/usr/share/icons/hicolor/scalable/apps
	install -m 644 debian/sunflow.svg \
		debian/sunflow/usr/share/icons/hicolor/scalable/apps

	# Not using python-distutils.mk, calling manually
	dh_python3 /usr/share/blender/scripts/sunflow

	# Javadoc
	mv release/javadoc release/api
	dh_installdocs -plibsunflow-java-doc release/api
