dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([spasm], [1.0], [aradia@theasylum.org])
AC_CONFIG_SRCDIR([src/spasmd.c])
AC_CONFIG_HEADER([config.h])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET

AC_PATH_PROG(AUTOHEADER, autoheader)
AC_PATH_PROG(AUTOCONF, autoconf)
AC_PATH_PROG(AMTAR, tar)

dnl Checks for libraries.
AC_CHECK_LIB([db], [db_create])
AC_CHECK_LIB([ncurses], [initscr])
AC_CHECK_LIB([pam], [pam_start])
AC_CHECK_LIB([pthread], [pthread_self])
AC_CHECK_LIB([resolv], [gethostbyname_r])
AC_CHECK_LIB([milter], [smfi_main])

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h curses.h errno.h fcntl.h libmilter/mfapi.h netdb.h netinet/in.h pwd.h regex.h security/pam_appl.h signal.h stdio.h stdlib.h string.h sysexits.h syslog.h sys/signal.h sys/stat.h sys/time.h sys/types.h time.h unistd.h])

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

dnl Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_FUNC_WAIT3
AC_CHECK_FUNCS([dup2 gettimeofday memset mkdir regcomp socket strcasecmp strchr strdup strerror strncasecmp strrchr strstr])

AC_CONFIG_FILES([Makefile
                 contrib/Makefile
                 src/Makefile
		 docs/Makefile])

dnl Check for spasm user
AC_ARG_WITH([spasm_user],
	AC_HELP_STRING([--with-spasm-user=USER],[Specify spasm user (default: spasm)]),
	[
		if test "x$withval" != "xno"; then
			foo=`id $withval 2>/dev/null`;
			if test -z "$foo"; then
				AC_MSG_ERROR([User $withval not found])
			fi
			SPASM_USER=$withval
		fi
	],
	[
		foo=`id spasm 2>/dev/null`;
		if test -z "$foo"; then
			AC_MSG_ERROR([User spasm not found])
		fi
		SPASM_USER=spasm
	]
)
AC_SUBST(SPASM_USER)

dnl Check for apache group
AC_ARG_WITH([apache_group],
	AC_HELP_STRING([--with-apache-group=GROUP],[Specify apache group (default: apache)]),
	[
		if test "x$withval" != "xno"; then
			APACHE_GROUP=$withval
		fi
	],
	[
		APACHE_GROUP=apache
	]
)
AC_SUBST(APACHE_GROUP)

dnl Check for CGI directory
AC_ARG_WITH([cgi-dir],
	AC_HELP_STRING([--with-cgi-dir=DIR],[Specify CGI directory (default: /var/www/cgi-bin)]),
	[
		if test "x$withval" != "xno"; then
			CGIDIR=$withval
		fi
	],
	[
		CGIDIR=/var/www/cgi-bin
	]
)
AC_SUBST(CGIDIR)

dnl Check for contrib directory
AC_ARG_WITH([contrib-dir],
	AC_HELP_STRING([--with-contrib-dir=DIR],[Specify directory for contrib binaries (default: /var/www/bin/spasm)]),
	[
		if test "x$withval" != "xno"; then
			CONTRIBDIR=$withval
		fi
	],
	[
		CONTRIBDIR=/var/www/bin/spasm
	]
)
AC_SUBST(CONTRIBDIR)

AC_OUTPUT
