# NGINX addon configuration; sourced by auto/configure with POSIX sh.

ngx_addon_name=ngx_http_cache_purge_module

# NGX_HAVE_OPENAT covers openat/fstatat only.  Probe the remaining operations
# together; the module must not assume they exist on every Unix target.
if [ "$NGX_PLATFORM" != win32 ]; then
    ngx_feature="cache purge descriptor-relative traversal"
    ngx_feature_name="NGX_CACHE_PURGE_HAVE_AT"
    ngx_feature_run=no
    ngx_feature_incs="#include <dirent.h>
                      #include <fcntl.h>
                      #include <sys/stat.h>"
    ngx_feature_path=
    ngx_feature_libs=
    ngx_feature_test='DIR *d; struct stat st; int fd;
                      fd = openat(AT_FDCWD, ".", O_RDONLY|O_NOFOLLOW|O_DIRECTORY);
                      d = fdopendir(fd);
                      fstatat(dirfd(d), ".", &st, AT_SYMLINK_NOFOLLOW);
                      unlinkat(dirfd(d), "cache-purge-feature-test", 0);
                      closedir(d);'
    . auto/feature
fi

# Mirror the enabled upstream protocols in the module's compile guards.
if [ "$HTTP_PROXY" = "YES" ]; then
    have=NGX_HTTP_PROXY . auto/have
fi

if [ "$HTTP_FASTCGI" = "YES" ]; then
    have=NGX_HTTP_FASTCGI . auto/have
fi

if [ "$HTTP_SCGI" = "YES" ]; then
    have=NGX_HTTP_SCGI . auto/have
fi

if [ "$HTTP_UWSGI" = "YES" ]; then
    have=NGX_HTTP_UWSGI . auto/have
fi

CACHE_PURGE_SRCS="$ngx_addon_dir/ngx_cache_purge_handler.c \
                  $ngx_addon_dir/ngx_cache_purge_invalidation.c \
                  $ngx_addon_dir/ngx_cache_purge_module.c \
                  $ngx_addon_dir/ngx_cache_purge_queue.c \
                  $ngx_addon_dir/ngx_cache_purge_refresh.c \
                  $ngx_addon_dir/ngx_cache_purge_response.c \
                  $ngx_addon_dir/ngx_cache_purge_walk.c"
CACHE_PURGE_DEPS="$ngx_addon_dir/ngx_cache_purge.h \
                  $ngx_addon_dir/ngx_cache_purge_invalidation.h \
                  $ngx_addon_dir/ngx_cache_purge_posix.h \
                  $ngx_addon_dir/ngx_cache_purge_upstream.h \
                  $ngx_addon_dir/ngx_cache_purge_win32.h"

# auto/module supports static and dynamic registration since NGINX 1.9.11.
if [ -n "$ngx_module_link" ]; then
    ngx_module_type=HTTP
    ngx_module_name="$ngx_addon_name"
    ngx_module_srcs="$CACHE_PURGE_SRCS"
    ngx_module_deps="$CACHE_PURGE_DEPS"
    ngx_module_libs=""
    . auto/module
else
    HTTP_MODULES="$HTTP_MODULES $ngx_addon_name"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $CACHE_PURGE_SRCS"
    NGX_ADDON_DEPS="$NGX_ADDON_DEPS $CACHE_PURGE_DEPS"
fi

have=NGX_CACHE_PURGE_MODULE . auto/have

echo "  + ngx_cache_purge module added"
