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

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

# for Java install
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-3.1.jar:/usr/share/java/httpcore.jar:/usr/share/java/httpclient.jar:/usr/share/java/junit4.jar:.

# for Go install
export DH_GOPKG=thrift

# 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:
	# delete symlinks
	#rm -f $(CURDIR)/lib/go/test/gopath/src/github.com
	#rm -f $(CURDIR)/test/go/src/github.com
	# let make clean
	dh_auto_clean
	#jh_clean
	# leftovers
	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
	rm -f $(CURDIR)/config.log
	rm -f $(CURDIR)/lib/java/Makefile $(CURDIR)/lib/js/test/Makefile

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

override_dh_auto_build:
	# symlinks for Go build
	#mkdir -p $(CURDIR)/lib/java/build/lib/
	#mkdir -p $(CURDIR)/lib/go/test/gopath/src/
	#ln -s /usr/share/gocode/src/github.com \
	#	$(CURDIR)/lib/go/test/gopath/src/
	#ln -s /usr/share/gocode/src/github.com \
	#	$(CURDIR)/test/go/src/
	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 $@ --install-layout=deb \
		--parallel
	#dh $@ --with python2,javahelper,ruby --install-layout=deb \
#	dh $@ --with python2,javahelper,golang,ruby --install-layout=deb \
#		--buildsystem=golang --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
