#! /bin/sh
#
# Copyright (C) 2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

# Usage: add-to-autopoint-files /somewhere/gettext-0.xx.yy.tar.gz
# Adds the infrastructure files for gettext version 0.xx.yy to the
# CVS repository in the archive directory.

if test $# != 1; then
  echo "Usage: add-to-autopoint-files /somewhere/gettext-0.xx.yy.tar.gz"
  exit 1
fi

sourcetgz="$1"
case "$sourcetgz" in
  *.tar.gz) ;;
  *) echo "$0: first argument should be a gettext release tar.gz file"; exit 1;;
esac

pack_ver=`basename "$sourcetgz" | sed -e 's/\.tar\.gz$//'`
if test -d "$pack_ver"; then
  echo "$0: directory $pack_ver already exists"; exit 1
fi
pack=`echo "$pack_ver" | sed -e 's/^\([^-]*\)-.*/\1/'`
ver=`echo "$pack_ver" | sed -e 's/^[^-]*-\(.*\)/\1/'`

# Unpack, build and install the source distribution.
myprefix=`pwd`/${pack_ver}-inst
gunzip -c < "$sourcetgz" | tar xvf -
cd $pack_ver
./configure --prefix="$myprefix"
make
make install
cd ..
rm -rf $pack_ver

# Copy the relevant files into an empty directory.
work_dir=tmpwrk$$
mkdir "$work_dir"
mkdir "$work_dir/archive"
work_archive=`pwd`/"$work_dir/archive"
(cd "$myprefix"/share/gettext
 for file in *; do
   case $file in
     ABOUT-NLS)
       cp -p $file "$work_archive/$file" ;;
     config.rpath | mkinstalldirs)
       cp -p $file "$work_archive/$file" ;;
   esac
 done
 mkdir "$work_archive/intl"
 cd intl
 for file in *; do
   if test $file != COPYING.LIB-2 && test $file != COPYING.LIB-2.0 && test $file != COPYING.LIB-2.1; then
     cp -p $file "$work_archive/intl/$file"
   fi
 done
 cd ..
 mkdir "$work_archive/po"
 cd po
 for file in *; do
   if test $file != Makevars; then
     cp -p $file "$work_archive/po/$file"
   fi
 done
 cd ..
 mkdir "$work_archive/m4"
 cd "$myprefix"/share/aclocal
 for file in *; do
   cp -p $file "$work_archive/m4/$file"
 done
)

# Add the contents of this directory to the repository.
CVSROOT=`pwd`/autopoint-files
export CVSROOT
cvsver=$pack-`echo "$ver" | sed -e 's/\./_/g'`
(cd "$work_archive"
 cvs import -m "Import $pack_ver" archive release "$cvsver"
)

# Clean up.
rm -rf "$work_dir"
rm -rf "$myprefix"

exit 0
