#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.67)
AC_INIT()

# Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [main])
AC_CHECK_LIB([crypto], [main])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string.h unistd.h],,[AC_MSG_ERROR(not found the header file for mod_mruby.)])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST

# Checks for library functions.
AC_FUNC_STAT
AC_CHECK_FUNCS([memset putenv strtol])

# nginx src root
NGX_SRC_ROOT=no
AC_ARG_WITH(ngx_src_root, AC_HELP_STRING([--with-ngx-src-root=DIR],
    [pathname to ngx_src_root [[ngx_src_root]]]),
    [NGX_SRC_ROOT="$with_ngx_src_root"])
if test "$NGX_SRC_ROOT" = no; then
    AC_MSG_ERROR([nginx src dir not found.])
fi
AC_SUBST(NGX_SRC_ROOT)

NGX_OPENSSL_SRC=
AC_ARG_WITH(openssl_src, AC_HELP_STRING([--with-openssl-src=DIR],
    [set path to OpenSSL library sources]),
    [NGX_OPENSSL_SRC="$with_openssl_src"])
AC_SUBST(NGX_OPENSSL_SRC)

NGX_OPENSSL_OPT=
AC_ARG_WITH(openssl_opt, AC_HELP_STRING([--with-openssl-opt=OPTIONS],
    [set additional build options for OpenSSL]),
    [NGX_OPENSSL_OPT="$with_openssl_opt"])
AC_SUBST(NGX_OPENSSL_OPT)

# nginx src root
NGX_CONFIG_OPT=
AC_ARG_WITH(ngx_config_opt, AC_HELP_STRING([--with-ngx-config-opt=OPT],
    [ngxin configure option [[ngx_config_opt]]]),
    [NGX_CONFIG_OPT="$with_ngx_config_opt"])
#if test "$NGX_CONFIG_OPT" = no; then
#    AC_MSG_ERROR([nginx configure option not found.])
#fi
AC_SUBST(NGX_CONFIG_OPT)

# mruby root
MRUBY_ROOT=`pwd`/mruby
AC_ARG_WITH(mruby_root, AC_HELP_STRING([--with-mruby-root=DIR],
    [pathname to mruby_root [[mruby_root]]]),
    [MRUBY_ROOT="$with_mruby_root"])
AC_SUBST(MRUBY_ROOT)

# mruby include directory
MRUBY_INCDIR=""
AC_ARG_WITH(mruby_incdir, AC_HELP_STRING([--with-mruby-incdir=DIR],
    [include directory for mruby [[mruby_incdir]]]),
    [MRUBY_INCDIR="$with_mruby_incdir"])
AC_SUBST(MRUBY_INCDIR)

# mruby library directory which contains libmruby
MRUBY_LIBDIR=""
AC_ARG_WITH(mruby_libdir, AC_HELP_STRING([--with-mruby-libdir=DIR],
    [library directory to libmruby [[mruby_libdir]]]),
    [MRUBY_LIBDIR="$with_mruby_libdir"])
AC_SUBST(MRUBY_LIBDIR)

# ndk root
NDK_ROOT=`pwd`/dependence/ngx_devel_kit
AC_ARG_WITH(ndk_root, AC_HELP_STRING([--with-ndk-root=DIR],
    [pathname to ndk_root [[ndk_root]]]),
    [NDK_ROOT="$with_ndk_root"])
AC_SUBST(NDK_ROOT)

## support mrbgems
#ENABLE_GEMS=false
#AC_ARG_ENABLE([mrbgems],
#    [AS_HELP_STRING([--enable-mrbgems],
#        [mrbgems feature (default is no)])], 
#    [],
#    [enable_mrbgems=no] 
#)
#
#AS_IF([test "x$enable_mrbgems" != xno],
#    [AC_DEFINE([ENABLE_GEMS], [1], [mrbgems support])
#        ENABLE_GEMS=true
#    ]
#)
#AC_SUBST(ENABLE_GEMS)

AC_CONFIG_FILES([Makefile config])
AC_OUTPUT
