AC_INIT(zither/zither.c)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(zither, 1.1.11, no-define)

AC_PROG_CC
AC_HEADER_STDC
AC_PROG_INSTALL
AC_SUBST(INSTALL)

AC_CHECK_HEADERS([stdio.h \
		netinet/in.h \
		string.h \
		stdlib.h \
		pthread.h \
		time.h \
		sys/types.h \
		sys/stat.h \
		unistd.h \
		signal.h \
		syslog.h \
		sys/time.h \
		sys/resource.h \
		sys/wait.h \
		errno.h \
		arpa/inet.h \
		netdb.h \
		sys/socket.h \
		netinet/in_systm.h \
		netinet/ip.h \
		fcntl.h \
		netinet/ip_icmp.h \
		sys/un.h])


AC_TYPE_OFF_T
AC_TYPE_SIZE_T

AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(size_t)

AC_TYPE_SIZE_T

AC_FUNC_MMAP

# AC_CHECK_LIB(pthread,pthread_mutex_unlock)
# AC_CHECK_LIB(pthread,pthread_mutex_lock)
# AC_CHECK_LIB(pthread,pthread_create)
# AC_CHECK_LIB(pthread,pthread_join)
# AC_CHECK_LIB(pthread,pthread_detach)
# AC_CHECK_LIB(pthread,pthread_mutex_init)
# AC_CHECK_LIB(pthread,pthread_cancel)

# AC_CHECK_LIB(netsnmp,snmp_sess_perror)
# AC_CHECK_LIB(netsnmp,snmp_free_pdu)
# AC_CHECK_LIB(netsnmp,snmp_close)
# AC_CHECK_LIB(netsnmp,snmp_add_null_var)
# AC_CHECK_LIB(netsnmp,snmp_synch_response)
# AC_CHECK_LIB(netsnmp,snmp_pdu_create)
# AC_CHECK_LIB(netsnmp,snmp_open)
# AC_CHECK_LIB(netsnmp,snmp_sess_init)
# AC_CHECK_LIB(netsnmp,init_snmp)

# AC_CHECK_LIB(ssl,SSL_free)
# AC_CHECK_LIB(ssl,SSL_shutdown)
# AC_CHECK_LIB(ssl,SSL_read)
# AC_CHECK_LIB(ssl,SSL_write)
# AC_CHECK_LIB(ssl,verify_ssl)
# AC_CHECK_LIB(ssl,SSL_get_peer_certificate)
# AC_CHECK_LIB(ssl,SSL_get_version)
# AC_CHECK_LIB(ssl,SSL_get_current_cipher)
# AC_CHECK_LIB(ssl,SSL_connect)
# AC_CHECK_LIB(ssl,ERR_error_string)
# AC_CHECK_LIB(ssl,SSL_get_error)
# AC_CHECK_LIB(ssl,SSL_new)
# AC_CHECK_LIB(ssl,SSL_set_fd)

AC_LANG(C)


AC_ARG_WITH(database, [  --with-database Specify it when the use database. 'MYSQL or MYPG or PGSQL']
 ,USE_DB="$withval",USE_DB="NODB")
AC_SUBST(USE_DB)

if test x$USE_DB == "xMYSQL"; then
   DB_LD="-lzither -lalmemsys -lzithermysql -lmysqlclient"
   AC_SUBST(DB_LD)
   ZITHER_CFLAGS="-Wall -O2 -g -DMYSQL_IN"
   AC_SUBST(ZITHER_CFLAGS)
elif test x$USE_DB == "xMYPG"; then
   DB_LD="-lzither -lalmemsys -lpq -lzitherpsql -lzithermysql -lmysqlclient"
   AC_SUBST(DB_LD)
   ZITHER_CFLAGS="-Wall -O2 -g -DMYPG_IN"
   AC_SUBST(ZITHER_CFLAGS)
elif test x$USE_DB == "xPGSQL"; then
   DB_LD="-lzither -lalmemsys -lpq -lzitherpsql"
   AC_SUBST(DB_LD)
   ZITHER_CFLAGS="-Wall -O2 -g -DPOSTGRES_IN"
   AC_SUBST(ZITHER_CFLAGS)
else
   DB_LD="-lzither -lalmemsys"
   AC_SUBST(DB_LD)
   ZITHER_CFLAGS="-Wall -O2 -g -DNODB"
   AC_SUBST(ZITHER_CFLAGS)
fi



AC_ARG_ENABLE(net-snmp, [  --enable-net-snmp use the net_snmp agent.])
if test "x$enable_net_snmp" = "xyes"; then
   USE_SNMP=true
   AM_CONDITIONAL(USE_SNMP, [test x$USE_SNMP = xtrue])
else
   USE_SNMP=
   AM_CONDITIONAL(USE_SNMP, [test x$USE_SNMP = xtrue])
fi

AC_ARG_ENABLE(https, [  --enable-https use the https check.])
if test "x$enable_https" = "xyes"; then
   USE_HTTPS=true
   AM_CONDITIONAL(USE_HTTPS, [test x$USE_HTTPS = xtrue])
else
   USE_HTTPS=
   AM_CONDITIONAL(USE_HTTPS, [test x$USE_HTTPS = xtrue])
fi

AC_ARG_ENABLE(mysqlcheck, [  --enable-mysqlcheck use the mysql check.])
if test "x$enable_mysqlcheck" = "xyes"; then
   USE_MYSQL=true
   AM_CONDITIONAL(USE_MYSQL, [test x$USE_MYSQL = xtrue])
else
   USE_MYSQL=
   AM_CONDITIONAL(USE_MYSQL, [test x$USE_MYSQL = xtrue])
fi

AC_ARG_ENABLE(psqlcheck, [  --enable-psqlcheck use the postgreSQL check.])
if test "x$enable_psqlcheck" = "xyes"; then
   USE_PGSQL=true
   AM_CONDITIONAL(USE_PGSQL, [test x$USE_PGSQL = xtrue])
else
   USE_PGSQL=
   AM_CONDITIONAL(USE_PGSQL, [test x$USE_PGSQL = xtrue])
fi


AC_ARG_ENABLE(services, [  --enable-services services is dh services mode.])
if test "x$enable_services" = "xyes"; then
   SERVICES_CFLAGS=" -DSERVICES_MODE"
   AC_SUBST(SERVICES_CFLAGS)
else
   SERVICES_CFLAGS=""
   AC_SUBST(SERVICES_CFLAGS)
fi


AC_ARG_ENABLE(signature, [  --enable-signature  randam mail signature.])
if test "x$enable_signature" = "xyes"; then
   SIGNATURE_CFLAGS=" -DSIGNATURE_MODE"
   AC_SUBST(SIGNATURE_CFLAGS)
else
   SIGNATURE_CFLAGS=""
   AC_SUBST(SIGNATURE_CFLAGS)
fi



AC_ARG_ENABLE(sitar-static, [  --enable-sitar-static Specify it when the sitar static make.])
if test "x$enable_sitar_static" = "xyes"; then
    USE_STATIC="yes"
    AC_SUBST(USE_STATIC)
else
    USE_STATIC="no"
    AC_SUBST(USE_STATIC)
fi


if test "x$USE_STATIC" == "xyes"; then
   SITAR_CFLAGS="-static -Wall -O2 -g"
   AC_SUBST(SITAR_CFLAGS)
   SNMP_LD="-lsitar_base -lsitar_com -lsitar_scan -lalmemsys -lfile_comp"
   AC_SUBST(SNMP_LD)
else
   SITAR_CFLAGS="-Wall -O2 -g"
   AC_SUBST(SITAR_CFLAGS)
   SNMP_LD="-lsitar_base -lsitar_com -lsitar_scan -lalmemsys -lfile_comp -lnetsnmp -lssl -lcrypto"
   AC_SUBST(SNMP_LD)
fi




AC_ARG_WITH(ssllib, [  --with-ssllib=DIR Specify it when you want the Open_SSL library dirctory.]
 ,SSL_LIB_PATH="$withval",SSL_LIB_PATH="/lib")
AC_SUBST(SSL_LIB_PATH)

AC_ARG_WITH(sslinclude, [  --with-sslinclude=DIR Specify it when you want the Open_ssl include dirctory.]
 ,SSL_INC_PATH="$withval",SSL_INC_PATH="/include")
AC_SUBST(SSL_INC_PATH)

AC_ARG_WITH(psqllib, [  --with-psqllib=DIR Specify it when you want the postgreSQL library dirctory.]
 ,PSQL_LIB_PATH="$withval",PSQL_LIB_PATH="/usr/local/pgsql/lib")
AC_SUBST(PSQL_LIB_PATH)

AC_ARG_WITH(psqlinclude, [  --with-psqlinclude=DIR Specify it when you want the postgreSQL include dirctory.]
 ,PSQL_INC_PATH="$withval",PSQL_INC_PATH="/usr/local/pgsql/include")
AC_SUBST(PSQL_INC_PATH)

AC_ARG_WITH(mysqllib, [  --with-mysqllib=DIR Specify it when you want the mysql library dirctory.]
 ,MYSQL_LIB_PATH="$withval",MYSQL_LIB_PATH="/usr/lib/mysql")
AC_SUBST(MYSQL_LIB_PATH)

AC_ARG_WITH(mysqlinclude, [  --with-mysqlinclude=DIR Specify it when you want the mysql include dirctory.]
 ,MYSQL_INC_PATH="$withval",MYSQL_INC_PATH="/usr/include/mysql")
AC_SUBST(MYSQL_INC_PATH)

AC_ARG_WITH(net-snmplib, [  --with-net-snmplib=DIR Specify it when you want the net-snmp-5.4.1 library dirctory.]
 ,SNMP_LIB_PATH="$withval",SNMP_LIB_PATH="/usr/local/lib")
AC_SUBST(SNMP_LIB_PATH)

AC_ARG_WITH(net-snmpinclude, [  --with-net-snmpinclude=DIR Specify it when you want the net-snmp-5.4.1 include file dirctory.]
 ,SNMP_INC_PATH="$withval",SNMP_INC_PATH="/usr/local/include")
AC_SUBST(SNMP_INC_PATH)

AC_ARG_WITH(zitheruser, [  --with-zitheruser=NAME Specify the user of the file.]
 ,ZITHER_USER="$withval",ZITHER_USER="zither")
AC_SUBST(ZITHER_USER)


MYCFLAGS="-Wall -O2 -g"
AC_SUBST(MYCFLAGS)

AC_PATH_PROG(SNMP_LIB_PATH, libnetsnmp.a, ./NOTFILE_libnetsnmp.a, $SNMP_LIB_PATH)
AC_PATH_PROG(SNMP_INC_PATH, net-snmp-config.h, ./NOTFILE_net-snmp-config.h, $SNMP_INC_PATH/net-snmp)
AC_PATH_PROG(SNMP_INC_PATH, net-snmp-includes.h, ./NOTFILE_net-snmp-include.h, $SNMP_INC_PATH/net-snmp)
AC_PATH_PROG(PSQL_INC_PATH, libpq-fe.h, ./NOTFILE_libpq-fe.h, $PSQL_INC_PATH)


AC_CONFIG_FILES(Makefile \
		almemsys/Makefile \
		file_comp/Makefile \
		proxy/Makefile \
		zither/Makefile \
		sitar/Makefile)

AC_PROG_RANLIB
AC_OUTPUT



