#!/bin/sh
#
# $Id: run_autoconfig,v 1.32 2001/09/23 21:22:16 grubba Exp $
#
# Bootstrap script

need_to_make_depend=no

case :$PATH: in
   */NT/tools:*)
      echo Stripping NT/tools from path temporarily...
      PATH=`echo :$PATH | sed 's@:[^:]*/NT/tools:@@g' | sed 's@^:@@'`
   ;;
esac

if test "x$1" = "x" ; then
  base=`echo $0 | sed 's@[^/]*$@@g'`
  if test "x$base" != "x" ; then
    cd "$base"
  fi

  localdir=`pwd`
else
  cd "$1"

  localdir=`echo $0 | sed 's@[^/]*$@@g'`
  if test "x$localdir" = "x"; then
    localdir=`pwd`
  else
    localdir=`cd $localdir;pwd`
  fi
fi

autoconf_version="`autoconf --version|head -1|awk '{ print $NF }'`"

if [ "`echo $autoconf_version|awk -F. '{ print $1 }'`" -ne "2" -o \
     "`echo $autoconf_version|awk -F. '{ print $2 }'`" -ge "50" ]; then
  # Autoconf 2.50 and later is seriously broken.
  echo "Autoconf version $autoconf_version is not supported." >&2
  echo >&2
  echo "Get and install autoconf 2.13." >&2
  # Abort
  exit 1
else :; fi

IFS=''
( find . -follow -type d -print || find . -type d -print ) |egrep -v '/(CVS)|(RCS)|(test-install)$'| while read dir; do

  if [ -f $dir/Makefile.am -a -f $dir/configure.in ]; then
    # aclocal needs to be run before autoconf
    echo "Running aclocal in $dir"
    (cd $dir ; aclocal )
    echo "Running automake in $dir"
    (cd $dir ; automake )
  fi

  if [ -f $dir/acconfig.h -a $dir/configure.in ]; then
    echo "Running autoheader in $dir"
    ( cd $dir ; autoheader && echo foo >stamp-h.in )
  fi

  if [ -f $dir/configure.in ]; then
    if grep AC_INIT $dir/configure.in >/dev/null; then
      echo "Running autoconf in $dir"
      ( cd $dir ; autoconf --localdir=$localdir )
    else
      echo "$dir seems to use Cygnus-configure."
    fi
  fi

  if [ -f $dir/Makefile.in -a ! -f $dir/dependencies ] && egrep @dependencies@ $dir/Makefile.in >/dev/null; then
    touch $dir/dependencies
    need_to_make_depend=yes
  fi
done

if test "x$need_to_make_depend" = "xyes" ; then
  echo You need to run \"make depend\" after \"configure\", and then \"configure\" again.
fi

exit 0
