# This makefile allows build tarball distribution for utt.

#
# Some variables
#

DIR=$(shell pwd)

# Directory with utt binaries
ifndef UTT_DIST_DIR
	UTT_DIST_DIR=${DIR}
endif

# Where put result
ifndef UTT_DIST_OUTPUT
	UTT_DIST_OUTPUT=${DIR}
endif

# Common info about version and release
_UTT_VER=$(shell cat ../common/version.def)
_UTT_REL=$(shell cat ../common/release.def)

# Temp vars
_TARBALL_ROOT=$(DIR)/utt-$(_UTT_VER).$(_UTT_REL)
_TAR_FILE_NAME=utt.$(_UTT_VER)_$(_UTT_REL).tar.gz

#defualt task
.PHONY: default
default:
	@echo Build directory: ${UTT_DIST_DIR}
	@echo Output directory for tarball: ${UTT_DIST_OUTPUT}
	mkdir -p ${_TARBALL_ROOT}
	cp -fr ${UTT_DIST_DIR}/* ${_TARBALL_ROOT}
	@# we add some extra files
	@# config files
	mkdir -p ${_TARBALL_ROOT}/cnf
	mv ${_TARBALL_ROOT}/etc/utt/*.conf ${_TARBALL_ROOT}/cnf/
	${DIR}/../common/prepare_conf.sh ${_TARBALL_ROOT}/cnf ${_TARBALL_ROOT}/etc/utt \~\\\/.local
	rm -rf ${_TARBALL_ROOT}/cnf
	cp ./INSTALL ${_TARBALL_ROOT}/
	cp ./Makefile.tarball ${_TARBALL_ROOT}/Makefile
	cp ../files/* ${_TARBALL_ROOT}/


	tar -czf ${UTT_DIST_OUTPUT}/${_TAR_FILE_NAME} utt*

	rm -rf ${_TARBALL_ROOT}

