#! /bin/sh
# $Id: make-current,v 1.14 1997/05/07 10:20:05 zeller Exp $
# Create DDD release-of-the-day

# Copyright (C) 1997 Technische Universitaet Braunschweig, Germany.
# Written by Andreas Zeller <zeller@ips.cs.tu-bs.de>.
# 
# This file is part of DDD.
# 
# DDD is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# DDD is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with ICE -- see the file COPYING.
# If not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# 
# DDD is the data display debugger.
# For details, see the DDD World-Wide-Web page, 
# `http://www.cs.tu-bs.de/softech/ddd/',
# or send a mail to the DDD developers at `ddd@ips.cs.tu-bs.de'.

# This script checks out the current DDD development tree, as
# stored in CVS, and creates a DDD release-of-the-day (`ROTD').

# Setup environment
tmpdir=$HOME/tmp
CVSROOT=/usr/local/share/CVS; export CVSROOT
PATH=/usr/local/bin:/usr/local/gnubin:$PATH; export PATH
target=/ftp/pub/local/softech/ddd/current

# Check whether the ChangeLog file has changed (i.e. we need a new ROTD)
install=false
/usr/local/gnubin/test $CVSROOT/CVSROOT/ddd-log -nt $target/ChangeLog.tail \
    && install=true
/usr/local/gnubin/test ! -f $target/ChangeLog.tail \
    && install=true

if [ $install = false ]; then
    exit 0;			# No installation required
fi

exec > $target/.current.log 2>&1 < /dev/null

echo make-current[$$]: start at `date`

# Fetch the date in ISO 8601 YYYY-MM-DD format.
year=`date +"%Y"`
month=`date +"%m"`
day=`date +"%d"`
date=$year-$month-$day

# Let this release expire in 30-60 days.  It is unlikely we won't make
# any changes until then.
next_year=`expr $year + 1`
case $month in
01) expires=$year-03-01;;
02) expires=$year-04-01;;
03) expires=$year-05-01;;
04) expires=$year-06-01;;
05) expires=$year-07-01;;
06) expires=$year-08-01;;
07) expires=$next_09-01;;
08) expires=$next_10-01;;
09) expires=$next_11-01;;
10) expires=$next_12-01;;
11) expires=$next_year-01-01;;
12) expires=$next_year-02-01;;
esac

# We are working in /tmp/ddd.  In case of trouble, clean up.
trap "exit 1" 1 2 15
trap "set +x; echo -n 'Cleaning up...'; cd $tmpdir; rm -fr ddd; echo done." 0

# Go ahead...
echo "Creating ddd-$date.tar.gz (expires $expires)..."
set -x
cd $tmpdir

# Get the DDD development tree out of CVS.
cvs checkout ddd
cd ddd

# Set the ROTD version.
sed 's/VERSION=.*/# &/
s/EXPIRES=.*/# &/
/^# VERSION=/a\
VERSION='$date'

/^# EXPIRES=/a\
EXPIRES='$expires'

' < ddd/configure.in > ddd/configure.in~
mv ddd/configure.in~ ddd/configure.in

# Configure the package.
ln -s $CVSROOT/CVSROOT/ddd-log ChangeLog
autoconf
(cd ddd && autoconf)
(cd librx && autoconf)
(cd termcap && autoconf)
sh ./configure --x-libraries=/usr/X11R5/lib --x-includes=/usr/X11R5/include -v

# Create distribution stuff.
touch ddd/Makedeps
(cd libiberty; make)
(cd librx; make)
(cd ddd; make Makefile)
(cd ddd; make diststuff)

# Create distribution.
make dist

if [ -f ddd-$date.tar.gz ]; then
    # Move dist file into FTP area
    rm -f $target/ddd-*.tar.gz
    mv ddd-$date.tar.gz ddd-$date-pics.tar.gz $target
    commits=200
    log=$CVSROOT/CVSROOT/ddd-log
    line=`grep -n '^\*\*\*' $log | tail -$commits | head -1 | cut -d: -f1`
    tail +$line $log > $target/ChangeLog.tail
    cp -p NEWS BUGS TODO $target
    echo "Creating ddd-$date.tar.gz (expires $expires)...done."
    echo make-current[$$]: done at `date`
fi

# That's all, folks!
exit 0
