#!/usr/bin/make -f

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

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --with javahelper --with python3

override_dh_auto_build:
	dh_auto_build -- package javadoc:jar javadoc:aggregate -Pfull-build
	
	# Build Python Bindings
	cd zookeeper-contrib/zookeeper-contrib-zkpython && \
	        python3 src/python/setup.py build --build-base=$(CURDIR)/build

override_dh_auto_install:
	dh_auto_install -- -Pfull-build

override_dh_install:
	# Installing the Python artifacts in debian/tmp before calling dh_install
	cd zookeeper-contrib/zookeeper-contrib-zkpython && \
	        python3 src/python/setup.py build --build-base=$(CURDIR)/build \
	                install --root=$(CURDIR)/debian/tmp --install-layout=deb ;\
	
	dh_install

#ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
## Limit architectures which execute tests as some
## non x86 archs can be a bit racey.
#TEST_ARCH=i386 amd64
#ifneq (,$(findstring $(DEB_BUILD_ARCH), $(TEST_ARCH)))
#TEST_JARS=jline log4j-1.2 xercesImpl xmlParserAPIs netty slf4j-api slf4j-log4j12
#override_dh_auto_test-arch:
#	# C testing starts/stops zookeeper
#	# this ensures that all the right classes are found
#	for jar in $(TEST_JARS); do \
#		ln -sf /usr/share/java/$$jar.jar build/lib/$$jar.jar; \
#	done;
#	# Execute multi-threaded test suite
#	# Disable on Ubuntu and Debian due to glibc 2.17 incompatibility
#	# https://issues.apache.org/jira/browse/ZOOKEEPER-1646
#	if ! dpkg-vendor --derives-from debian; then \
#		$(MAKE) -C src/c zktest-mt; \
#		cd src/c && ./zktest-mt; \
#	fi;
#endif
#endif

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build
	find . -name "*.jar" -delete
	-rm zookeeper-client/zookeeper-client-c/generated/*
	[ ! -f zookeeper-client/zookeeper-client-c/Makefile ] || $(MAKE) -C zookeeper-client/zookeeper-client-c distclean
	-rm -rf zookeeper-client/zookeeper-client-c/Makefile.in
	-rm -rf zookeeper-client/zookeeper-client-c/aclocal.m4
	-rm -rf zookeeper-client/zookeeper-client-c/autom4te.cache
	-rm -rf zookeeper-client/zookeeper-client-c/compile
	-rm -rf zookeeper-client/zookeeper-client-c/config.guess
	-rm -rf zookeeper-client/zookeeper-client-c/config.sub
	-rm -rf zookeeper-client/zookeeper-client-c/configure
	-rm -rf zookeeper-client/zookeeper-client-c/ltmain.sh
	-rm -rf zookeeper-client/zookeeper-client-c/TEST-*

override_dh_installinit:
	dh_installinit --name=zookeeper
