#!/usr/bin/make -f

#DH_VERBOSE = 1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export PYBUILD_NAME = avro

export LC_ALL=C.UTF-8
export JAVA_HOME=/usr/lib/jvm/default-java

# The original sources have to be preprocessed by ant before we
# we can use them to actually build
export PYBUILD_BEFORE_CONFIGURE_python2 = ant build
py2srcdir=lang/py
py2blddir=lang/py/build

py2dir=$(py2blddir)

clean: py2dir=$(py2srcdir)
%:
	PYBUILD_DISABLE_python3=1               \
	dh $@                                   \
		--with python2                  \
		--buildsystem=pybuild           \
		--sourcedirectory=$(py2dir)     \
		--no-package=python3-avro
	PYBUILD_DISABLE_python2=1               \
	dh $@                                   \
		--with python3                  \
		--buildsystem=pybuild           \
		--sourcedirectory=lang/py3      \
		--no-package=python-avro

# This is necessary because there's no "dh configure" to allow us
# to simply set a target-specific variable like was done for "clean"
override_dh_auto_configure:
	PYBUILD_DISABLE_python3=1               \
	dh_auto_configure                       \
		--sourcedirectory=$(py2srcdir)  \
		--package=python-avro
	PYBUILD_DISABLE_python2=1               \
	dh_auto_configure                       \
		--sourcedirectory=lang/py3      \
		--package=python3-avro

override_dh_install:
# Only keep /usr/bin/avro that is provided by the python3 package
	rm -f debian/python-avro/usr/bin/avro
	find debian/ -name "*LICENSE*" -delete
	dh_install

override_dh_auto_clean:
	dh_auto_clean
# The python3 package doesn't clean up after itself properly
	$(RM)						\
		lang/py3/README.txt			\
		lang/py3/avro/HandshakeRequest.avsc	\
		lang/py3/avro/HandshakeResponse.avsc	\
		lang/py3/avro/VERSION.txt		\
		lang/py3/avro/tests/interop.avsc
