dnl $Id: configure.in,v 1.15 2002/08/21 15:20:34 leodav Exp $
AC_PREREQ(2.52)
AC_INIT(src/opennap.h)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(opennap-ng,0.49.1)
AM_CONFIG_HEADER(src/config.h)
AM_MAINTAINER_MODE
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_AWK

# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h stdlib.h string.h strings.h sys/socket.h sys/time.h syslog.h unistd.h])

# Define templates here
dnl AH_TEMPLATE([CSC],[Define if you use Client-Server Compression.])
AH_TEMPLATE([DEBUG],[Define if you want to debug.])
AH_TEMPLATE([EMAIL],[Define if you want to use the email function.])
AH_TEMPLATE([FD_SETSIZE],[Is used with win32 for whatever.])
AH_TEMPLATE([HAVE_SOCKLEN_T],[Do we have struct socklen_t?])
AH_TEMPLATE([RESUME],[Define if you want to use the resume feature.])
AH_TEMPLATE([ROUTING_ONLY],[Define if you want to run as router.])
AH_TEMPLATE([USE_CHROOT],[Define if you want to run chrooted.])
AH_TEMPLATE([USE_GID],[Run server with group id.])
AH_TEMPLATE([USE_INVALID_CLIENTS],[Define if you want to use the invalid clients feature.])
AH_TEMPLATE([USE_INVALID_NICKS],[Define if you want to use the invalid nicks feature.])
AH_TEMPLATE([USE_PROTNET],[Define if you want to use the potected net feature.])
AH_TEMPLATE([USE_UID],[Run server with user id.])

AC_MSG_CHECKING(for socklen_t)
AC_EGREP_HEADER(socklen_t, /usr/include/sys/socket.h,
	[AC_MSG_RESULT(yes)
	AC_DEFINE(HAVE_SOCKLEN_T)],
	[AC_MSG_RESULT(no)])
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(long)
AC_REPLACE_FUNCS(getopt)
AC_CHECK_FUNCS(regcomp alarm syslog)

dnl check for zlib installed in /usr/local
if test -f /usr/local/lib/libz.a; then
	LIBS="$LIBS -L/usr/local/lib -lz"
	CFLAGS="$CFLAGS -I/usr/local/include"
else
AC_CHECK_LIB(z, compress2,[LIBS="$LIBS -lz"],
	[AC_MSG_ERROR(you must install zlib first)])
fi

AC_CHECK_LIB(xnet,gethostbyname)
AC_CHECK_LIB(nsl,socket)
AC_CHECK_LIB(socket,gethostbyname)

# Checks for library functions.
# AC_FUNC_GETLOADAVG
AC_FUNC_MEMCMP
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([mlockall poll alarm bzero strsep dup2 gethostbyname gethostname gettimeofday inet_ntoa memmove memset re_comp regcomp select socket strcasecmp strchr strdup strerror strncasecmp strpbrk strrchr strtol strtoul])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME



AC_MSG_CHECKING(for shared directory)
case "$host_os" in
*linux* | *freebsd* )
# maybe more needed here it's used for the stats ;)
  AC_DEFINE(LINUX, 1, [Do we run linux?])
  SHAREDIR=\${pkgdatadir}
  ;;
windows* | mingw* | os2*)
# No need for SHAREDIR=//c/opennap anymore just run it from any directory!
  SHAREDIR=.
#  AC_DEFINE(FD_SETSIZE,1024)
  REGEX=regex.o
  AC_SUBST(REGEX)
  WINRES=opennap.coff
  AC_SUBST([WINRES])
  GETOPT=getopt.o
  AC_SUBST(GETOPT)
  LIBS="$LIBS -lwsock32"
  ;;
cygwin*)
  SHAREDIR=.
  AC_DEFINE(FD_SETSIZE,4096)
  ;;
*solaris* )
# define SOLARIS so we can access data in proc
  AC_DEFINE(SOLARIS, 1, [Do we run Solaris?])
  SHAREDIR=\${pkgdatadir}
  ;;
*)
  SHAREDIR=\${pkgdatadir}
  ;;
esac
AC_SUBST(SHAREDIR)
AC_MSG_RESULT($SHAREDIR)

ac_cv_warnings=yes

# Define options here
AC_ARG_ENABLE(warnings, [  --disable-warnings		Turn off GCC compiler warnings ],
	[ac_cv_warnings=$enableval])
if test $ac_cv_warnings != "no"; then
	CFLAGS="-W -Wall -Wmissing-prototypes -Wcast-align -pedantic $CFLAGS"
fi

AC_ARG_ENABLE(debug, [  --enable-debug		Turn on memory debugging code],
	[if test $enableval = yes; then
		AC_DEFINE(DEBUG)
	fi])

AC_ARG_WITH(fd-setsize,
	[  --with-fd-setsize=N	Set max connections with select() to N],
	[AC_DEFINE_UNQUOTED(FD_SETSIZE,$withval)])

dnl support for resume is now turned off by default
AC_ARG_ENABLE(resume, [  --enable-resume		Turn on support for resume],
	[if test $enableval = yes; then
		AC_DEFINE(RESUME)
	fi])

dnl support for saving email address is turned off by default
AC_ARG_ENABLE(email,
	[  --enable-email		Turn on support for saving client email addresses],
	[if test $enableval = yes; then
		AC_DEFINE(EMAIL)
	fi])

AC_ARG_ENABLE(gprof, [  --enable-gprof		Use -pg with gcc to generate profiling data],
	[if test $enableval = yes; then
		CFLAGS="$CFLAGS -pg"
	fi])

AC_MSG_CHECKING(whether running as a router)
AC_ARG_ENABLE(router, [  --enable-router		Compile routing-only server (used as a hub only)],
	[AC_DEFINE(ROUTING_ONLY)
	AC_MSG_RESULT(yes)],
	[AC_MSG_RESULT(no)])

AC_MSG_CHECKING(whether to run chrooted)
AC_ARG_ENABLE(chroot, [  --enable-chroot		Run opennap chrooted],
	[if test $enableval = yes; then
		AC_DEFINE(USE_CHROOT)
		AC_MSG_RESULT(yes)
	fi],
	[AC_MSG_RESULT(no)])

AC_MSG_CHECKING(whether to use the default uid(nobody))
AC_ARG_WITH(uid, [  --with-uid=UID		Switch to UID if run as root],
	[AC_DEFINE_UNQUOTED(USE_UID,"$withval")
	AC_MSG_RESULT(no - using "$withval" uid)],
	[AC_DEFINE_UNQUOTED(USE_UID,"nobody")
	AC_MSG_RESULT(yes - using nobody uid)])
   
AC_MSG_CHECKING(whether to use the default gid(nobody))
AC_ARG_WITH(gid, [  --with-gid=GID		Switch to GID if run as root],
	[AC_DEFINE_UNQUOTED(USE_GID,"$withval")
	AC_MSG_RESULT(no - using "$withval" gid)],
	[AC_DEFINE_UNQUOTED(USE_GID,"nobody")
	AC_MSG_RESULT(yes - using nobody gid)])

AC_MSG_CHECKING(whether to disable invalid_clients variable)
AC_ARG_ENABLE(invalid_clients, [  --disable-invalid-clients	Disable the invalid_clients variable in the config],
	[AC_MSG_RESULT(yes)],
	[AC_DEFINE(USE_INVALID_CLIENTS)
	 AC_MSG_RESULT(no)])

AC_MSG_CHECKING(whether to disable invalid_nicks variable)
AC_ARG_ENABLE(invalid_nicks, [  --disable-invalid-nicks	Disable the invalid_nicks variable in the config],
	[AC_MSG_RESULT(yes)],
	[AC_DEFINE(USE_INVALID_NICKS)
	 AC_MSG_RESULT(no)])
      
AC_MSG_CHECKING(whether to disable Elite protection)
AC_ARG_ENABLE(protnet, [  --disable-protnet		Disable the protnet variable in the config],
	[AC_MSG_RESULT(yes)],
	[AC_DEFINE(USE_PROTNET)
	 AC_MSG_RESULT(no)])
	
dnl AC_MSG_CHECKING(whether to disable client-server zlib compression)
dnl AC_ARG_ENABLE(csc, [  --disable-csc			Disable client-server zlib compression],
dnl 	[AC_MSG_RESULT(yes)],
dnl 	[AC_DEFINE(CSC)
dnl 	 AC_MSG_RESULT(no)])

AC_OUTPUT([
           Makefile
	   rpm/opennap-ng.spec
           src/Makefile
          ])

