
# configure.in for gopher
# Process this file with autoconf to produce a configure script.

dnl
dnl MACROS
dnl
define(UP_ASK_FOR,
[echo "$2 ($3)?";
read $1;
if test "$$1" = "" ; then
        $1="$3";
fi])dnl


AC_INIT(gopher/gopher.c)
echo "----------------------------------------------------------------------"
echo "You are about to build the Gopher system for Unix"
echo "Please read the file doc/INSTALL for full information on"
echo "building Gopher"
echo " "
echo "Gopher is copyrighted software, see the file Copyright in"
echo "the distribution for more information and limitations."
echo "----------------------------------------------------------------------"
echo " "
dnl AC_CANONICAL_HOST


AC_CONFIG_HEADER(config.h)
dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB
AC_PROG_MAKE_SET

dnl Checks for libraries.
AC_CHECK_LIB(m, main)

######################################################################
AC_SUBST(DEBUGGING)
AC_ARG_ENABLE(debug, [  --disable-debug         controls whether debug text is compilied in], DEBUGGING=$enableval, DEBUGGING="")

if test "$DEBUGGING" = yes; then
	DEBUGGING="-DDEBUGGING"
fi

######################################################################
AC_SUBST(SOCKSLIBS)
AC_SUBST(SOCKSFLAGS)
HAVE_SOCKS=0
AC_ARG_ENABLE(socks, [  --enable-socks          use socks library, requires -lsocks], HAVE_SOCKS=1, HAVE_SOCKS=0)

if test "$HAVE_SOCKS" = 1; then
  AC_CHECK_LIB(socks, main,
  SOCKSLIBS="-lsocks";
  SOCKSFLAGS="-Dconnect=Rconnect -Dgetsockname=Rgetsockname -Dbind=Rbind -Daccept=Raccept -Dlisten=Rlisten -Dselect=Rselect")
fi

######################################################################
AC_SUBST(GINTERNATIONAL)
GINTERNATIONAL=""
AC_ARG_ENABLE(locale, [  --enable-locale         use international localized msgs for the client], GINTERNATIONAL="-DGINTERNATIONAL", GINTERNATIONAL="")

######################################################################
AC_SUBST(GOPHER_DATA)
GOPHER_DATA="/gopher-data"
AC_ARG_ENABLE(datadir, [  --enable-datadir=dir    enable custom datadir (/gopher-data)], GOPHER_DATA="$enableval", GOPHER_DATA="/gopher-data")

######################################################################
AC_SUBST(GOPHER_PORT)
GOPHER_PORT=70
AC_ARG_ENABLE(port, [  --enable-port=portnum   enable custom port (70)], GOPHER_PORT="$enableval", GOPHER_PORT=70)

######################################################################
AC_SUBST(DLPATH)
AC_SUBST(DLOBJS)
AC_ARG_ENABLE(dl,        [  --enable-dl=dlpathname  use Tim Cook's dl databases], DLPATH="$enableval";DLOBJS="$enableval/getdesc.o $enableval/enddesc.o";SERVEROPTS="$SERVEROPTS -DDL",:)

######################################################################
AC_SUBST(OPT)
AC_ARG_ENABLE(opt,       [  --enable-opt=args       Special optimization flags to pass to the compiler], OPT="$enableval",OPT="$CFLAGS")

######################################################################

dnl
dnl LIBRARIES
dnl

# If we can't find connect, try looking in -lsocket, -lnsl, and -linet.
# The Irix 5 libc.so has connect and gethostbyname, but Irix 5 also has
# libsocket.so which has a bad implementation of gethostbyname (it
# only looks in /etc/hosts), so we only look for -lsocket if we need
# it.
unset ac_cv_func_connect
AC_CHECK_FUNC(connect, :, 
[case $LIBS in
*-lnsl*) ;;
*) AC_CHECK_LIB(nsl_s, main) ;;
esac
case $LIBS in
*-lnsl*) ;;
*) AC_CHECK_LIB(nsl, main) ;;
esac
case $LIBS in
*-lsocket*) ;;
*) AC_CHECK_LIB(socket, connect) ;;
esac
case $LIBS in
*-linet*) ;;
*) AC_CHECK_LIB(inet, connect) ;;
esac

unset ac_cv_func_connect
AC_CHECK_FUNCS(connect)])
 
AC_CHECK_FUNC(gethostname, :, LIBOBJS="$LIBOBJS hostname.o")

######################################################################
dnl Check for WAIS
with_wais=1
AC_ARG_WITH(wais,[  --without-wais          Don't try using WAIS (default: try)], with_wais=1, with_wais=0)

AC_SUBST(REGEXLIBS)
AC_SUBST(WAISTYPE)
AC_SUBST(SEARCH)

LDFLAGS=$OLDLDFLAGS

AC_CHECK_LIB(compat, re_comp, REGEXLIBS="$REGEXLIBS -lcompat")

######################################################################
AC_CHECK_LIB(malloc, main)

AC_SUBST(CLIENTLIBS)
AC_CHECK_LIB(curses, main, CLIENTLIBS="$CLIENTLIBS -lcurses")
AC_CHECK_LIB(termcap, main, CLIENTLIBS="$CLIENTLIBS -ltermcap")

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(strings.h string.h sys/param.h term.h re_comp.h regex.h crypt.h fcntl.h time.h ctype.h limits.h locale.h sys/types.h sys/stat.h sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h malloc.h stdlib.h libgen.h regexp.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_UID_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MMAP
dnl AC_FUNC_SETVBUF_REVERSED
AC_TYPE_SIGNAL
AC_FUNC_STRCOLL
AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_FUNC_GETLOADAVG

dnl Do this again so the AC_CHECK_FUNCS works.

AC_CHECK_LIB(curses, main)
AC_CHECK_LIB(termcap, main)
AC_CHECK_FUNCS(bzero gethostname fgetpwent get_current_dir_name getcwd getwd madvise mkdir mkstemp mktime putenv re_comp select seteuid setsid socket strcasecmp strcspn strdup strerror strftime strspn strstr strtol sysconf tempnam tzset wait3 waitpid strcasestr regcomp regfree wattron wattroff wstandout wstandend)

AC_TRY_LINK([#include <unistd.h>], [getdtablesize();])
AC_OUTPUT(Makefile Makefile.config object/Makefile gopher/Makefile gopher/locales/Makefile doc/Makefile gophfilt/Makefile)

