#!/usr/bin/make -f
#export DH_VERBOSE = 1

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
  CFLAGS = -O0 -g
endif

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export QT_SELECT = 5

_DEBIAN_VERSION=$(shell dpkg-parsechangelog | grep '^Version: .*' | grep -o ' .*' | grep -o '[0-9].*')
_VERSION=$(shell echo $(_DEBIAN_VERSION) | cut -d- -f 1)
_PKGNAME=$(shell dpkg-parsechangelog | head -n 1 | cut -d ' ' -f 2)
JAVA_HOME=/usr/lib/jvm/default-java
CLASSPATH=.
TIDY_LIB_DIR=/usr/lib/nixnote2/tidy

# https://github.com/aperezdc/cuacfmeego/blob/master/debian/rules
QMAKE_OPTIONS = -makefile -nocache

ifneq (,$(filter debug,$(DEB_BUILD_OPTIONS)))
  QMAKE_OPTIONS += CONFIG*=debug CONFIG-=release
  CFLAGS = -O0 -g
else
  QMAKE_OPTIONS += CONFIG*=release CONFIG-=debug
endif

# Teach qmake about CFLAGS, poor qmake doesn't know about it...
#
QMAKE_OPTIONS += QMAKE_CXXFLAGS_RELEASE='$(CFLAGS)' \
				QMAKE_CXXFLAGS_DEBUG='$(CFLAGS)' \
				QMAKE_CFLAGS_RELEASE='$(CFLAGS)' \
				QMAKE_CFLAGS_DEBUG='$(CFLAGS)' \
				QMAKE_STRIP=: \
				QMAKE_RPATHDIR+=${TIDY_LIB_DIR}

# main packaging script based on dh7 syntax
%:
	echo running main packaging script: $@
	dh $@ --buildsystem=qmake --with javahelper

override_dh_auto_configure:
	env PKG_CONFIG_PATH=${TIDY_LIB_DIR}/pkgconfig qmake $(QMAKE_OPTIONS)


# build java jar file from source, discard upstream jar file
override_jh_build:
	echo override_jh_build - skip
	# turned off for now; should not be needed
	#jh_build -N --main=cx.fbn.encrypt.Crypto --javacopts="-source 1.6 -target 1.6"

# note: this tried to copy changelog.txt which doesn't exist; off for now
override_dh_installchangelogs:
	echo override_dh_installchangelogs - skip

# this tried to delete debian/nixnote2/usr/local/bin/nixnote2 which doesn't exist
override_dh_usrlocal:
	echo override_dh_usrlocal - skip

# due to order issue, translations don't get installed by qmake
override_dh_clean:
	dh_clean install translations/*.qm