#! /bin/sh
### ====================================================================
### With the current directory set to the build directory (possibly in
### /tmp/glimpse-x.y.src), make a binary distribution of a glimpse
### installation for distribution back to the glimpse developers so they
### can offer more prebuilt versions.  The .tar.gz file is created in
### /usr/local/sys/src/glimpse/bindist/glimpse-x.y.z, if that directory
### exists, or can be created, and otherwise, in /tmp.
###
### The build log file is included in the distribution so people can see
### exactly what they are getting.  It is assumed that the log files
### reside in the build directory, named [Tt]ypescript.`hostname.`date`.
###
### Usage:
###	MAKE-GLIMPSE-BINARY-DISTRIBUTION.sh [majorversion.minorversion]
###
### [09-Oct-2001] -- Update for version 4.15.
### [27-Oct-1999] -- Update for version 4.12.6, and use gzip instead of 
###		     compress; The version number is now automatically 
###		     determined from the name of the build directory
### [23-Nov-1996] -- Original version.
### ====================================================================
if test "xx$1" = "xx"
then
	GLIMPSERELEASE=`basename $PWD | sed -e 's/glimpse-//' `
else
	GLIMPSERELEASE=$1
fi

# Use rcp instead of scp, because not all local systems have the latter yet (e.g. jwb104a)
RCP=rcp
# [09-Oct-2001] Use /bin/cp: all local systems now support the -p flag
RCP=/bin/cp

DISTMANFILES="
	glimpse.1		\
	glimpseindex.1		\
	glimpseserver.1		\
	agrep/agrep.1		\
	"

DISTBINFILES="
	bin/agrep		\
	bin/buildcast		\
	bin/cast		\
	bin/glimpse		\
	bin/glimpseindex	\
	bin/glimpseserver	\
	bin/tbuild		\
	bin/uncast		\
	bin/wgconvert		\
	"

DISTDOCFILES="
	WHERE-FROM              \
	CHANGES			\
	CONTRIBUTIONS		\
	COPYRIGHT		\
	ChangeLog		\
	KNOWN_BUGS		\
	README			\
	README.install		\
	"

if test ! -f WHERE-FROM 
then
	echo WARNING: Need to fetch WHERE-FROM file from the master archive:
	scp beebe@suntan.math.utah.edu:/usr/local/sys/src/glimpse/WHERE-FROM .
	test -f WHERE-FROM || ( echo Could not get WHERE-FROM file ... aborting ; exit 1)
fi

GLIMPSEDIR=/usr/local/sys/src/glimpse

DISTDIR=$GLIMPSEDIR/bindist/glimpse-$GLIMPSERELEASE
test -d $GLIMPSEDIR -a ! -d $DISTDIR && mkdir -p $DISTDIR 2>/dev/null
test -d $DISTDIR || DISTDIR=/tmp

echo ========================================================================
echo Distribution directory: $DISTDIR
echo ========================================================================

TMPDIST=glimpse-$GLIMPSERELEASE.bin.`uname -s -r -m | sed -e 's@[/ ]@-@g'`

LOGFILE=`ls [Tt]ypescript.$HOST.* | grep -v '~' | head -1`

/bin/rm -fr $TMPDIST

mkdir $TMPDIST $TMPDIST/bin $TMPDIST/doc $TMPDIST/log $TMPDIST/man || true

### [09-Oct-2001] Latest glimpse does not put all created binaries in the
### bin directory, so create links there if needed.
for f in $DISTBINFILES 
do
	g=`basename $f`
	test -f $f || ln `find . -type f -name $g` $f
done

$RCP -p $DISTBINFILES $TMPDIST/bin/
$RCP -p $DISTDOCFILES $TMPDIST/doc/
$RCP -p $DISTMANFILES $TMPDIST/man/
$RCP -p $LOGFILE $TMPDIST/log/

TARFILE=$DISTDIR/$TMPDIST.tar

/bin/rm -f $TMPDIST.tar $TMPDIST.tar.Z $TMPDIST.tar.gz $TARFILE $TARFILE.gz

tar cf $TARFILE $TMPDIST

tar tvf $TARFILE

echo ""
gzip -9 $TARFILE
tar tvfz $TARFILE.gz > ${TARFILE}-lst
ls -l ${TARFILE}*
