#!/usr/bin/make -f
# -*- makefile -*-

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

export CLASSPATH=/usr/share/java/maven-ant-tasks.jar:/usr/share/java/commons-codec.jar:/usr/share/java/commons-logging.jar:/usr/share/java/slf4j-simple.jar:/usr/share/java/slf4j-api.jar:/usr/share/java/servlet-api-2.5.jar:/usr/share/java/httpcore.jar:/usr/share/java/httpclient.jar:/usr/share/java/junit4.jar:.

# for Ruby install
export DESTDIR=$(CURDIR)/debian/tmp/
export JAVA_PREFIX=/usr/share/java/
export PERL_PREFIX=/usr/
export INSTALLDIRS=vendor

export QT_SELECT=qt5

RUBY_LIBDIR := $(shell ruby -rrbconfig -e'print RbConfig::CONFIG["vendordir"]')

override_dh_auto_clean:
	dh_auto_clean
	jh_clean
	rm -f $(CURDIR)/thrift.jar
	rm -f $(CURDIR)/lib/cpp/test/tests.xml \
		$(CURDIR)/test/gen-html/ThriftTest.html \
		$(CURDIR)/test/gen-html/index.html \
		$(CURDIR)/test/gen-html/style.css
	rm -rf $(CURDIR)/lib/py/thrift.egg-info
	rm -f $(CURDIR)/lib/haxe/test/Makefile \
		$(CURDIR)/test/py.twisted/_trial_temp/test.log \
		$(CURDIR)/hs_err_pid*.log

override_dh_auto_configure:
	dh_auto_configure -- --with-cpp --with-c_glib --with-php \
		--with-perl --with-python --with-java \
		--without-nodejs --without-erlang --without-lua \
		--without-go --with-ruby \
		--with-qt4=no --with-qt5=yes \
		--disable-tutorial

override_dh_auto_build:
	mkdir -p $(CURDIR)/lib/java/build/lib/
	dh_auto_build --parallel
	jh_build thrift.jar $(CURDIR)/lib/java/src/

override_dh_auto_install:
	dh_auto_install
	jh_installlibs -plibthrift-java thrift.jar
#	jh_installjavadoc
	jh_depends

	find $(CURDIR)/debian/tmp/ -name \*.la -exec rm {} \;

override_dh_auto_test:
	dh_auto_test --max-parallel=1

override_dh_strip:
	dh_strip -plibthrift-0.9.3 --dbg-package=libthrift-0.9.3-dbg
	dh_strip -plibthrift-c-glib0 --dbg-package=libthrift-c-glib0-dbg
	dh_strip -ppython-thrift --dbg-package=python-thrift-dbg
	dh_strip

%:
	dh $@ --with python2,javahelper,ruby --install-layout=deb --parallel
#	dh $@ --with python2,javahelper --install-layout=deb --parallel

.PHONY: override_dh_auto_clean override_dh_auto_configure \
	override_dh_auto_install override_dh_auto_test override_dh_strip
