#!/bin/bash

if [[ $# -eq 1 ]]; then
  name=$1
elif [[ $# -ne 0 ]]; then
  echo "usage: $0 [release-name]"
  exit 2
else
  # Default the name to the svn revision
  svnRevision=$(svn info | grep ^Revision: | awk '{print $2}')
  name=r${svnRevision}
fi

name=qpid-cppclient-$name
dir=build/$name

if [[ -d $dir ]]; then
  echo "$dir already exists"
  exit 2
fi

mkdir $dir

#
# Copy over libs.
#
mkdir $dir/lib
cp \
  build/apr-release/lib/libqpid_client.so.1.0 \
  build/apr-release/lib/libqpid_common.so.1.0 \
  $dir/lib
cp -r ~/local/apr-1.2.7 $dir/lib
cp -r ~/local/boost-1.33.1 $dir/lib

#
# Copy over headers.
#

cp -r src $dir/include
cp build/gen/qpid/framing/*.h $dir/include/qpid/framing
# remove .svn directories
find $dir/include -type d -name .svn | xargs rm -r
# remove .cpp source files
find $dir/include -type f -name \*.cpp | xargs rm

#
# Copy over examples.
#
mkdir $dir/examples
cp test/client/*.cpp $dir/examples
cp test/client/Makefile.cppclient.examples $dir/examples/Makefile

#
# Build tarball
#
cd build
tar -cvjf $name.tar.bz2 $name
