#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_COMPAT=10

export LC_ALL:=C.UTF-8
export
CLASSPATH:=/usr/share/java/xercesImpl.jar:/usr/share/java/ivy.jar:/usr/share/java/junit4.jar


build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	if [ "$(DEB_BUILD_ARCH)" = "armhf" ]; then \
		sed -i -e 's/2\.718281828459045/2\.7182818284590455/' \
			src/test/psylla/operators/exp/general.t.out; \
	fi
	dh_auto_build -- -v \
		-Divy.settings.file=/usr/share/ivy-debian-helper/ivysettings.xml \
		-Divy.default.ivy.user.dir=$(shell pwd)/.ivy \
		-Ddestdir=$(DESTDIR) \
		-Dconfig.docdir=/usr/share/doc \
		-Dconfig.docdir.package=/usr/share/doc/psylla \
		-Dconfig.javadocdir.package=/usr/share/doc/psylla/api \
		-Dconfig.licensedir.package=/usr/share/doc/psylla \
		-Dlinux.flavour=debian \
		build
	# --- end custom part for compiling
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	#dh_auto_test -- -v
	dh_auto_build -- -v \
		-Divy.settings.file=/usr/share/ivy-debian-helper/ivysettings.xml \
		-Divy.default.ivy.user.dir=$(shell pwd)/.ivy \
		-Dlinux.flavour=debian \
		test
endif

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	# Add here commands to clean up after the build process.
	dh_auto_build -- -v clean
	# --- end custom part for cleaning up

	dh_clean

DESTDIR = /usr/src/packages/BUILD/debian/tmp

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package
	# The DESTDIR Has To Be Exactly  /usr/src/packages/BUILD/debian/<nameOfPackage>
	dh_auto_build -- -v \
		-Divy.settings.file=/usr/share/ivy-debian-helper/ivysettings.xml \
		-Divy.default.ivy.user.dir=$(shell pwd)/.ivy \
		-Ddestdir=$(DESTDIR) \
		-Dconfig.docdir=/usr/share/doc \
		-Dconfig.docdir.package=/usr/share/doc/psylla \
		-Dconfig.javadocdir.package=/usr/share/doc/psylla/api \
		-Dconfig.licensedir.package=/usr/share/doc/psylla \
		-Dlinux.flavour=debian \
		install
	mh_installpoms -ppsylla
	mh_linkjars
	ln -s LICENSE $(DESTDIR)/usr/share/doc/psylla/copyright
	dh_install
	# --- end custom part for installing

# Build architecture-independent files here.
binary-indep: build install
	# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
