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(Makefile.in)
version=1.1.1
AC_SUBST(version)

dnl The default PREFIX:
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
dnl AC_CANONICAL_SYSTEM
dnl AC_CANONICAL_HOST
AC_PROG_AWK
#AC_PROG_CC

dnl Checks for LIBREADLINE
dnl AC_CHECK_LIB(readline,readline)
AC_MSG_CHECKING(has readline)
readline=1
curses=1
CURSES=ncurses
f=`find /usr/include /usr/local/include -name readline.h -print | sort | tail -1`
if test -z "$f" ; then
    AC_MSG_RESULT(no)
    readline=0
    curses=0
else
    f=`find /lib /usr/lib -name libreadline.\* -print | sort | tail -1`
    AC_MSG_RESULT($f)
    test -z "$f" && readline=0
    dnl some distribution needs to add ncurses
    AC_MSG_CHECKING(has curses)
    n=`find /lib /usr/lib  /usr/local/lib -name lib$CURSES.\* -print | sort | tail -1`
    if test -z "$n" ; then
        AC_MSG_RESULT(no)
        curses=0
    else
        AC_MSG_RESULT($n)
    fi
fi
AC_SUBST(readline)



dnl Checks for libraries.
AC_PROG_RANLIB
AC_MSG_CHECKING(options from computer)
CC=cc
case `uname -m` in 
    alpha) a="alpha";   LIBS="-ldnet_stub" ;;
    sun4*) a="solaris"; LIBS="-lnsl -lsocket" ;
	test -x /opt/SUNWspro/bin/cc && CC=/opt/SUNWspro/bin/cc;
	$CC  -flags | grep '^-Xs' > /dev/null && cc_opt="-Xs" ;;
    i??6)  a="linux";   LIBSYS=""; cc_opt="-Wall" ;;
    x86*)  a="linux";   LIBSYS=""; cc_opt="-Wall" ;;
    *)     a="unknown"; LIBS="" ;;
esac
test -z "$f" || LIBSYS="-l readline $LIBSYS"
test -z "$n" || LIBSYS="-l $CURSES $LIBSYS"

AC_MSG_RESULT($a)
AC_SUBST(cc_opt)
AC_SUBST(LIBSYS)
AC_SUBST(CC)
AC_MSG_CHECKING(64bit-integer and pointer size)
echo '
#include <stdio.h>
int main()
{
    if (sizeof(int) == 4) printf("int");
    else printf("long");
    printf(" int%d", (int)sizeof(char *));
    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`"
intp="`echo $a|cut -d' ' -f2`"
int8="`echo $a|cut -d' ' -f3-`"
AC_MSG_RESULT($int8 $intp)
AC_SUBST(int8)
AC_SUBST(intp)
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)

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

dnl Checks for typedefs, structures, and compiler characteristics.

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

AC_OUTPUT(Makefile)

test $prefix = /usr/local && altprefix=\$HOME || altprefix=/usr/local
dnl --- Indicate the Default Directory Installation ---
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"

