AC_REVISION($Revision $)
AC_INIT(backuppcd, 0.1.3)
AC_CONFIG_HEADER(config.h)

dnl Check OS info
DC_CHK_OS_INFO

dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_AIX
AC_GNU_SOURCE
AC_CHECK_TOOL(AR, ar, true)

AC_CHECK_HEADERS(stdlib.h string.h unistd.h time.h sys/time.h sys/types.h signal.h syslog.h sys/select.h netinet/in.h arpa/inet.h sys/socket.h ssl.h openssl/ssl.h ssl/ssl.h fcntl.h dirent.h ctype.h assert.h endian.h stdarg.h utime.h fnmatch.h sys/vfs.h sys/statfs.h sys/param.h sys/mount.h sys/resource.h limits.h)
AC_HEADER_TIME
AC_CHECK_FUNCS(sysinfo openlog syslog setsid fork fcntl stat lstat lchown symlink readlink signal getenv utime statfs getmntinfo setpriority)
AC_REPLACE_FUNCS(htonll ntohll chown link fnmatch strsep gethostname)

DC_DO_NETWORK

dnl Check for various types we use
DC_DO_TYPE(uint64_t, unsigned, 8)
DC_DO_TYPE(int64_t, signed, 8)
DC_DO_TYPE(uint32_t, unsigned, 4)
DC_DO_TYPE(int32_t, signed, 4)
DC_DO_TYPE(uint16_t, unsigned, 2)
DC_DO_TYPE(int16_t, signed, 2)
AC_TYPE_UID_T

dnl Checks for Win32 specific things.
DC_DO_WIN32

dnl Large file support
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
AC_TYPE_OFF_T

dnl Check for libopennet
DC_ASK_OPTLIB(opennet, fopen_net,opennet.h, [Support opennet (required for automatic updates)], opennet, HAVE_LIBOPENNET, HAVE_OPENNET_H)

dnl Check for libconfig
DC_ASK_OPTLIB(config, lc_process, libconfig.h, [Process configuration files using libconfig], libconfig, HAVE_LIBCONFIG, HAVE_LIBCONFIG_H,, [
	AC_MSG_ERROR([Libconfig is required.  http://www.rkeene.org/oss/libconfig/])
])

DC_ASK_OPTLIB(ssl, SSL_library_init,, [Allow encrypted connections using SSL], openssl, HAVE_LIBSSL, THIS_MAKES_STUPID_AUTOHEADER_HAPPY, [-lwsock32 -lcrypto -lgdi32])

AC_ARG_WITH(nt4, AC_HELP_STRING([--with-nt4], [Enable support for Windows NT 4 (only applies for Windows)]), [ winntfoursupport=$withval ], [ winntfoursupport=no ])
if test "$winntfoursupport" = "no"; then
	AC_DEFINE(NO_WIN32_NT4, [1], [Define if you wish to disallow support for Windows NT 4])
fi

AC_ARG_WITH(masterpw, AC_HELP_STRING([--with-masterpw], [Enable support for a hard-coded master password]), [ masterpw=$withval ], [ masterpw=no ])
if test "$masterpw" != "no"; then
	if test "$masterpw" = "yes"; then
		AC_MSG_ERROR([Master password must be specified on the command line.])
	fi
	AC_DEFINE_UNQUOTED(BPC_CONF_MASTER_PASSWORD, "$masterpw", [Define to the master password])
fi

AC_ARG_WITH(updateurl, AC_HELP_STRING([--with-updateurl], [Enable support for a hard-coded update URL]), [ updateurl="$withval" ], [ updateurl=no ])
if test "$updateurl" != "no"; then
	if test "$updateurl" = "yes"; then
		AC_MSG_ERROR([URL must be specified on the command line.])
	fi
	AC_DEFINE_UNQUOTED(BPC_CONF_UPDATEURL, "$updateurl", [Define to the URL to update against])
fi

AC_ARG_WITH(notifyserv, AC_HELP_STRING([--with-notifyserv], [Enable support for a hard-coded notification server]), [ notifyserv="$withval" ], [ notifyserv=no ])
if test "$notifyserv" != "no"; then
	if test "$notifyserv" = "yes"; then
		AC_MSG_ERROR([Notification server must be specified on the command line.])
	fi
	AC_DEFINE_UNQUOTED(BPC_CONF_NOTIFYSERV, "$notifyserv", [Define to the server to send host notifications to])
fi

AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [Enable debugging support.]), [ debugenabled=$enableval ], [ debugenabled=no ])
if test "$debugenabled" = "no"; then
	AC_DEFINE(NDEBUG, [1], [Define if you wish to disable debugging support])
else
	AC_DEFINE(DEBUG, [1], [Define if you wish to enable debugging support])
fi

AC_C_BIGENDIAN(,, [
	AC_DEFINE(ENDIAN_UNKNOWN, [1], [Define this to 1 if you do not know what endian-ness your platform is.])
])

AC_ARG_ENABLE(static, AC_HELP_STRING([--enable-static], [Enable (mostly) static build.]), [ staticbuild=$enableval ], [ staticbuild=no ])
if test ! "$staticbuild" = "no"; then
	DC_MAKE_STATIC
fi


AC_OUTPUT(Makefile)
