dnl File: configure.in
dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT(confdefs.h)

dnl set default location for isip_proto
dnl
AC_PREFIX_DEFAULT("")

dnl find the system type for ISIP_BINARY
dnl
AC_CANONICAL_SYSTEM

dnl isip_cancel is used to allow for all programs to be tested before
dnl issuing a failure message at the end
dnl isip_test is a temporary variable for testing results
dnl
isip_cancel=

dnl check for programs
dnl
AC_PROG_AWK
AC_PROG_CC
if [ test "$GCC" != "yes" ]; then
   isip_cancel=true
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(GNU C++, gcc, was not found on your system)
   AC_MSG_WARN(see http://www.gnu.org/software/gcc/gcc.html)
   AC_MSG_WARN("=============== Cannot Install ===============")
fi

AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_SUBST(SET_MAKE)

AC_MSG_CHECKING(Checking for GNU make)
isip_test=`echo \`gmake --version 2>/dev/null | grep GNU | wc -l\` 2>/dev/null`

if [ test "$isip_test" = "1" ]; then
   AC_MSG_RESULT(found - gmake)
   ISIP_MAKE=gmake
else
   isip_test=`echo \`make --version 2>/dev/null | grep GNU | wc -l\` 2>/dev/null`
   if  [ test "$isip_test" = "1" ]; then
       AC_MSG_RESULT(found - make)
       ISIP_MAKE=make
   else
      AC_MSG_RESULT(not found)
      isip_cancel=true
   fi
fi

AC_SUBST(ISIP_MAKE)
if [ test "$ISIP_MAKE" = "" ]; then
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(GNU make was not found on your system)
   AC_MSG_WARN(see http://www.gnu.org/software/make/make.html)
   AC_MSG_WARN("=============== Cannot Install ===============")
fi

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h strings.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

dnl Checks for library functions.
AC_CHECK_FUNCS(strstr strtod strtol)

dnl if an absolute path is not given, then prepend the current working 
dnl directory. this takes care of problems with . and ..
dnl
if [ test "$prefix" = "." ]; then
   prefix=`pwd`
fi

target=`pwd`

dnl if a required program is missing, echo an error message
dnl otherwise, output the proper files for making the system
dnl
if ( test -z "$isip_cancel" ); then
   AC_OUTPUT(GC_ENV.sh recognizer.csh demo.csh demo.pgm final_models/params.text)
   chmod +x recognizer.csh
   chmod +x demo.csh
   AC_MSG_RESULT(=============================================)
   AC_MSG_RESULT(Use $ISIP_MAKE as your make program and type:)
   AC_MSG_RESULT($ISIP_MAKE)
   AC_MSG_RESULT(to compile the programs)
   AC_MSG_RESULT(=============================================)
else
   AC_MSG_RESULT(===================================================)
   AC_MSG_RESULT(Required features missing.)
   AC_MSG_RESULT(Read warning messages above and see README.html.)
   AC_MSG_ERROR(Unable to continue installation.)
fi
