#!/bin/sh

preprocess() {
	ruby -r erb -e 'puts ERB.new(ARGF.read).result' $1.erb > $1.tmp
	if [ "$?" != 0 ]; then
		echo ""
		echo "** preprocess failed **"
		echo ""
		exit 1
	else
		mv $1.tmp $1
	fi
}

if [ "$1" == "clean" ];then
	rm -f src/msgpack/type/tuple.hpp
	rm -f src/msgpack/type/define.hpp
	rm -f src/msgpack/zone.hpp
else
	preprocess src/msgpack/type/tuple.hpp
	preprocess src/msgpack/type/define.hpp
	preprocess src/msgpack/zone.hpp
fi
cp -f ../msgpack/sysdep.h          src/msgpack/
cp -f ../msgpack/pack_define.h     src/msgpack/
cp -f ../msgpack/pack_template.h   src/msgpack/
cp -f ../msgpack/unpack_define.h   src/msgpack/
cp -f ../msgpack/unpack_template.h src/msgpack/
cp -f ../test/cases.mpac           test/
cp -f ../test/cases_compact.mpac   test/

sed -e 's/8\.00/9.00/' < msgpack_vc8.vcproj > msgpack_vc2008.vcproj
sed -e 's/9\.00/10.00/' -e 's/msgpack_vc8/msgpack_vc2008/' < msgpack_vc8.sln > msgpack_vc2008.sln

