#! /bin/sh
# $Id: make-patch 6884 2008-03-09 20:42:06Z apg $
# Create DDD patch between two releases.

# Copyright (C) 2000 Universitaet Passau, Germany.
# Written by Andreas Zeller <zeller@gnu.org>.
# 
# 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 3 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 DDD -- see the file COPYING.
# If not, see <http://www.gnu.org/licenses/>.
# 
# DDD is the data display debugger.
# For details, see the DDD World-Wide-Web page, 
# `http://www.gnu.org/software/ddd/',
# or send a mail to the DDD developers <ddd@gnu.org>.

# This script checks out two DDD development trees, as stored in CVS,
# and creates a DDD patch.

# Usage: `make-patch [YESTERDAY-TAG [TODAY-TAG]]'

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

# Default `yesterday' tag
yesterday_tag=`cvs checkout -p ddd/.RELEASE | grep 'ddd-' | sed 's/ddd-//' | \
sed 's/:.*//' | sed 's/\./_/g'`

# Default `today' tag
eval `cvs checkout -p ddd/ddd/acinclude.m4 2> /dev/null | \
 egrep '^(EXPIRES|VERSION|NICKNAME)='`
today_tag=DDD_`echo $VERSION | sed 's/\./_/g'`

case $# in
0) 
   ;;
1)
   yesterday_tag="$1";;
2)
   yesterday_tag="$1"
   today_tag="$2";;
*)
   echo "make-patch: usage: make-patch [TAG1] [TAG2]" 1>&2
   exit 2
esac

yesterday=`echo $yesterday_tag | sed 's/DDD_//' | sed 's/_/\./g'`
today=`echo $today_tag | sed 's/DDD_//' | sed 's/_/\./g'`
yesterday_dir=ddd-$yesterday
today_dir=ddd-$today

diff=ddd-$yesterday-$today.diff

echo "Creating $target/$diff..."
echo "Working directory is $tmpdir"
set -x
mkdir $tmpdir
cd $tmpdir

# 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

# Checkout releases
mkdir ddd
chgrp ddd ddd
chmod g+s ddd
cvs checkout -kkv -P -r "$yesterday_tag" ddd
mv ddd $yesterday_dir

mkdir ddd
chgrp ddd ddd
chmod g+s ddd
cvs checkout -kkv -P -r "$today_tag" ddd
mv ddd $today_dir

# Remove files and directories that are not in the distribution
rm -fr `find . -name 'CVS' -print`
rm -fr `find . -name '.cvs*' -print`
rm -fr ddd-*/etc ddd-*/tests ddd-*/.RELEASE

# Create diffs
(
echo "# $diff"
echo "# Bring a DDD $yesterday source package up to DDD $today"
echo 
echo "About this patch"
echo "----------------"
echo 
echo "* This patch must only be applied on DDD $yesterday source packages."
echo 
echo "* This patch only affects true source files - that is, files"
echo "  generated manually."
echo
echo "* Derived files as contained in the DDD source package are not"
echo "  affected by this patch and must be reconstructed using \`make'."
echo
echo
echo "Applying this patch"
echo "-------------------"
echo
echo "1. See the INSTALL file for additional packages required"
echo "   to rebuild DDD after making changes to the source code."
echo "   Typically, you will need at least:"
echo "   - GNU \`autoconf' 2.13 or later"
echo "   - GNU \`automake' 1.4 or later"
echo "   - GNU \`bison'"
echo "   - GNU \`flex'"
echo "   - GNU \`makeinfo' 4.0 or later."
echo "   We also recommend GNU make for rebuilding DDD."
echo
echo "2. Change to the directory containing the ddd-$yesterday"
echo "   top-level directory, such that \`./ddd-$yesterday/ANNOUNCE'"
echo "   contains the DDD $yesterday announcement."
echo
echo "3. Apply this patch on DDD $yesterday, using \`patch':"
echo
echo "   % patch -p0 < $diff"
echo
echo "4. Rename the \`ddd-$yesterday' directory to \`ddd-$today':"
echo
echo "   % mv ddd-$yesterday ddd-$today"
echo
echo "5. See the installation instructions for building or rebuilding DDD."
echo "   In case of missing packages, install the package and try again."
echo
echo "Please report any bugs or problems to bug-ddd@gnu.org."
echo
echo
diff -r -C 2 -P $yesterday_dir $today_dir
) | gzip -c -v9 > $target/$diff.gz

echo "Creating $target/$diff...done"

# That's all, folks!
exit 0
