#!/bin/sh

if [ ! -f Makefile ];
then
  ./config/reconf
  ./configure
fi
make distclean

DELCONF_FILES=`ls config.*`
DELETE_FILES=" config.cache    acconfig.h    Makefile    Makefile.in    aclocal.m4    acinclude.m4 configure    ${DELCONF_FILES}"
for DF in ${DELETE_FILES}; 
do
  echo "deleting ${DF}"
  find . -name ${DF} -exec rm \{\} \;
done

find . -type l -exec rm \{\} \;

find . -type d | while read DIR; do

if [ "$DIR" = "./autom4te.cache" ];
then
  echo "deleting $DIR"
  rm -r $DIR
  continue
fi

if [ "$DIR" = "." ];
then
  continue
fi
(
  cd $DIR
  
  echo "# Scripts which shall be ignored by cvs commit" > .cvsignore
  echo "# because they are unimportant, only" >> .cvsignore
  echo "# temporarily used or will automatically" >> .cvsignore
  echo "# be rewritten by autoconf/automake" >> .cvsignore
  echo "Makefile.in" >> .cvsignore
  echo "Makefile" >> .cvsignore
  echo "*.la" >> .cvsignore
  echo "*.lo" >> .cvsignore
  echo "*.o" >> .cvsignore
  echo ".libs" >> .cvsignore
  echo ".deps" >> .cvsignore 
)

done

echo "# Links which shall be ignored by cvs commit." > .cvsignore
echo "# They can be regenerated by automake -a" >> .cvsignore 
echo "# after having checked out the whole project" >> .cvsignore 
echo ""  >> .cvsignore
echo "COPYING" >> .cvsignore 
echo "INSTALL" >> .cvsignore 
echo "config.guess" >> .cvsignore 
echo "config.sub" >> .cvsignore 
echo "install-sh" >> .cvsignore 
echo "ltmain.sh" >> .cvsignore 
echo "ltconfig" >> .cvsignore 
echo "missing" >> .cvsignore 
echo "mkinstalldirs" >> .cvsignore 
echo ""  >> .cvsignore
echo "# Scripts which shall be ignored by cvs commit. " >> .cvsignore 
echo "# They will be regenerated each time when" >> .cvsignore 
echo "# automake and autoconf will be called" >> .cvsignore 
echo ""  >> .cvsignore
echo "aclocal.m4" >> .cvsignore 
echo "configure" >> .cvsignore 
echo "Makefile.in" >> .cvsignore 
echo "Makefile" >> .cvsignore 
echo "stamp-h" >> .cvsignore 
echo "config.h" >> .cvsignore 
echo "config.log" >> .cvsignore 
echo "config.status" >> .cvsignore 
echo "libtool" >> .cvsignore 
echo "i686" >> .cvsignore 
echo "autom4te.cache" >> .cvsignore 

