#! /bin/sh

# Call this without arguments if p4est is the toplevel package.
# Call this with one argument if p4est is itself a subdirectory:
# ./bootstrap <sc config directory>

# override by option argument
SC_CONFIG="sc/config"
if test -n "$1" ; then
  SC_CONFIG="$1"
fi
if test ! -d "$SC_CONFIG" ; then
  echo "Error: Cannot find directory $SC_CONFIG"
  echo "   If you just called ./bootstrap from a fresh clone of p4est"
  echo "   you may need to checkout the submodule sc:"
  echo "   \$ git submodule init && git submodule update"
  exit 1
fi
# convert into an absolute path
SC_CONFIG=`cd "$SC_CONFIG" && pwd`

if test -x "sc/bootstrap" ; then
  echo "Running bootstrap in subdirectory sc"
  (cd sc && ./bootstrap)
fi

echo "--- This is the bootstrap script for p4est ---"
echo "Current directory is $PWD"

LIBTOOLIZE=`which glibtoolize 2>/dev/null`
if test ! -x "$LIBTOOLIZE" ; then LIBTOOLIZE=`which libtoolize` ; fi
if test ! -x "$LIBTOOLIZE" ; then echo "bootstrap requires libtoolize" ; \
   exit 1 ; fi

aclocal -Wall -I config -I "$SC_CONFIG"
autoconf -Wall --force
autoheader -Wall --force
"$LIBTOOLIZE" --install --copy
automake -Wall --add-missing --copy
