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(`pwd`)

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 define function to check for the g++ compiler. We redefine this so that
dnl autoconf will look for g++ before c++
dnl
AC_DEFUN(ISIP_PROG_CXX,
[AC_CHECK_PROGS(CXX, $CCC g++ c++ gcc CC cxx cc++ cl, gcc)
AC_PROG_CXX])

dnl check for programs
dnl
AC_PROG_AWK
ISIP_PROG_CXX
if [ test "$GXX" != "yes" ]; then
   isip_cancel=true
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(GNU C++, g++ (or c++), 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

AC_PATH_PROG(PERL,perl)
AC_SUBST(PERL)
if ( test -z "$PERL" ); then
   isip_cancel=true
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(perl was not found on your system)
   AC_MSG_WARN(see http://www.perl.com/pub)
   AC_MSG_WARN("=============== Cannot Install ===============")
fi

AC_PATH_PROG(SCLITE,sclite)
AC_SUBST(SCLITE)
if ( test -z "$SCLITE" ); then
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(sclite was not found on your system)
   AC_MSG_WARN(for more informattion see http://www.itl.nist.gov/iaui/894.01)
   AC_MSG_WARN(or download in ftp://jaguar.ncsl.nist.gov/pub/sctk-1.2.tar.Z)
   AC_MSG_WARN("=============== Cannot Install ===============")
   isip_cancel=true
fi

AC_MSG_CHECKING(tcl/tk)
AC_PATH_PROG(TCL,wish)
AC_SUBST(TCL)
if ( test -z "$TCL" ); then
   AC_MSG_WARN("=============== Cannot Install ===============")
   AC_MSG_WARN(tcl/tk was not found on your system)
   AC_MSG_WARN(see http://dev.scriptics.com/)
   AC_MSG_WARN(you may need to rename or link your version to /usr/bin/wish)
   AC_MSG_WARN("=============== Cannot Install ===============")
   isip_cancel=true
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`
else
case "$prefix" in
NONE) prefix=`pwd` ;;
/*) ;;
\\*) ;;
*) prefix=`pwd`/"$prefix" ;;
esac
fi

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(GNUmakefile test_suite.sh ISIP_ENV.sh util/isip_eval/isip_eval.sh util/isip_to_score/isip_to_score.pl util/convert_models/convert_models.sh util/index_models/index_models.pl util/index_states/index_states.pl util/index_trans/index_trans.pl util/split_mmf/split_mmf.pl util/create_models/create_models.pl util/create_triphone_map/create_triphone_map.pl util/isip_function_help/isip_function_help.sh util/isip_decoder_demo/isip_decoder_demo.tcl scripts/tcl/isip_decoder_demo/src/dec_config.tcl scripts/tcl/isip_decoder_demo/src/dec_display.tcl scripts/tcl/isip_decoder_demo/src/dec_env.tcl scripts/tcl/isip_decoder_demo/src/dec_file_0.tcl scripts/tcl/isip_decoder_demo/src/dec_filesel.tcl scripts/tcl/isip_decoder_demo/src/dec_globals.tcl scripts/tcl/isip_decoder_demo/src/dec_next_0.tcl scripts/tcl/isip_decoder_demo/src/dec_plot_0.tcl scripts/tcl/isip_decoder_demo/src/dec_plot_1.tcl scripts/tcl/isip_decoder_demo/src/dec_plot_2.tcl scripts/tcl/isip_decoder_demo/src/dec_plot_3.tcl scripts/tcl/isip_decoder_demo/src/dec_quit_0.tcl scripts/tcl/isip_decoder_demo/src/dec_read_0.tcl scripts/tcl/isip_decoder_demo/src/dec_write_0.tcl scripts/tcl/isip_decoder_demo/src/dec_reset.tcl)
   chmod +x test_suite.sh
   AC_MSG_RESULT(=============================================)
   AC_MSG_RESULT(Use $ISIP_MAKE as your make program and type:)
   AC_MSG_RESULT(source $ISIP_ENV.sh)
   AC_MSG_RESULT($ISIP_MAKE)
   AC_MSG_RESULT(to compile the programs)
   AC_MSG_RESULT($ISIP_MAKE install)
   AC_MSG_RESULT(to install everything to the correct directories)
   AC_MSG_RESULT($ISIP_MAKE test)
   AC_MSG_RESULT(to run the verification suite)
   AC_MSG_RESULT(=============================================)
else
   AC_MSG_RESULT(===================================================)
   AC_MSG_RESULT(Required features missing.)
   AC_MSG_RESULT(Read warning messages above and see AAREADME.text.)
   AC_MSG_ERROR(Unable to continue installation.)
fi
