#!/bin/sh

ngx_addon_name=ngx_http_mruby_module
mruby_root=@MRUBY_ROOT@
mruby_incdir="@MRUBY_INCDIR@"
mruby_libdir="@MRUBY_LIBDIR@"

if [ -z "$mruby_root" ]; then
    mruby_root=$ngx_addon_dir/mruby
fi
if [ -z "$mruby_incdir" ]; then
    mruby_incdir="$mruby_root/src $mruby_root/include"
fi
if [ -z "$mruby_libdir" ]; then
    mruby_libdir=$mruby_root/build/host/lib
fi

NGX_MRUBY_SRCS="$ngx_addon_dir/src/http/ngx_http_mruby_module.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_core.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_init.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_request.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_var.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_connection.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_server.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_filter.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_upstream.c \
                $ngx_addon_dir/src/http/ngx_http_mruby_ssl.c \
                "

if [ $STREAM = YES ]; then
  NGX_MRUBY_SRCS="$NGX_MRUBY_SRCS \
                  $ngx_addon_dir/src/stream/ngx_stream_mruby_module.c \
                  $ngx_addon_dir/src/stream/ngx_stream_mruby_init.c \
                  $ngx_addon_dir/src/stream/ngx_stream_mruby_core.c \
                  $ngx_addon_dir/src/stream/ngx_stream_mruby_connection.c \
                  "
fi

if [ $ngx_module_link = DYNAMIC ] ; then
    ngx_module_type=HTTP_AUX_FILTER
    ngx_module_name="$ngx_addon_name __ngx_http_upstream_keepalive_module"

    if [ $STREAM = YES ]; then
      ngx_module_name="$ngx_module_name ngx_stream_mruby_module"
    fi
    ngx_module_srcs="$NGX_MRUBY_SRCS"

    ngx_module_libs="$LDFLAGS -L$mruby_libdir -lmruby -lm"
    ngx_module_incs="$CORE_INCS $CFLAGS $mruby_incdir"

    if [ -f $ngx_addon_dir/mrbgems_config_dynamic ]; then
        . $ngx_addon_dir/mrbgems_config_dynamic
    fi

    . auto/module
else
    HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES __ngx_http_upstream_keepalive_module ngx_http_mruby_module"
    if [ $STREAM = YES ]; then
      HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES ngx_stream_mruby_module"
    fi
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
                    $NGX_MRUBY_SRCS
                    "
    CORE_LIBS="$CORE_LIBS -L$mruby_libdir -lmruby -lm"
    CORE_INCS="$CORE_INCS $mruby_incdir"

    if [ -f $ngx_addon_dir/mrbgems_config ]; then
        . $ngx_addon_dir/mrbgems_config
    fi
fi

have=NDK_SET_VAR . auto/have
