dnl Process this file with autoconf to produce a configure script.
AC_INIT(qmailadmin.c)
AM_INIT_AUTOMAKE(qmailadmin,1.0.6)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST

dnl Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB

AC_ISC_POSIX
AC_AIX

dnl Checks for libraries.
dnl Replace `main' with a function in -lcrypt:
AC_CHECK_LIB(crypt,crypt)
AC_CHECK_LIB(shadow,crypt)
AC_CHECK_LIB(m,floor)
AC_CHECK_LIB(nsl, gethostbyaddr)
AC_CHECK_LIB(socket, getsockname)

CGIBINTARGETS=qmailadmin
AC_SUBST(CGIBINTARGETS)

vpopmaildir=""
for f in ~vpopmail
do
    if test -d $f
    then
        vpopmaildir=$f
    fi
done

AC_ARG_ENABLE(vpopmaildir, [  --enable-vpopmaildir=dir  Home directory of vpopmail.],
    vpopmaildir="$enableval",
    [
        if test "$vpopmaildir" = ""
        then
            AC_MSG_ERROR([Unable to find your vpopmaildir, specify --enable-vpopmaildir.])
        fi
    ] )
AC_SUBST(vpopmaildir)

auth_incs=`cat $vpopmaildir/etc/inc_deps`
AC_SUBST(auth_incs)
auth_libs=`cat $vpopmaildir/etc/lib_deps`
AC_SUBST(auth_libs)

htmldir=""
for f in /home/httpd/html /usr/local/apache/htdocs /usr/local/www/data /var/www/html
do
    if test -d $f
    then
        htmldir=$f
    fi
done
AC_ARG_ENABLE(htmldir, [  --enable-htmldir={dir}   HTTP server's base html dir.],
    htmldir="$enableval",
    [
        if test "$htmldir" = ""
        then
            AC_MSG_ERROR([Unable to find your html base directory, specify --enable-htmldir.])
        fi
    ] )
AC_SUBST(htmldir)


cgibindir=""

for f in /home/httpd /usr/local/apache /usr/local/www /var/lib/httpd /var/www /usr/local/www 
do
    if test -d $f/cgi-bin
    then
        cgibindir=$f/cgi-bin
    fi
done

AC_ARG_ENABLE(cgibindir, [  --enable-cgibindir={dir}   HTTP server's cgi-bin directory.],
    cgibindir="$enableval",
    [
        if test "$cgibindir" = ""
        then
            AC_MSG_ERROR([Unable to find your cgi-bin directory, specify --enable-cgibindir.])
        fi
    ] )
AC_SUBST(cgibindir)


htmllibdir="/usr/local/share/qmailadmin/"

AC_ARG_WITH(htmllibdir, [  --with-htmllibdir={dir}    qmailadmin HTML library directory.],
    htmllibdir="$withval",
    [
        if test "$htmllibdir" = ""
        then
            AC_MSG_ERROR([Unable to find your htmllibdir directory, specify --with-htmllibdir.])
        fi
    ] )
AC_SUBST(htmllibdir,$htmllibdir)
AC_DEFINE_UNQUOTED(HTMLLIBDIR, "$htmllibdir/html")


qmaildir=""
for f in /var/qmail
do
    if test -d $f
    then
        qmaildir=$f
    fi
done

AC_ARG_ENABLE(qmaildir, [  --enable-qmaildir={dir}   directory where qmail is installed.],
    qmaildir="$enableval",
    [
        if test "$qmaildir" = ""
        then
            AC_MSG_ERROR([Unable to find your qmaildir directory, specify --enable-qmaildir.])
        fi
    ] )
AC_DEFINE_UNQUOTED(QMAILDIR,"$qmaildir")

cgipath="/cgi-bin/qmailadmin"

AC_ARG_ENABLE(cgipath, [  --enable-cgipath={/cgi-bin/qmailadmin}   URL path for cgi.],
    cgipath="$enableval",
    [
        if test "$cgipath" = ""
        then
            AC_MSG_ERROR([Unable to find your cgipath directory, specify --enable-cgipath.])
        fi
    ] )
AC_DEFINE_UNQUOTED(CGIPATH,"$cgipath")

vpopuser="vpopmail"
AC_ARG_ENABLE(vpopuser, [  --enable-vpopuser={vpopmail}   user vchkpw was installed as.],
    vpopuser="$enableval",
    [
        if test "$vpopuser" = ""
        then
            AC_MSG_ERROR([Unable to find your vpopuser user, specify --enable-vpopuser.])
        fi
    ] )
AC_DEFINE_UNQUOTED(VPOPUSER,"$vpopuser")
AC_SUBST(vpopuser)
   
vpopgroup="vchkpw"
AC_ARG_ENABLE(vpopgroup, [  --enable-vpopgroup={vchkpw}   group vchkpw was installed as.],
    vpopgroup="$enableval",
    [
        if test "$vpopgroup" = ""
        then
            AC_MSG_ERROR([Unable to find your vpopgroup group, specify --enable-vpopgroup.])
        fi
    ] )
AC_DEFINE_UNQUOTED(VPOPGROUP,"$vpopgroup")
AC_SUBST(vpopgroup)

for f in /usr/local/bin /usr/bin /usr/sbin /usr/local/bin /var/qmail/bin
do
    if test -f $f/autorespond
    then
        autorespond_bin=$f
    fi
done
AC_ARG_ENABLE(autoresponder-bin, [  --enable-autoresponder-bin={path}  Path to autoresponder directory or =n to disable.],
    autorespond_bin="$enableval",
    [
        if test "$autorespond_bin" = ""
        then
            AC_MSG_ERROR([Unable to find your autorespond program directory, specify --enable-autoresponder-bin.])
        fi
    ] )
AC_DEFINE_UNQUOTED(AUTORESPOND_BIN,"$autorespond_bin")

ezmlmdir=""
for f in /usr/local/bin/ezmlm /usr/bin /usr/sbin /usr/local/bin
do
    if test -f $f/ezmlm-make
    then
        ezmlmdir=$f
    fi
done

AC_ARG_ENABLE(ezmlmdir, [  --enable-ezmlmdir={dir}  Directory that holds the ezmlm package.],
    ezmlmdir="$enableval",
    [
        if test "$ezmlmdir" = ""
        then
            AC_MSG_ERROR([Unable to find your ezmlmdir user, specify --enable-ezmlmdir.])
        fi
    ] )
AC_DEFINE_UNQUOTED(EZMLMDIR,"$ezmlmdir")

maxpopusers=-1
AC_ARG_ENABLE(maxpopusers, [  --enable-maxpopusers=unlimited  -1 is unlimited, zero turns off functionality.],
    maxpopusers="$enableval",)
AC_DEFINE_UNQUOTED(DEFAULT_MAX_POP_USERS,$maxpopusers)

maxaliases=-1
AC_ARG_ENABLE(maxaliases, [  --enable-maxaliases=unlimited  -1 is unlimited, zero turns off functionality.],
    maxaliases="$enableval",)
AC_DEFINE_UNQUOTED(DEFAULT_MAX_ALIASES,$maxaliases)

maxforwards=-1
AC_ARG_ENABLE(maxforwards, [  --enable-maxforwards=unlimited  -1 is unlimited zero turns off functionality.],
    maxforwards="$enableval",)
AC_DEFINE_UNQUOTED(DEFAULT_MAX_FORWARDS,$maxforwards)

maxautoresponders=-1
AC_ARG_ENABLE(maxautoresponders, [  --enable-maxautoresponders=unlimited  -1 is unlimited zero turns off functionality.],
    maxautoresponders="$enableval",)
AC_DEFINE_UNQUOTED(DEFAULT_MAX_AUTORESPONDERS,$maxautoresponders)

maxmailinglists=-1
AC_ARG_ENABLE(maxmailinglists, [  --enable-maxmailinglists=unlimited  default is unlimited or a number.],
    maxmailinglists="$enableval",)
AC_DEFINE_UNQUOTED(DEFAULT_MAX_MAILINGLISTS,$maxmailinglists)

maxusersperpage=15
AC_ARG_ENABLE(maxusersperpage, [  --enable-maxusersperpage=15  default is 15 or a number.],
    maxusersperpage="$enableval",)
AC_DEFINE_UNQUOTED(MAXUSERSPERPAGE,$maxusersperpage)

maxaliasesperpage=25
AC_ARG_ENABLE(maxaliasesperpage, [  --enable-maxaliasesperpage=25  default is 25 or a number.],
    maxusersperpage="$enableval",)
AC_DEFINE_UNQUOTED(MAXALIASESPERPAGE,$maxaliasesperpage)

NO_CACHE=no
AC_ARG_ENABLE(no-cache, [  --enable-no-cache={N|y}  prohibit caching via http headers. n is default.],
    NO_CACHE="$enableval",)

case $NO_CACHE in
1*|y*|Y*)
	NO_CACHE=1
        AC_DEFINE_UNQUOTED(NO_CACHE,$NO_CACHE)
        echo "checking whether we should prohibit caching... yes"
        ;;
*)
        echo "checking whether we should prohibit caching... no"
        ;;
esac

IPAUTH=yes
AC_ARG_ENABLE(ipauth, [  --enable-ipauth={Y|n}  Users must maintain the same IP for the whole session. NAT/proxie systems may not maintain the same IP for the whole session. Default is yes.],
    IPAUTH="$enableval",)

case $IPAUTH in
1*|y*|Y*)
	IPAUTH=1
        AC_DEFINE_UNQUOTED(IPAUTH,$IPAUTH)
        echo "checking whether to require ip authentication... yes"
        ;;
*)
        echo "checking whether to require ip authentication... no"
        ;;
esac

USER_INDEX=yes
AC_ARG_ENABLE(user-index, [  --enable-user-index={Y|n}  Display user index on show usersw page, Default is yes.],
    USER_INDEX="$enableval",)

case $USER_INDEX in
1*|y*|Y*)
	USER_INDEX=1
        AC_DEFINE_UNQUOTED(USER_INDEX,$USER_INDEX)
        echo "checking whether to display user index... yes"
        ;;
*)
        echo "checking whether to display user index... no"
        ;;
esac


EZMLMIDX=no
if test -f $ezmlmdir/ezmlm-moderate
then
	EZMLMIDX=yes
fi

case $EZMLMIDX in
1*|y*|Y*)
                EZMLMIDX=1
                AC_DEFINE_UNQUOTED(EZMLMIDX,$EZMLMIDX)
				echo "checking for ezmlm-idx... yes"
        ;;
*)
				echo "checking for ezmlm-idx... no"
        ;;
esac



dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)

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

dnl Checks for library functions.
AC_CHECK_FUNCS(getcwd mkdir strdup strstr)

AC_OUTPUT(Makefile)
