1#!/bin/sh
2#set -e
3
4srcdir=`dirname $0`
5
6ACLOCAL_FLAGS="-I ${srcdir}/m4 ${ACLOCAL_FLAGS}"
7
8fail() {
9    status=$?
10    echo "Last command failed with status $status in directory $(pwd)."
11    echo "Aborting"
12    exit $status
13}
14
15# Refresh GNU autotools toolchain: libtool
16echo "Removing libtool cruft"
17rm -f ltmain.sh config.guess config.sub
18echo "Running libtoolize"
19(glibtoolize --version) < /dev/null > /dev/null 2>&1 && LIBTOOLIZE=glibtoolize || LIBTOOLIZE=libtoolize
20$LIBTOOLIZE --copy --force || fail
21
22# Refresh GNU autotools toolchain: aclocal autoheader
23echo "Removing aclocal cruft"
24rm -f aclocal.m4
25echo "Running aclocal $ACLOCAL_FLAGS"
26aclocal $ACLOCAL_FLAGS || fail
27echo "Removing autoheader cruft"
28rm -f config.h.in src/config.h.in
29echo "Running autoheader"
30autoheader || fail
31
32# Refresh GNU autotools toolchain: automake
33echo "Removing automake cruft"
34rm -f depcomp install-sh missing mkinstalldirs
35rm -f stamp-h*
36echo "Running automake"
37touch config.rpath
38automake --add-missing --gnu || fail
39
40# Refresh GNU autotools toolchain: autoconf
41echo "Removing autoconf cruft"
42rm -f configure
43rm -rf autom4te*.cache/
44echo "Running autoconf"
45autoconf
46
47# Autoupdate config.sub and config.guess 
48# from GNU CVS
49WGET=`which wget`
50if [ "x$WGET" != "x" ]; then
51    echo "Autoupdate config.sub and config.guess (y/n)?"
52    read IN
53    if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then
54	wget -O tmpfile http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
55	mv tmpfile config.guess
56	wget -O tmpfile http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub
57	mv tmpfile config.sub
58    fi
59else
60    echo "Could not autoupdate config.sub and config.guess"
61fi
62
63if [ ! -z "$NOCONFIGURE" ]; then
64	echo "autogen.sh finished! ./configure skipped."
65	exit $?
66fi
67
68echo "autogen.sh finished! Now going to run ./configure $@"
69./configure $@ || {
70    echo "./configure failed";
71    exit 1;
72}
73