dnl
dnl  Configuration input file for Harvest
dnl
dnl  Darren Hardy, hardy@cs.colorado.edu, July 1994 (autoconf v1.11)
dnl  Darren Hardy, hardy@cs.colorado.edu, July 1995 (autoconf v2.4)
dnl  Duane Wessels, wesels@cs.colorado.edu, Jan 1996 (autoconf v2.7)
dnl
dnl  configure.in,v 1.99 1996/02/01 06:31:57 duane Exp
dnl
AC_INIT(common/include/config.h)
AC_CONFIG_HEADER(common/include/autoconf.h)
AC_REVISION(1.99)dnl
AC_PREFIX_DEFAULT(/usr/local/harvest)

dnl Build a copy of prefix

if test -n "$prefix"; then
  myprefix="$prefix";
else
  myprefix='/usr/local/harvest';
fi

INSTALL_TOPDIR="$myprefix";
INSTALL_LIBDIR="$myprefix/lib";
INSTALL_BINDIR="$myprefix/bin";
INSTALL_MANDIR="$myprefix/man";

THIS_HOST="`hostname`"
XTRA_CFLAGS=''
XTRA_LIBS=''
CRYPT_LIB=''

SOCKET_PH_TYPE='default'

echo '-----------------------'
echo "Installing Harvest in $myprefix"
echo '-----------------------'

dnl Subsitutions
AC_SUBST(INSTALL_TOPDIR)
AC_SUBST(INSTALL_LIBDIR)
AC_SUBST(INSTALL_BINDIR)
AC_SUBST(INSTALL_MANDIR)
AC_SUBST(DEFS)
AC_SUBST(XTRA_CFLAGS)
AC_SUBST(THIS_HOST)
AC_SUBST(SOCKET_PH_TYPE)

dnl Check for GNU cc
AC_PROG_CC

dnl Warn if not using GNU cc
XXXCC=`echo $CC | awk '{print $1}'`
if test "`basename $XXXCC`" != "gcc" 
then
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**';
        echo '**   WARNING:  You should compile Harvest using GNU cc.';
        echo "**   Currently, you're using $CC";
        echo '**   ';
        echo '**   For more information about the platforms on which';
        echo '**   Harvest works, see: ';
        echo '**    http://harvest.cs.colorado.edu/harvest/FAQ.html#platforms';
        echo '**   ';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
        echo '**************************************************************';
	sleep 5
fi

dnl Check for programs
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_YACC
AC_PROG_LEX
AC_PROG_LN_S
AC_PATH_PROG(RM, rm, /bin/false)
AC_PATH_PROG(MV, mv, /bin/false)
AC_PATH_PROG(MKDIR, mkdir, /bin/false)
AC_PATH_PROG(LN, ln, cp)
AC_PATH_PROG(CMD_PERL, perl, /bin/false)
dnl look for compression pgms
AC_PATH_PROG(CMD_GZIP, gzip, /bin/false)
AC_PATH_PROG(CMD_GUNZIP, gunzip, /bin/false)
AC_PATH_PROG(CMD_UNCOMPRESS, uncompress, /bin/false)
dnl 'unzip' is for DOS pkzip stuff
AC_PATH_PROG(CMD_UNZIP, unzip, /bin/false)

dnl Set PERL too
PERL="$CMD_PERL"
AC_SUBST(PERL)

dnl Set the XXMyOs variable
dnl
if test -x "/bin/uname"; then
        XXMyOs=`/bin/uname`;
else
	XXMyOs="unknown"
fi

dnl Decide if we should really use -lmalloc.  It is known to have
dnl problems on SunOS 5.4 at least.
dnl
dnl Set XXMyOsVer variable
dnl
if test -x "/bin/uname"; then
	XXMyOsVer=`/bin/uname -sr`
else
	XXMyOsVer="unknown"
fi

dnl Check for headers
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(config.h fcntl.h memory.h stdlib.h string.h unistd.h \
		utime.h \
		syslog.h sys/file.h sys/types.h sys/syslog.h sys/time.h \
                regex.h netinet/in.h arpa/inet.h)
AC_EGREP_HEADER(mxfast, malloc.h, [XTRA_CFLAGS="$XTRA_CFLAGS -DLNG_MALLINFO"], [XTRA_CFLAGS="$XTRA_CFLAGS"])

dnl Check for typedefs
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_C_CONST

dnl Check for library functions
AC_CHECK_FUNCS(bcopy bzero flock fsync ftruncate getcwd getdtablesize \
	      getrusage lrand48 memmove mktime nice on_exit random rename \
	      regcomp regexec regfree \
	      setrlimit srand48 srandom setlinebuf strdup strerror \
	      strftime sysconf timegm usleep vfork)

dnl Check for needed libraries
AC_CHECK_LIB(socket, main, [XTRA_LIBS="$XTRA_LIBS -lsocket"])
AC_CHECK_LIB(malloc, main, [XTRA_LIBS="$XTRA_LIBS -lmalloc"])
AC_CHECK_LIB(nsl, main, [XTRA_LIBS="$XTRA_LIBS -lnsl"])
AC_CHECK_LIB(resolv, main, [XTRA_LIBS="$XTRA_LIBS -lresolv"])

dnl We found a version of libresolv on SunOS 4.x which requires -l44bsd
dnl We have to first check to see if -l44bsd is present and has the
dnl function inet_aton 
AC_CHECK_LIB(44bsd, inet_aton, [HAVE_44BSD="yes"])
AC_CHECK_LIB(resolv, inet_aton, [if test "$HAVE_44BSD" = "yes"; then XTRA_LIBS="$XTRA_LIBS -l44bsd"; fi])

dnl Check for libcrypt
dnl cached uses crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
AC_CHECK_LIB(crypt, crypt, [CRYPT_LIB="-lcrypt"])

dnl Need these libraries for gdbm
AC_CHECK_LIB(dbm, main)
AC_CHECK_LIB(ndbm, main)
AC_SUBST(LIBS)

if echo $XXMyOsVer | grep ['SunOS 5.[0-4]'] >/dev/null 2>&1; then
	echo "Removing -lmalloc for Solaris"
	XTRA_LIBS=`echo $XTRA_LIBS | sed -e s/-lmalloc//`
	NO_LIBMALLOC=yes
fi

if [ "$XXMyOs" = "IRIX" ]; then
	echo "Removing -lsocket for IRIX"
	XTRA_LIBS=`echo $XTRA_LIBS | sed -e s/-lmalloc//`
	echo "Removing -lnsl for IRIX"
	XTRA_LIBS=`echo $XTRA_LIBS | sed -e s/-lnsl//`
fi

dnl Check for structures
AC_STRUCT_ST_BLKSIZE
AC_FUNC_ALLOCA
AC_TYPE_OFF_T
AC_TYPE_UID_T

dnl Need the debugging version of malloc if available
XTRA_OBJS=''
if test x$NO_LIBMALLOC != x ; then
	if test -r /usr/lib/debug/malloc.o ; then
		XTRA_OBJS="$XTRA_OBJS /usr/lib/debug/malloc.o"
	fi
	if test -r /usr/lib/debug/mallocmap.o ; then
		XTRA_OBJS="$XTRA_OBJS /usr/lib/debug/mallocmap.o"
	fi
fi
AC_SUBST(XTRA_OBJS)

AC_SUBST(CRYPT_LIB)

dnl Override XTRA_LIBS
if test -n "$XTRA_LIBS_OVERRIDE"; then
  XTRA_LIBS="$XTRA_LIBS_OVERRIDE";
fi
AC_SUBST(XTRA_LIBS)

dnl Set DEBUG_TOP
if test -z "$DEBUG_TOP"; then
    DEBUG_TOP='#-O #-g #-DDEBUG'
fi
AC_SUBST(DEBUG_TOP)

dnl Try to see if we're on Solaris or not
if test -x "/bin/uname"; then
	if /bin/uname -sr | grep 'SunOS 5.[0-9]' >/dev/null 2>&1; then
		SOCKET_PH_TYPE="Solaris";
	fi
fi

dnl Try to see if we're on HP-UX or not
if test "HP-UX" = "$XXMyOs"; then
	RANLIB=":";
fi

dnl Clean up after OSF/1 core dump bug
rm -f core 

AC_OUTPUT(\
	broker/Makefile \
	common/Makefile \
	common/gdbm/Makefile \
	common/include/paths.h \
	common/md5/Makefile \
	common/template/Makefile \
	common/url/Makefile \
	common/util/Makefile \
	common/regex/Makefile \
	gatherer/Makefile \
	gatherer/db/Makefile \
	gatherer/db/gdbmutil/Makefile \
	gatherer/enumerate/Makefile \
	gatherer/essence/Makefile \
	gatherer/essence/file/Makefile \
	gatherer/example/Makefile \
	gatherer/gatherd/Makefile \
	gatherer/mgmt/Makefile \
	gatherer/urld/Makefile \
)
