dnl Process this file with autoconf to produce a configure script.
dnl ====NOTE: When the user has PREFIX defined, use that one.
dnl ----------------------------------------------------------------
AC_INIT(acut.c)
version=4.32
AC_SUBST(version)

dnl The default PREFIX ('cds' user uses local definitions)
test "$USER" = "" && USER=`basename $HOME`
AC_PREFIX_DEFAULT(`test X$USER = Xcds && echo $HOME || echo /usr/local`)

dnl Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_AWK
AC_PROG_CC

dnl Checks for libraries.
AC_PROG_RANLIB
AC_MSG_CHECKING(options from computer)
case `uname -m` in 
    alpha) a="alpha";   LIBSYS="-ldnet_stub" ;;
    sun4*) a="solaris"; LIBSYS="-lnsl -lsocket" ;
	which cc | fgrep SUNWspro>/dev/null && CC=cc && cc_opt="-Xt -DSOLARIS";;
    i??6)  a="linux";   LIBSYS="-lcrypt"; cc_opt="-Wall" ;;
    *)     a="unknown"; LIBSYS="" ;;
esac
AC_MSG_RESULT($a)
AC_SUBST(cc_opt)
AC_SUBST(LIBSYS)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h termio.h dirent.h)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(gethostname socket strerror)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_SUBST(CC)
AC_MSG_CHECKING(64bit-integer)
echo '
#include <stdio.h>
int main()
{
    if (sizeof(int) == 4) printf("int");
    else printf("long");
    if (sizeof(long long) == 8) printf(" long long");
    else printf(" long");
    putchar(012);
    /* printf("%d\n", sizeof(long)); */
}
' > ttest.c
$CC ttest.c
a=`./a.out`
rm -f ttest.* a.out
int4="`echo $a|cut -d' ' -f1`"
int8="`echo $a|cut -d' ' -f2-`"
AC_MSG_RESULT($int8)
AC_SUBST(int8)
AC_SUBST(int4)

dnl ---- Verify the STRIP utility is not corrupted !
AC_MSG_CHECKING(strip utility)
echo '
#include <stdio.h>
int main()
{
  char buffer[[BUFSIZ]];
    while(fgets(buffer, sizeof(buffer), stdin))
        printf(">%s\\n", buffer);
}
' > ttest.c
$CC ttest.c
a=`strip a.out 2>&1| wc -w`
rm -f ttest.* a.out
if test $a -lt 1; then
    a=" ok "
    STRIP=strip
else
    a=" ***bad strip***"
    STRIP=echo
fi
AC_MSG_RESULT($a)
AC_SUBST(STRIP)

EXPORT_CVS_OPT="-d :pserver:anonymous@cdsarc:/home/cvs/data"
AC_SUBST(EXPORT_CVS_OPT)
cvs -version > /dev/null
if test $? -ne 0 ; then AC_MSG_WARN("YOU NEED CVS TO EXPORT!"); fi

AC_OUTPUT(Makefile)

dnl --- Indicate the Default Directory Installation ---
test $prefix = /usr/local && altprefix=\$HOME || altprefix=/usr/local
echo "----the prefix for installation directories is:	$prefix"
echo "    If this choice is not convenient, re-execute this configure"
echo "    with the --prefix option, e.g."
echo " ./configure --prefix=$altprefix"
echo "----Otherwise, proceed with   make   followed by   make install"
