#!/bin/sh
#
# gama tar: script is run in the parent directory of scripts
# #########
#
# $Id: GaMaLib_archive,v 1.15 2003/02/01 16:12:04 cepek Exp $

if pwd | grep scripts$; then cd ..; fi

HOME=.
cd $HOME
(cd doc; make clean; cd ..)

LIBVER=$(scripts/get-gamalib-version)
DIRVER=$(echo $LIBVER | awk -F. '// { print $1"."$2 }')

VERSION=gama-$LIBVER

rm -f   $VERSION 2>/dev/null
if [ -d $VERSION ]; then
   echo
   echo $VERSION directory exists - building of tar archive failed!
   echo
   echo
   exit 1
fi
ln -s . $VERSION

TAR=$VERSION.tar.gz
ADD="$VERSION/gamalib $VERSION/gamaprog $VERSION/xml"
ADD="$ADD $VERSION/Makefile $VERSION/AUTHORS"
ADD="$ADD $VERSION/ChangeLog* $VERSION/TODO"
ADD="$ADD $VERSION/INSTALL $VERSION/README"
ADD="$ADD $VERSION/gmatvec $VERSION/scripts"
ADD="$ADD $VERSION/expat"
ADD="$ADD $VERSION/doc"


MD5=$VERSION/gamalib-$LIBVER.md5sum
rm -f $MD5
for s in $(find $ADD | egrep \.'(h|cpp|c|gkf|dtd)'$ | egrep -v \# | grep -v \~ )
do
    if [ -f $s ] ; then    
       md5sum $s >> $MD5
    fi 
done

rm -f /tmp/gama-$VERSION-exclude
for i in `find $ADD | grep -v [.]o$ | grep -v [.]cpp$ | grep -v [.]h$ \
          | grep -v CVS | grep -v [.]html$ | grep -v [.]c$`
do
  if [ ! -d $i ] ; then
    echo -n \.
    TTT=`file $i`
    echo $TTT | grep ELF.*execu | sed s/:.*// >> /tmp/gama-$VERSION-exclude
    echo $TTT | grep "ar archi" | sed s/:.*// >> /tmp/gama-$VERSION-exclude
    echo $TTT | grep "core fil" | sed s/:.*// >> /tmp/gama-$VERSION-exclude
    echo $TTT | grep [\#~]      | sed s/:.*// >> /tmp/gama-$VERSION-exclude
  fi
done
echo

rm -f $TAR
echo
echo tar czvf $TAR
echo 
tar czvf $TAR $MD5 $ADD --exclude=*.o --exclude=*.a --exclude=*.bak \
              --exclude=$VERSION/$VERSION \
              --exclude=CVS \
              --exclude=doc/gama \
              --exclude-from=/tmp/gama-$VERSION-exclude

rm -f /tmp/gama-$VERSION-exclude

if ! test -d archive;
then
   mkdir archive
fi
if ! test -d archive/gama;
then
   mkdir archive/gama
fi
if ! test -d archive/gama/$DIRVER;
then
   mkdir archive/gama/$DIRVER
fi

cp $TAR archive/gama/$DIRVER
echo
ls -l   archive/gama/$DIRVER/$TAR | awk '//{ print $5 " " $9 }'   
echo
rm -f   $TAR $MD5 $VERSION

#
#------------------------------------------------------------------









