#!/bin/sh
# "bootstrap" 
# Maintainer script for regenerating Makefiles and configure scripts.
# (also known as autogen.sh in some conventions)
#	$Id: bootstrap,v 1.8 2007/08/28 20:10:39 fang Exp $
# picks up AUTOCONF, AUTOMAKE, etc. from environment, which is used
# to override the default program names.

# this regenerates some critical files
# run this after "make maintainer-clean" or "make distclean"

PROJECT=hackt
TEST_TYPE=-f
FILE=INSTALL

# defaults
test "$AUTOCONF" || AUTOCONF=autoconf
test "$AUTOHEADER" || AUTOHEADER=autoheader
test "$AUTOMAKE" || AUTOMAKE=automake
test "$ACLOCAL" || ACLOCAL=aclocal
test "$LIBTOOLIZE" || LIBTOOLIZE=libtoolize
ACLOCAL_FLAGS="-I config $ACLOCAL_FLAGS"

echo "using:"
echo "AUTOCONF = $AUTOCONF"
echo "AUTOHEADER = $AUTOHEADER"
echo "AUTOMAKE = $AUTOMAKE"
echo "ACLOCAL = $ACLOCAL"
echo "LIBTOOLIZE = $LIBTOOLIZE"
echo "ACLOCAL_FLAGS = $ACLOCAL_FLAGS"

# May need this to break chicken-before-the-egg
touch src/headers_deps.make

DIE=0

# TODO: version compare

($AUTOCONF --version) < /dev/null > /dev/null 2>&1 || {
        echo
        echo "You must have autoconf installed to bootstrap $PROJECT from CVS."
        echo "Download the appropriate package for your distribution,"
        echo "or get the source tarball at: "
	echo "http://ftp.gnu.org/gnu/autoconf/autoconf-2.60.tar.gz"
        DIE=1
}

($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 || {
        echo
        echo "You must have libtool installed to bootstrap $PROJECT from CVS."
	echo "Get ftp://ftp.gnu.org/gnu/libtool/libtool-1.5.22.tar.gz"
        echo "(or a newer version if it is available)"
        DIE=1
}

($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || {
        echo
        echo "You must have automake installed to bootstrap $PROJECT from CVS."
        echo "Get http://ftp.gnu.org/gnu/automake/automake-1.9.6.tar.gz"
        echo "(or a newer version if it is available)"
        DIE=1
}

if test "$DIE" -eq 1; then
        exit 1
fi

test $TEST_TYPE $FILE || {
        echo "You must run this script in the top-level $PROJECT directory"
        exit 1
}

# function, no arguments
regen () 
{
$ACLOCAL $ACLOCAL_FLAGS
# optionally feature autoheader
($AUTOHEADER --version)  < /dev/null > /dev/null 2>&1 && $AUTOHEADER $ACLOCAL_FLAGS
$AUTOMAKE --copy --add-missing --gnu $am_opt
# --verbose if needed
$AUTOCONF $ACLOCAL_FLAGS
# really, 'autoreconf' with flags should suffice
}

$LIBTOOLIZE --copy --force --ltdl
# we forcibly remove some autotool files to force them to be regenerated
# using the local versions of the autotools, in case of version mismatch.
# Also point the config dir to the top-level one to share common files.
(cd libltdl && \
	mkdir -p removed && \
	mkdir -p config && \
	mv -f configure.ac configure.ac.bkp && \
	sed '/^AC_CONFIG_AUX_DIR/s|(.*)|([../config])|' configure.ac.bkp \
		> configure.ac && \
	mv -f configure.ac.bkp removed && \
	mv -f Makefile.in configure aclocal.m4 removed && \
	mv -f config.* install-sh ltmain.sh missing removed && \
	regen )

regen


# may not want verbose for autoconf, aclocal, and autoheader

