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(anafile.c)
#version=`gawk '/^.VERSION/{v=$2}END{print v}' anafile.c`
version=7.86
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 How to open HTTP files.
AC_MSG_CHECKING(wwwget program)
wwwget=wwwget
test `which $wwwget | wc -w` -eq 1 || wwwget=wget
test `which $wwwget | wc -w` -eq 1 || wwwget="NO_HTTP"
AC_MSG_RESULT($wwwget)
AC_SUBST(wwwget)

dnl Create the links
AC_MSG_CHECKING(existence of adckeys.txt)
if test -f adckeys.txt; then
    a=" (exists)"
else
    a=" (create link)"
    ln -s ADC_Keywords adckeys.txt
fi
AC_MSG_RESULT($a)

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 and pointer size)
echo '
#include <stdio.h>
int main()
{
    printf("%d,%d,%d\n", sizeof(int), sizeof(long), sizeof(char *));
}
' > ttest.c
$CC ttest.c
a=`./a.out`; rm -f ttest.* a.out
a4=`echo $a|cut -d, -f1`
a8=`echo $a|cut -d, -f2`
ap=`echo $a|cut -d, -f3`
if test $a4 -eq 4; then
    int4=int
else
    int4=long
fi
if test $a8 -eq 8; then
    int8=long
    int8l=1
else
    int8="long long"
    int8l=2
fi
if test $ap -eq 8; then
    intp="$int8"
else
    intp="$int4"
fi
AC_MSG_RESULT($int8 $intp)
AC_SUBST(int8l)
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)

AC_OUTPUT(Makefile)

test $prefix = /usr/local && altprefix=\$HOME || altprefix=/usr/local
dnl --- Indicate the Default Directory Installation ---
test "$wwwget" = "NO_HTTP" && echo '#---HTTP files can''t be processed !
#    Consider the installation of cdsclient from
#    ftp://cdsarc.u-strasbg.fr/pub/sw/cdsclient.tar.gz'
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"
