dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/weex.c)

PACKAGE=weex
VERSION=2.8.0
ALL_LINGUAS="ja de es nl fr"

AM_INIT_AUTOMAKE($PACKAGE,$VERSION,no-define)
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_USE_SYSTEM_EXTENSIONS()
AM_CONFIG_HEADER(config.h)

AC_ARG_WITH(cafile,
    AC_HELP_STRING([--with-cafile=FILE]
	[Define the default SSL CA certificates file.]),
    [default_cafile="$withval"],
    [default_cafile="/etc/ssl/certs/ca-certificates.crt"])
AC_DEFINE_UNQUOTED([DEFAULT_CAFILE], ["$default_cafile"], [default CA FILE])


dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

dnl for gettext
AM_GNU_GETTEXT
AC_CHECK_FUNC(gettext,,AC_CHECK_LIB(intl, gettext))
localedir='${prefix}/share/locale'
AC_SUBST(localedir)

dnl Checks for libraries.
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(nsl,gethostbyname)
AC_CHECK_LIB([crypto],[CRYPTO_new_ex_data],
    AC_CHECK_LIB([ssl],[OPENSSL_init_ssl], 
	[LIBS="$LIBS -lssl -lcrypto"; CFLAGS="$CFLAGS -DUSE_SSL=1"], AC_MSG_ERROR([OpenSSL is not installed]))
    )

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h sys/time.h unistd.h gnuregex.h regex.h)
AC_CHECK_HEADER(gnuregex.h,gnuregex_ok=yes,gnuregex_ok=no)
if test "$gnuregex_ok" = no; then
  AC_CHECK_HEADER(regex.h,,AC_MSG_ERROR(GNU regex library is not installed.))
fi


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


dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(mkdir regcomp select socket strdup strerror strtol strtoul)
      

dnl this is for debug
AC_ARG_ENABLE(debug, [  --enable-debug          enable debug messages [default no]],,enable_debug=no)
AC_MSG_CHECKING(whether to enable debug)
if test x$enable_debug = xyes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(DEBUG)
else
  AC_MSG_RESULT(no)
fi


dnl 
AC_C_INLINE
if test x$CC = xgcc; then
   CFLAGS="$CFLAGS -Wall"
fi     
      

AC_OUTPUT(Makefile intl/Makefile src/Makefile po/Makefile.in \
debian/Makefile doc/Makefile man/Makefile)
