#!/usr/bin/make -f

daemon=tours
component=tours-indexer

#export DH_VERBOSE=1
export DH_OPTIONS=-Pdebian/$(component)
export DEVSCRIPTS_CHECK_DIRNAME_LEVEL=0
export JAVA_HOME=/usr/local/java8
export SBT_OPTS=-Xms512M -Xmx2g -Xss1M -XX:+CMSClassUnloadingEnabled -Dsbt.log.noformat=true -Dsbt.log.format=false -XX:MaxPermSize=384M -Dsbt.ivy.home=${HOME}/.ivy2/ -Divy.home=${HOME}/.ivy2/ -Dsbt.boot.directory=${HOME}/.sbt/boot/

LIBDIR=debian/$(component)/usr/lib/yandex/$(component)/lib
CONFDIR=debian/$(component)/etc/yandex/$(component)
BINDIR=debian/$(component)/usr/bin

binary-indep: install
	@echo "====	Building the component ..."
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	@echo "====	Done."

build:
	@echo "====	Rebuilding sources ..."
	dh_testdir
	(cd .. && sbt "indexer/copyDependencies")

install:
	@echo "====	Installing into temporary folder ..."
	dh_testroot
	dh_testdir
	dh_installdirs
	dh_installchangelogs
	
	mkdir -p $(LIBDIR)
	cp target/scala-2.11/lib/*.jar $(LIBDIR)

	mkdir -p $(BINDIR)
	cp assembly/deb/*.sh $(BINDIR)
	chmod +x $(BINDIR)/*

	mkdir -p $(CONFDIR)
	mkdir -p debian/$(component)/etc/monrun/conf.d/
	cp assembly/deb/ulimit.conf $(CONFDIR)
	cp assembly/deb/monrun.conf debian/$(component)/etc/monrun/conf.d/$(component).conf

	dh_installinit -r --no-start --name=$(component)
	dh_installlogrotate --name=$(component)
	dh_install --sourcedir=debian/$(component)

clean:
	@echo "====	Cleaning folders... "
	dh_testroot
	dh_testdir
	(cd .. && sbt "clean")
	-rm -f `find . -name "*~"`
	-rm -rf build debian/$(component) debian/tmp debian/files* debian/substvars debian/debhelper.log

binary-arch:

binary: binary-indep

.PHONY: binary binary-arch binary-indep clean
