#!/bin/sh
#
# Make a release tarball from current head.  If you give an argument, it
# will override the version normally taken from ../VERSION.  Produces
# a file named ntpsec-$V.tar.gz.  The name of this tarball is echoed to
# standard output as part of the success message.
#
# Do not try running this outside of devel/
#
# *Do* test-build before running it.

if [ `basename $PWD` != devel ]
then
    echo "You are doomed to fail."
    exit 1
fi

set -e

if [ "$1" != "" ]
then
    V=$1
else
    V=`cat ../VERSION`
fi

# Build the tarball
rm -fr .tmp
(cd ..; git ls-files; find build -print | grep '\.[0-9]$') >MANIFEST
(cd ..; tar --transform="s:^:ntpsec-${V}/:" -T devel/MANIFEST -czf ntpsec-${V}.tar.gz)
rm MANIFEST
mv ../ntpsec-${V}.tar.gz .


# Test-build from it, bailing out if we fail
set -e
mkdir .tmp
cd .tmp
tar -xzf ../ntpsec-${V}.tar.gz
cd ntpsec-${V}
./waf configure --refclock=all --enable-doc
./waf build
cd ../..
rm -fr .tmp

echo ""
echo "Success: " ntpsec-${V}.tar.gz
# end

