#!/usr/bin/env bash

# Copyright (C) 2013 Preferred Infrastructure and Nippon Telegraph and Telephone Corporation.

RUBY="ruby"

function r() {
	echo "$@"
	"$@"
}

function preprocess() {
	file="$1"
	out="$(dirname "$file")/$(basename "$file" mpl)"
	r "$RUBY" -I. mplex -rmpl "$file" -o "$out"
	if [ "$?" != 0 ]; then
		echo ""
		echo "** preprocess failed **"
		echo ""
		exit 1
	fi
}

if [ "$1" == "clean" ];then
	rm -f src/jubatus/msgpack/rpc/caller.h
	rm -f src/cclog/cclog.h
else
	preprocess src/jubatus/msgpack/rpc/caller.hmpl
	preprocess src/cclog/cclog.hmpl
fi

