#! /bin/echo this_file_should_be_sourced,_not_executed
#  -*- Mode: Shell-script -*-
# ----------------------------------------------------------------------
# defs --- define the environment for autogen tests.
#
# Time-stamp:        "2003-12-31 02:37:58 bkorb"
# Author:         Bruce Korb <bkorb@gnu.org>
# Maintainer:     Bruce Korb <bkorb@gnu.org>
# Created:        Fri Mar 27 21:15:30 1998
#
# $Id: defs,v 1.14 2003/12/31 11:56:14 bkorb Exp $
# ----------------------------------------------------------------------

# Make sure srcdir is an absolute path.  Supply the variable
# if it does not exist.  We want to be able to run the tests
# stand-alone!!
#
srcdir=${srcdir-.}
if test ! -d $srcdir
then
    echo "defs: installation error" 1>&2
    exit 1
fi

if test -z "$top_srcdir"
then
   top_srcdir=`cd $srcdir/../.. ; pwd`
fi

if test -z "$top_builddir"
then
   top_builddir=`cd ../.. ; pwd`
fi

homedir=`pwd`

#  IF the source directory is a Unix or a DOS root directory, ...
#
case "$srcdir" in
    /* | [A-Za-z]:\\*) ;;
    *) srcdir=`\cd $srcdir && pwd` ;;
esac

stdopts=${srcdir}/stdopts.def
progname=`echo "$0" | sed 's,^.*/,,'`
testname=`echo "$progname" | sed 's,\..*$,,'`
testsubdir=${testsubdir-testdir}

#  All the tests will require the templates in the autoopts dir.
#
AGEN="$AGEN -L `cd ${srcdir}/..;pwd`"

#  In general, they will have a test main procedure, too.
#
test_main=yes

# User can set VERBOSE to prevent output redirection
case x$VERBOSE in
  xNO | xno | x0 | x)
    exec > /dev/null 2>&1
    rm -rf $testsubdir
    VERBOSE=false
    ;;

  x* )
    VERBOSE=true
    ;;
esac
use_flags=true

test -d $testsubdir || mkdir $testsubdir
cd $testsubdir || {
  echo "Cannot make or change into $testsubdir"
  exit 1
}

echo "=== Running $progname"
chmod +w * > /dev/null 2>&1 || :

# A standard failure function
failure()
{
  test -d ../FAILURES || mkdir ../FAILURES
  ${VERBOSE} && set -x
  l=`echo ${testname}*`
  ( \cd ../FAILURES ; rm -rf $l )
  mv -f ${l} ../FAILURES
  echo "$*"
  exit 1
}

cleanup()
{
  if $VERBOSE ; then : ; else
    cd ${homedir}
    rm -rf $testsubdir
  fi
}

compile()
{
  d=`echo TEST_TEST_${testname}_OPTS | tr '[a-z]' '[A-Z]'`
  cmd="${CC} ${CFLAGS} -D$d ${INC} -o $testname $testname.c ${LIB}"
  echo $cmd >&2
  eval $cmd || \
    failure cannot compile $testname.c
  ./$testname $@ > $testname.help || \
    failure cannot obtain help output for $testname
}

## Local Variables:
## Mode: shell-script
## tab-width: 4
## indent-tabs-mode: nil
## sh-indentation: 2
## End:

# defs ends here
