#!/bin/sh

# This script prepares and creates a .tar.gz package of FFC.

# Update version number in ChangeLog
pico -w ChangeLog

# Update version number in constants.py
pico -w src/ffc/common/constants.py

# Update version number in setup.py
pico -w setup.py

# Get the version number
VERSION=`grep 'FFC_VERSION =' src/ffc/common/constants.py | cut -d'"' -f2`

# Verify output\
echo Verifying output
scripts/verify
echo Only version numbers should differ, press return to continue
read
cp src/demo/*.h src/reference

# Run benchmark problem
echo Running benchmark problem
cd src/bench
echo "FFC version $VERSION" >> bench.log
date >> bench.log
echo "" >> bench.log
./bench >> bench.log
cd ../../

# Commit changes to cvs
cvs commit

# Write a message
echo Creating release $VERSION of FFC

# Create the directory
DISTDIR=ffc-$VERSION
echo "Creating directory $DISTDIR"
mkdir $DISTDIR

# Copy files
FILES=`ls | grep -v $DISTDIR`
cp -R $FILES $DISTDIR

# Remove unecessary files
REMOVE1=`find $DISTDIR | grep CVS`
REMOVE2=`find $DISTDIR -name '*~'`
REMOVE="$REMOVE1 $REMOVE2"
rm -rf $REMOVE

# Create the archive
TARBALL="ffc-$VERSION.tar.gz"
echo "Creating arhive: $TARBALL"
tar zcf $TARBALL $DISTDIR

# Remove the directory
echo 'Removing temporary directory'
rm -rf $DISTDIR

# Copy archive and files to web page
scp $TARBALL fenics@fenics.org:www.fenics.org/pub/software/ffc/v0.1
scp ChangeLog fenics@fenics.org:www.fenics.org/pub/software/ffc/
scp TODO fenics@fenics.org:www.fenics.org/pub/software/ffc/

# Update on web server
ssh fenics@fenics.org 'xterm -e emacs -nw www.fenics.org/ffc/index.cpp'
ssh fenics@fenics.org 'xterm -e /home/fenics/local/bin/news'

# Notify ffc-dev of the new version
SUBJECT="Version "$VERSION" of FFC released"
cat ChangeLog | mail -s "$SUBJECT" ffc-dev@fenics.org
