
# Copyright (C) 2010-2013 Alibaba Group Holding Limited

ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <yajl/yajl_parse.h> \
                  #include <yajl/yajl_gen.h>"
ngx_feature_test="yajl_version();"

if [ -n "$LIBYAJL_INC" -o -n "$LIBYAJL_LIB" ]; then
    # explicit set libdyajl lib path
    ngx_feature="libdyajl library in directories specified by LIBYAJL_INC ($LIBYAJL_INC) and LIBYAJL_LIB ($LIBYAJL_LIB)"
    ngx_feature_path="$LIBYAJL_INC"
    if [ $NGX_RPATH = YES ]; then
        ngx_feature_libs="-R$LIBYAJL_LIB -L$LIBYAJL_LIB -lyajl"
    else
        ngx_feature_libs="-L$LIBYAJL_LIB -lyajl"
    fi
    . auto/feature
else
    # auto-discovery
    ngx_feature="libyajl library"
    ngx_feature_path=
    ngx_feature_libs="-lyajl"
    . auto/feature

    if [ $ngx_found = no ]; then
        # FreeBSD, OpenBSD, linux
        ngx_feature="libyajl library in /usr/local/"
        ngx_feature_path="/usr/local/include/yajl /usr/local/include"
        if [ $NGX_RPATH = YES ]; then
            ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lyajl"
        else
            ngx_feature_libs="-L/usr/local/lib -lyajl"
        fi
        . auto/feature
    fi

    if [ $ngx_found = no ]; then
        # NetBSD
        ngx_feature="libyajl library in /usr/pkg/"
        ngx_feature_path="/usr/pkg/include/yajl /usr/pkg/include"
        if [ $NGX_RPATH = YES ]; then
            ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lyajl"
        else
            ngx_feature_libs="-L/usr/pkg/lib -lyajl"
        fi
        . auto/feature
    fi

    if [ $ngx_found = no ]; then
        # MacPorts
        ngx_feature="libyajl library in /opt/local/"
        ngx_feature_path="/opt/local/include/yajl /opt/local/include"
        if [ $NGX_RPATH = YES ]; then
            ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lyajl"
        else
            ngx_feature_libs="-L/opt/local/lib -lyajl"
        fi
        . auto/feature
    fi
fi

if [ $ngx_found = yes ]; then
    CORE_INCS="$CORE_INCS $ngx_feature_path"
    CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
else
 cat << END
 $0: error: the ngx_tfs addon requires the libyajl library.
END
 exit 1
fi
