#! /bin/sh

#############################################################################
# version and archive name configuration
version=`sed -e "s,^[^0-9]*\([0-9][0-9]*\)[^0-9]*\([0-9][0-9.]*\).*$,\1.\2," -e t -e d VERSION`
majorversion=`sed -e "s,^[^0-9]*\([0-9][0-9]*\)[^0-9]*\([0-9][0-9]*\).*$,\1.\2," -e t -e d VERSION`

echo [43m version $version [0m

archive=mined-$version

if ! egrep "$majorversion" doc/mined.lsm > /dev/null
then	echo "wrong archive major version listed in doc/mined.lsm" >&2
	exit -1
fi
if sed -e "s,$archive.tar.gz,,g" -e "s,mined-$majorversion.tar.gz,,g" doc/mined.lsm doc/download.html | egrep "mined.*tar" > /dev/null
then	echo "wrong archive name listed in doc/mined.lsm or doc/download.html" >&2
	exit -1
fi

release=`sed -e "s,.*release,release," -e "s,\..*,," VERSION`
if ! egrep "$release" doc/header.html > /dev/null
then	echo "wrong VERSION information in doc/header.html" >&2
	exit -1
fi

#############################################################################
# file name configuration
src="src/*.h src/*.c"
srcbuild="src/mnemos.??* src/*.cfg src/*.map src/charmaps/*.map src/keymaps0/*.h"
srcdoc="src/*.doc"
srcconf="configure src/*config* src/*.prj"
srcmake="src/make* src/mk* src/vms-link.com"
man="man/*html*man* man/*.1 man/makefile src/help/[^@]*"
doc="$man doc/*.html doc/*.gif doc/*.lsm doc/compilation doc/*term"
stuff="README LICENSE.GNU CHANGES VERSION mined.hlp Xdefaults.mined"
conf="minedenv.sh"
aux="minedmar*"
make="make*"

extra="merk src/merk*"

# assemble file list, without extra stuff
# include bin for recursive inclusion
files="$src $srcbuild $srcdoc $srcconf $srcmake $doc $stuff $conf $make $aux"
#bin="bin"
bin=

#############################################################################
# include extra files but exclude bin if parameter "+" included
if [ "$1" = "+" ]
then	files="$files $extra"
	shift
else	files="$files $bin"
fi

#############################################################################
# prefix $archive to all file names
ff=
for f in $files
do	ff="$ff $archive/$f"
done
files="$ff"


#############################################################################
# make the archive
ln -s . $archive

#zip -qyr $archive $files
/bin/tar clf $archive.tar $files
rm -f $archive.tar.gz
gzip $archive.tar

/bin/rm $archive


#############################################################################
