#! /usr/bin/make -f

export JAVA_HOME=/usr/lib/jvm/default-java
export JAVA?=${JAVA_HOME}/bin/java

# build flags for hardening
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Current TuxGuitar source version (see misc/build_tuxguitar_from_source.sh)
TGSRCVER := $(shell grep 'CURRENT = new TGVersion' common/TuxGuitar-lib/src/org/herac/tuxguitar/util/TGVersion.java | awk -F '[(,)]' '{ print $$2"."$$3"."$$4 }')

%:
	dh $@ --no-parallel

execute_before_dh_auto_build:
	# Change build version from 9.99-SNAPSHOT to ${TGSRCVER} in config files (see misc/build_tuxguitar_from_source.sh)
	find . \( -name "*.xml" -or -name "*.html" \) -and -type f -exec sed -i "s/9.99-SNAPSHOT/${TGSRCVER}/" '{}' \;

override_dh_auto_configure:
	# Since our build system is maven, give mh_patchpoms something
	# to patch so arch-any builds succeed.
	# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1029476
	ln -s tuxguitar.poms debian/tuxguitar-alsa.poms
	# Without a pom file in the root directory, dh_auto_configure without --buildsystem=maven does not call mh_patchpoms
	dh_auto_configure --buildsystem=maven

override_dh_auto_clean:
	-rm -f debian/tuxguitar-alsa.poms
	dh_auto_clean

override_dh_auto_build-arch:
	dh_auto_build --sourcedirectory=desktop/build-scripts/tuxguitar-linux-swt -- -e verify -Dnative-modules=true

override_dh_auto_build-indep:
	dh_auto_build --sourcedirectory=desktop/build-scripts/tuxguitar-linux-swt -- -e verify -Dnative-modules=false
	docbook-to-man misc/tuxguitar.sgml > debian/tuxguitar.1

override_dh_auto_install:
	dh_auto_install
	-rm -rf ./debian/tuxguitar-alsa/usr/share/maven-repo
