#! /bin/sh

# Run this program to setup the build environment.

# $Id$
# $URL$
# $Progeny: setup,v 1.6 2002/07/12 07:05:45 epg Exp $

# This program is in the public domain.

# Too bad we don't have something like sysexits.h for POSIX sh...
EX_USAGE=64

usage ()
{
    cat <<EOF
usage: $0
       $0 (aclocal|autoheader|autoconf) ...

Setup the build environment.  If arguments are given, only those
actions are performed.
EOF
}

do_aclocal ()
{
    echo "cat /dev/null $@ > aclocal.m4"
    cat /dev/null "$@" > aclocal.m4
    return $?
}

do_autoheader ()
{
    echo "autoheader && touch config.h.in"
    autoheader && touch config.h.in
    return $?
}

do_autoconf ()
{
    echo "autoconf"
    autoconf
    return $?
}

###############################################################################

build=build
aclibs="${build}/check.m4"
aclibs="${aclibs} ${build}/config-script.m4"
aclibs="${aclibs} ${build}/libtool.m4"
aclibs="${aclibs} ${build}/show-config.m4"

if [ -f aclibs ]; then
    aclibs=$(sed -e 's/#.*//' aclibs)
fi

if [ $# -eq 0 ]; then
    set aclocal autoheader autoconf
fi

while [ $# -gt 0 ]; do
    case $1 in
    aclocal)
        do_aclocal ${aclibs}
        ;;
    autoheader)
        do_autoheader
        ;;
    autoconf)
        do_autoconf
        ;;
    *)
        usage
        exit ${EX_USAGE}
        ;;
    esac

    result=$?
    if [ ${result} -ne 0 ]; then
        echo "$0: $1 failed."
        exit ${result}
    fi

    shift
done

exit 0
