#! /bin/sh
#
# Copyright (C) 1995 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.
#

# This file is meant for authors or maintainers which want to
# internationalize their package with the help of GNU gettext.  For
# further information how to use it consult the GNU gettext manual.

echo=echo
progname=$0
force=0
configstatus=0
origdir=`pwd`
usage="\
Usage: gettextize [OPTION]... [package-dir]
  -h, --help           print this help and exit
  -v, --version        print version information and exit
  -f, --force          force writing of new files even if old exist"
package=gettext
version=0.10

while test $# -gt 0; do
  case "$1" in
    -f | --force | --f* )
      shift
      force=1 ;;
    -r | --run | --r* )
      shift
      configstatus=1 ;;
    -h | --help | --h* )
      $echo "$usage"; exit 0 ;;
    --version | --v* )
      echo "$progname - GNU $package $version"; exit 0 ;;
    -- )	# Stop option prcessing
      shift; break ;;
    -* )
      $echo "$usage"; exit 1 ;;
    * )
      break ;;
  esac
done

if test $# -gt 1; then
  $echo "$usage"
  exit 1
fi

# Fill in the command line options value.
if test $# -eq 1; then
  srcdir=$1
  if cd $srcdir; then
    srcdir=`pwd`
  else
    $echo "Cannot change directory to \`$srcdir'"
    exit 1
  fi
else
  srcdir=$origdir
fi

# Directory where the sources are stored.
gettext_dir=/share/gettext

test -f configure.in || {
  $echo "Missing configure.in, please cd to your package first."
  exit 1
}

if test -d intl && test $force -eq 0; then
  $echo "\
intl/ subdirectory exists: use option -f if you really want to delete it."
  exit 1
fi

if test -f po/Makefile.in.in && test $force -eq 0; then
  $echo "\
po/Makefile.in.in exists: use option -f if you really want to delete it."
  exit 1
fi

if test -f NLS && test $force -eq 0; then
  $echo "NLS exists: use option -f if you really want to delete it."
  exit 1
fi

$echo "Any pre-existing gettext source file will be removed."
rm -fr intl
mkdir intl || {
  $echo "failed to create intl/ subdirectory"
  exit 1;
}

test -d po || mkdir po || {
   $echo "failed to create po/ subdirectory"
   exit 1
}

# For simplicity we changed to the gettext source directory.
cd $gettext_dir

# Now copy all files.  Take care for the destination directories.
for file in *; do
  case $file in
    intl-*)
      copy=$srcdir/`echo $file | sed 's%^intl-%intl/%'`
      ln -s $gettext_dir/$file $copy 2>/dev/null || cp $file $copy
      ;;
    po-*)
      copy=$srcdir/`echo $file | sed 's%^po-%po/%'`
      rm -f $copy
      ln -s $gettext_dir/$file $copy 2>/dev/null || cp $file $copy
      ;;
    root-*)
      copy=$srcdir/`echo $file | sed 's%^root-%%'`
      rm -f $copy
      ln -s $gettext_dir/$file $copy 2>/dev/null || cp $file $copy
      ;;
    *)
      ;;
  esac
done

# Check whether we can run config.status to produce intl/Makefile.in.
cd $origdir
if test -f ./config.status; then
  if test $configstatus -eq 0; then
    echo "Shall I run config.status? (y/n)"
    read ans
    case "$ans" in
      y* | Y* | 1* )
	configstatus=1 ;;
      * )
	;;
    esac
  fi

  test $configstatus -ne 0 &&
    (CONFIG_FILES=intl/Makefile CONFIG_HEADERS= ./config.status)
fi

$echo "You should update your own aclocal.m4 by merging into it the contents of"
echo "		$gettext_dir/aclocal.m4"

exit 0

