#! /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`

good=[43m
error=[41m
normal=[0m


echo "$good version $version $normal"

case "$1" in
-)	archive=mined-$version-beta;;
*)	archive=mined-$version;;
esac

if [ "$1" = "" ]
then

    majorrelease=`sed -e 's,\..*,,' VERSION`
    if ! egrep "$majorrelease" src/help/introduction > /dev/null
    then
	echo "$error wrong VERSION information in help section 'introduction' $normal" >&2
	exit -1
    fi

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

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/categors.sed src/vni.* src/insutf8 src/handescr/m* src/handescr/*.se? src/keymaps0/punctuation* src/vms-link.com"
man="man/*html*man* man/*.sed man/*.1 man/makefile src/help/[^@]*"
doc="$man doc/*.html doc/*.gif doc/*.png doc/compilation"
stuff="README* LICENSE.GNU CHANGES INSTALL* VERSION usrshare/*"
package="*.sed DESCR debian"
make="make*"

extra="src/merk*"

# assemble file list, without extra stuff
# include bin for recursive inclusion
files="$src $srcbuild $srcdoc $srcconf $srcmake $doc $stuff $package $make"
#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

/bin/tar clf release/$archive.tar $files
rm -f release/$archive.tar.gz
gzip release/$archive.tar

/bin/rm $archive


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