dnl Process this file with autoconf to produce a configure script.
AC_INIT(bin/rip/whois_rip.c)
AC_CONFIG_HEADER(include/config.h)

AC_CONFIG_SUBDIRS(utils/whoisRIP)
AC_PREFIX_DEFAULT(/usr/local/whois_rip)

dnl Local RIP things.

PRODUCT=`cat PRODUCT | cut -f2 -d'=' | tr -d " "`
VERSION=`cat VERSION | cut -f2 -d'=' | tr -d " "`
RELEASE_TAG=`cat VERSION | cut -f2 -d'=' | tr -d " .\n"`
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(PRODUCT)
AC_SUBST(VERSION)
AC_SUBST(RELEASE_TAG)

dnl
dnl glib-config
dnl

AC_ARG_WITH(glibconfig, 
	[  --with-glibconfig=FILE     FILE=path of MySQL include dir[$ac_default_prefix/bin/glib-config]],
	if test [ x$withval != x ] -a [ -x $withval ]; then
	  glibconfig=$withval
	else
	  echo "Please specify a suitable glib-config file: --with-glibconfig=FILE"; exit 1
	fi ,
	glibconfig=$ac_default_prefix/bin/glib-config)

AC_CHECK_FILE($glibconfig, , 
	      echo "The file glib-config does not exist!";
	      echo "Please specify a suitable glib-config file: --with-glibconfig=FILE"; exit 1)

AC_SUBST(glibconfig)


dnl
dnl MySQL include directory
dnl

AC_ARG_WITH(mysqlinc, 
	[  --with-mysqlinc=DIR        DIR=path of MySQL include dir[$ac_default_prefix/mysql/include]],
	if test [ x$withval != x ] -a [ -d $withval ]; then
	  mysqlincdir=$withval
	else
	  echo "Please specify a suitable MySQL include directory: --with-mysqlinc=DIR"; exit 1
	fi ,
	mysqlincdir=$ac_default_prefix/mysql/include)

AC_CHECK_FILE($mysqlincdir/mysql.h, , 
	      echo "MySQL include directory does not contain mysql.h !";
	      echo "Please specify a suitable MySQL include directory: --with-mysqlinc=DIR"; exit 1)

AC_SUBST(mysqlincdir)

dnl
dnl MySQL library directory
dnl

AC_ARG_WITH(mysqllib, 
	[  --with-mysqllib=DIR        DIR=path of MySQL library dir[$ac_default_prefix/mysql/lib]],
	if test [ x$withval != x ] -a [ -d $withval ]; then
	  mysqllibdir=$withval
	else
	  echo "Please specify a suitable MySQL library directory: --with-mysqllib=DIR"; exit 1
	fi ,
	mysqllibdir=$ac_default_prefix/mysql/lib)

AC_CHECK_FILE($mysqllibdir/libmysqlclient.a, , 
	      echo "MySQL library directory does not contain libmysqlclient.a !";
	      echo "Please specify a suitable MySQL library directory: --with-mysqllib=DIR"; exit 1)

AC_SUBST(mysqllibdir)

dnl
dnl c-client library directory (with c-client.a and various header files)
dnl

AC_ARG_WITH(cclientdir, 
	[  --with-cclientdir=DIR      DIR=path of c-client library dir[$ac_default_prefix/build/imap/c-client]],
	if test [ x$withval != x ] -a [ -d $withval ]; then
	  cclientdir=$withval
	else
	  echo "Please specify a suitable c-client library directory: --with-cclientdir=DIR"; exit 1
	fi ,
	cclientdir=$ac_default_prefix/build/imap/c-client)

AC_CHECK_FILE($cclientdir/c-client.a, , 
	      echo "MySQL include directory does not contain c-client.a !";
	      echo "Please specify a suitable c-client library directory: --with-cclientdir=DIR"; exit 1)

AC_CHECK_FILE($cclientdir/mail.h, , 
	      echo "MySQL include directory does not contain mail.h !";
	      echo "Please specify a suitable c-client library directory: --with-cclientdir=DIR"; exit 1)

AC_SUBST(cclientdir)

dnl End of local RIP things.

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PATH_PROGS(M4, gm4 gnum4 m4, m4)
AC_PATH_PROGS(PERL5, perl5 perl, /usr/local/bin/perl5)

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h pthread.h sys/time.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_CHECK_TYPE(uint64_t,u_int64_t)
AC_CHECK_TYPE(uint32_t,u_int32_t)
#AC_CHECK_TYPE(u_int64_t,uint64_t)
#AC_CHECK_TYPE(u_int32_t,uint32_t)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(socket strstr strsep strtok_r)
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(nsl,gethostbyname)
AC_CHECK_LIB(pthread,pthread_create)
AC_SEARCH_LIBS(pthread_attr_getstacksize,[pthread pthreads thread threads])
AC_CHECK_FUNCS(pthread_attr_getstacksize pthread_attr_setstacksize)

AC_OUTPUT(Makefile.site Makefile utils/lnsafe utils/remadmin/remadmin.pl)
AC_OUTPUT_COMMANDS([echo changing file permissions for executables... utils/lnsafe])
AC_OUTPUT_COMMANDS([chmod +x utils/lnsafe])
AC_OUTPUT_COMMANDS([echo changing file permissions for executables... utils/remadmin/remadmin.pl])
AC_OUTPUT_COMMANDS([chmod +x utils/remadmin/remadmin.pl])
