#!/bin/bash

BASEDIR=`dirname $0`/../..
RELEASE=""
DIRS="\
	krb5 \
	openldap \
	centutils \
	dcerpc \
	domainjoin \
	eventlog \
	libgss \
	libiconv \
	libkeytab \
	librpc \
	libsmbclient \
	libunistr \
	lsass \
	netlogon \
	npcmuxer \
	build \
	config \
	packaging \
	pstore \
	sqlite \
	lwdns \
	"

. ${BASEDIR}/packaging/scripts/functions
VERSION=$(get_lwopen_version)
if [ "x$1" = "xrelease" ]; then
	RELEASE="-release"
fi

TARGET=likewise-open-$VERSION$RELEASE
/bin/rm -rf $BASEDIR/../$TARGET || exit 1
mkdir $BASEDIR/../$TARGET || exit 1

for dir in ${DIRS}; do
	echo "Copying $dir..."
	rsync -a --exclude=.git* --exclude=.svn --exclude=*~ --exclude=*bak \
		$BASEDIR/$dir $BASEDIR/../$TARGET/ || exit 1
done

for file in LICENSE Build.sh Makefile Configure.sh autogen.sh; do
	cp -p $file $BASEDIR/../$TARGET/ || exit 1
done

cd $BASEDIR/..

find $TARGET -name "*.sh" | xargs chmod u+x
(cd $TARGET && ./autogen.sh)

tar cf - $TARGET | gzip -9 > likewise-open-$VERSION.tar.gz
[ "$TARGET" != "/" ] && /bin/rm -rf $TARGET

