#! /bin/sh
# $Id: make-current,v 1.33 1998/06/04 20:03:09 zeller Exp $
# Create DDD release-of-the-day.  
# If `-final' is given, make an official release.

# Copyright (C) 1997-1998 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 <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').
# If `-final' is given, create an official release.

# Check args
final=false;
case "$0" in
  *final*) final=true;;
esac
if [ "$1" = "-final" ]; then
  final=true;
fi

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

if $final; then
  target=`pwd`
else
  target=/ftp/pub/local/softech/ddd/current
fi

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

$install || exit 0; # No installation required

if $final; then
  :
else
  exec > $target/.current.log 2>&1 < /dev/null
fi

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

if $final; then
  # This is a final release; use the expiration date from the file.
  eval `co -p $CVSROOT/ddd/ddd/configure.in 2> /dev/null | \
        egrep '^(EXPIRES|VERSION)='`
  expires=$EXPIRES
  date=$VERSION
else
  # 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=$year-09-01;;
    08) expires=$year-10-01;;
    09) expires=$year-11-01;;
    10) expires=$year-12-01;;
    11) expires=$next_year-01-01;;
    12) expires=$next_year-02-01;;
  esac
fi

# 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...'; rm -fr $tmpdir; echo done." 0

# Go ahead...
if [ "$expires" = "" ]; then
  expires_msg=""
else
  expires_msg=" (expires $expires)"
fi
echo "Creating ddd-$date.tar.gz$expires_msg..."
echo "Target is $target"
echo "Working directory is $tmpdir"
set -x
mkdir $tmpdir
cd $tmpdir

# Create a DDD subdirectory and make its group `ddd'
mkdir ddd
chgrp ddd ddd
chmod g+s ddd

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

if $final; then
  :
else
# Override 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
fi

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

# Create an empty `ddd/Makedeps' such that old MAKEs won't fail.
touch ddd/Makedeps

# Create distribution stuff.
(cd libiberty && test -f Makefile && make)
(cd ddd; make Makefile)
(cd ddd; make diststuff)

# Add a RELEASE tag
if $final; then
  echo "ddd-$date: released `date`" > ./.RELEASE
  cvs commit -m"ddd-$date released" .RELEASE
fi

# Create distribution.
make dist

if [ -f ddd-$date.tar.gz ]; then
  if $final; then
    # Tag our CVS files
    tag=DDD_`echo $date | sed 's/[^a-zA-Z0-9]/_/g'`
    cvs tag -F $tag .
  fi

  # Move dist file into target area
  rm -f $target/ddd-*.tar.gz
  mv ddd-$date.tar.gz ddd-$date-pics.tar.gz $target

  if $final; then
    :
  else
    # Copy the ChangeLog and NEWS/BUGS/TODO files
    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
  fi
  echo "Creating ddd-$date.tar.gz$expires_msg...done."
  echo "make-current[$$]: done at `date`"
else
  echo "make-current[$$]: failed at `date`"
  Mail -s "make-current failed at `date`" ddd@ips.cs.tu-bs.de \
   < $target/.current.log
fi

# That's all, folks!
exit 0
