#! /bin/sh
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# release --- use make to roll a tarball which works in situ & VPATH
#
# Author:            Gary V Vaughan <gvv@techie.com>
# Maintainer:        Gary V Vaughan <gvv@techie.com>
# Created:           Thu Apr  9 17:22:07 1998
# Last Modified:     Thu Apr 29 14:17:34 1999				      
#            by:     Gary V. Vaughan <gvv@techie.com>		      
# ----------------------------------------------------------------------
# $Id: release,v 1.2 1999/06/03 18:49:40 bkorb Exp $
# ----------------------------------------------------------------------
# Copyright (C) 1998, 1999 Gary V. Vaughan
#
# This program 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.
#
# This program 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 this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

# Code:

# Figure out the absolute path to the working directory.
wd=`echo $0|sed 's,/[^/]*$,,'`
test -z "$wd" && wd=.
wd=`(cd $wd ; pwd)`

# Search for a configure.in
for srcdir in $wd $wd/.. .. .; do
   test -f $srcdir/configure.in && break
done
srcdir=`(cd $srcdir ; pwd)`
top_srcdir=`(cd ${top_srcdir-$srcdir}; pwd)`
export top_srcdir

cd $top_srcdir

# get the version numbers
. VERSION

# Reconfigure with our local options
$wd/bootstrap
if test -f config.status; then
    ./config.status --recheck
    ./config.status
else
    ./configure
fi

# Be certain to have an autogen executable before we continue!
make

# Assuming this has worked so far, we will regenerate the autogen opts
# files before the tests are run incase they have gone out of synch with
# the template file.
(
    oldwd=`pwd`
    remake=false

    cd ${top_srcdir}/config
    rm -f opts.def opts.c opts.h
    ln -s ${top_srcdir}/src/opts.def opts.def
    ${top_srcdir}/src/autogen -L ${top_srcdir}/autoopts opts.def

    for file in opts.h opts.c; do
	if test ! -s $file; then
	    echo "$file regeneration failed"
	    exit 1
	else
	    ct=`diff $file ${top_srcdir}/src/$file | wc -l`
	    if expr $ct '>' 8 > /dev/null 2>&1; then
		mv -f $file ${top_srcdir}/src/$file
		remake=:
		echo ${top_srcdir}/src/$file was regenerated
	    fi
	fi
    done

    rm -f opts.def opts.c opts.h

    # redo
    cd $oldwd
    $remake && make
)


# test VPATH build
make distcheck

# test for "in-tree" build success
tar zxvpf ${PACKAGE}-${VERSION}.tar.gz
(
    cd ${PACKAGE}-${VERSION}

    ./configure --prefix=`pwd`/\=inst \
        && make \
    	&& make info \
	&& make dvi \
	&& make check \
	&& make install \
	&& make installcheck \
	&& make dist

    # TODO: if we want complete overkill... perhaps we ought
    #       to see if the tarfile in here is the same as the one
    #       we were extracted from?
)
rm -rf ${PACKAGE}-${VERSION}

# If all of the above worked, then there is a good chance that the
# distribution is good.
cat << EOF
-------------------------------------------------------------------------------

	${PACKAGE}-${VERSION} has passed the release tests.

-------------------------------------------------------------------------------
EOF

exit 0

# release ends here
