#!/bin/sh
# package: unionfs-utils
# regenerate configure, Makefile.in and other developers
# only developers should run this script
# requires GNU autoconf and GNU automake
# this is not meant to go into the distributions
# Erez Zadok <ezk@cs.sunysb.edu>

# test cwd
test -f ../unionfs.h && cd ..
if [ ! -f unionfs.h ]; then
    echo "Must run $0 from the top level source directory."
    exit 1
fi

# remove any remaining autom4te.cache directory
rm -fr autom4te.cache autom4te-*.cache

# generate aclocal.m4 file
echo "UU: aclocal..."
test -f aclocal.m4 && mv -f aclocal.m4 aclocal.m4.old
# show version
aclocal --version 2>&1 | head -1
if aclocal ; then
    :
else
    echo "aclocal command failed.  fix errors and rerun $0."
    exit 2
fi

# produce new configure (temp) script
echo "UU: autoconf..."
# show version
autoconf --version 2>&1 | head -1
LOG=/tmp/uu-$$.log
rm -f ${LOG}
autoconf configure.ac > configure.new 2> ${LOG}
CUTWARNMSG1="warning: fill-this-in-with-any-warning-you-want-to-ignore"
egrep -v "${CUTWARNMSG1}" ${LOG} > ${LOG}.new
mv ${LOG}.new ${LOG}
if test -s ${LOG}; then
    echo "AUTOCONF ERRORS (MUST FIX):"
    cat ${LOG}
    rm -f ${LOG}
    exit 2
fi
# now prepare the real configure script
test -f configure && mv -f configure configure.old
mv -f configure.new configure
chmod a+rx configure
rm -f configure.old

# run autoheader to produce C header .in files
echo "UU: autoheader..."
# show version
autoheader --version 2>&1 | head -1
autoheader configure.ac > config.h.in 2> ${LOG}
CUTWARNMSG2="autoheader: \`config.h.in' is updated"
egrep -v "${CUTWARNMSG2}" ${LOG} > ${LOG}.new
mv ${LOG}.new ${LOG}
if test -s ${LOG}; then
    echo "AUTOHEADER ERRORS (MUST FIX):"
    cat ${LOG}
    rm -f ${LOG}
    exit 2
fi
rm -f ${LOG}

# generate makefiles
cmd="automake --add-missing --copy --ignore-deps"
#cmd="automake --add-missing"
echo "UU: $cmd..."
# show version
automake --version 2>&1 | head -1
if ${cmd} ; then
    :
else
    echo "automake command failed.  fix errors and rerun $0."
    exit 2
fi

# save timestamp
echo "UU: save timestamp..."
echo timestamp > stamp-h.in

exit 0
