ngx_addon_name=ngx_http_vod_module
ngx_module_incs=
ngx_module_libs=
VOD_SRCS=
VOD_DEPS=

# version
#
VOD_DEFAULT_VERSION=1.11
VOD_VERSION=${VOD_VERSION:-`git --git-dir=$ngx_addon_dir/.git describe 2>/dev/null`}
VOD_VERSION=${VOD_VERSION:-$VOD_DEFAULT_VERSION}
echo "#define NGINX_VOD_VERSION \""$VOD_VERSION"\"" > $NGX_OBJS/ngx_vod_version.h

# taken from echo-nginx-module
# nginx won't have HTTP_POSTPONE_FILTER_MODULE & HTTP_POSTPONE_FILTER_SRCS
# defined since 1.9.11
if test -z "$HTTP_POSTPONE_FILTER_MODULE"; then
    HTTP_POSTPONE_FILTER_MODULE=ngx_http_postpone_filter_module
    HTTP_POSTPONE_FILTER_SRCS=src/http/ngx_http_postpone_filter_module.c
fi

# This module depends upon the postpone filter being activated
if [ "$HTTP_POSTPONE" = NO ]; then
    HTTP_FILTER_MODULES="$HTTP_FILTER_MODULES $HTTP_POSTPONE_FILTER_MODULE"
    HTTP_SRCS="$HTTP_SRCS $HTTP_POSTPONE_FILTER_SRCS"
    HTTP_POSTPONE=YES
fi

# zlib
#
if [ $ZLIB = NONE ]; then
    ngx_feature="zlib library"
    ngx_feature_name="NGX_HAVE_ZLIB"
    ngx_feature_run=no
    ngx_feature_incs="#include <zlib.h>"
    ngx_feature_path=
    ngx_feature_libs="-lz"
    ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)"
    . auto/feature

    if [ $ngx_found = yes ]; then
        ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
    fi
else
    cat << END >> $NGX_AUTO_CONFIG_H

#ifndef NGX_HAVE_ZLIB
#define NGX_HAVE_ZLIB  1
#endif

END
fi

# openssl evp
#
VOD_FEATURE_SRCS="                                      \
    $ngx_addon_dir/vod/dash/edash_packager.c            \
    $ngx_addon_dir/vod/hls/aes_cbc_encrypt.c            \
    $ngx_addon_dir/vod/hls/eac3_encrypt_filter.c        \
    $ngx_addon_dir/vod/hls/frame_encrypt_filter.c       \
    $ngx_addon_dir/vod/hls/sample_aes_avc_filter.c      \
    $ngx_addon_dir/vod/mp4/mp4_aes_ctr.c                \
    $ngx_addon_dir/vod/mp4/mp4_cbcs_encrypt.c           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_decrypt.c           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_encrypt.c           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_passthrough.c       \
    $ngx_addon_dir/vod/mss/mss_playready.c              \
    "

VOD_FEATURE_DEPS="                                      \
    $ngx_addon_dir/vod/dash/edash_packager.h            \
    $ngx_addon_dir/vod/hls/aes_cbc_encrypt.h            \
    $ngx_addon_dir/vod/hls/eac3_encrypt_filter.h        \
    $ngx_addon_dir/vod/hls/frame_encrypt_filter.h       \
    $ngx_addon_dir/vod/hls/sample_aes_avc_filter.h      \
    $ngx_addon_dir/vod/mp4/mp4_aes_ctr.h                \
    $ngx_addon_dir/vod/mp4/mp4_cbcs_encrypt.h           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_decrypt.h           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_encrypt.h           \
    $ngx_addon_dir/vod/mp4/mp4_cenc_passthrough.h       \
    $ngx_addon_dir/vod/mss/mss_playready.h              \
    "

if [ $OPENSSL = NONE ]; then
    LIB_CRYPTO=${LIB_CRYPTO:--lcrypto}
    LIB_PTHREAD=${LIB_PTHREAD:--lpthread}

    ngx_feature="OpenSSL EVP library"
    ngx_feature_name="NGX_HAVE_OPENSSL_EVP"
    ngx_feature_run=no
    ngx_feature_incs="#include <openssl/evp.h>"
    ngx_feature_path=
    ngx_feature_libs="$LIB_CRYPTO $NGX_LIBDL $LIB_PTHREAD"
    ngx_feature_test="EVP_CIPHER_CTX_new();"
    . auto/feature

    if [ $ngx_found = yes ]; then
        ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
        VOD_SRCS="$VOD_SRCS $VOD_FEATURE_SRCS"
        VOD_DEPS="$VOD_DEPS $VOD_FEATURE_DEPS"
    fi
else
    VOD_SRCS="$VOD_SRCS $VOD_FEATURE_SRCS"
    VOD_DEPS="$VOD_DEPS $VOD_FEATURE_DEPS"
    cat << END >> $NGX_AUTO_CONFIG_H

#ifndef NGX_HAVE_OPENSSL_EVP
#define NGX_HAVE_OPENSSL_EVP  1
#endif

END
fi

# iconv
#
ngx_feature="iconv"
ngx_feature_name="NGX_HAVE_ICONV"
ngx_feature_run=no
ngx_feature_incs="#include <iconv.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="iconv_open(NULL, NULL);"
. auto/feature

# clock_gettime
#
ngx_feature="clock_gettime()"
ngx_feature_name="NGX_HAVE_CLOCK_GETTIME"
ngx_feature_run=no
ngx_feature_incs="#include <sched.h>"
ngx_feature_path=
ngx_feature_libs=
ngx_feature_test="clock_gettime()"
. auto/feature

if [ $ngx_found != yes ]; then

    ngx_feature="clock_gettime() in librt"
    ngx_feature_libs="-lrt"
    . auto/feature

    if [ $ngx_found = yes ]; then
        ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
    fi
fi

# libavcodec
#
LIB_AV_UTIL=${LIB_AV_UTIL:--lavutil}
LIB_AV_CODEC=${LIB_AV_CODEC:--lavcodec}

ngx_feature="libavcodec"
ngx_feature_name="NGX_HAVE_LIB_AV_CODEC"
ngx_feature_run=no
ngx_feature_incs="#include <libavcodec/avcodec.h>"
ngx_feature_path=
ngx_feature_libs="$LIB_AV_CODEC"
ngx_feature_test="avcodec_send_packet(NULL, NULL)"
. auto/feature

if [ $ngx_found = yes ]; then
    ngx_module_libs="$ngx_module_libs $LIB_AV_CODEC $LIB_AV_UTIL -lm"
    VOD_FEATURE_SRCS="                                      \
        $ngx_addon_dir/ngx_http_vod_thumb.c                 \
        $ngx_addon_dir/ngx_http_vod_volume_map.c            \
        $ngx_addon_dir/vod/filters/audio_decoder.c          \
        $ngx_addon_dir/vod/filters/audio_encoder.c          \
        $ngx_addon_dir/vod/filters/volume_map.c             \
        $ngx_addon_dir/vod/thumb/thumb_grabber.c            \
        "

    VOD_FEATURE_DEPS="                                      \
        $ngx_addon_dir/ngx_http_vod_thumb.h                 \
        $ngx_addon_dir/ngx_http_vod_thumb_commands.h        \
        $ngx_addon_dir/ngx_http_vod_thumb_conf.h            \
        $ngx_addon_dir/ngx_http_vod_volume_map.h            \
        $ngx_addon_dir/ngx_http_vod_volume_map_commands.h   \
        $ngx_addon_dir/ngx_http_vod_volume_map_conf.h       \
        $ngx_addon_dir/vod/filters/audio_decoder.h          \
        $ngx_addon_dir/vod/filters/audio_encoder.h          \
        $ngx_addon_dir/vod/filters/volume_map.h             \
        $ngx_addon_dir/vod/thumb/thumb_grabber.h            \
        "

    VOD_SRCS="$VOD_SRCS $VOD_FEATURE_SRCS"
    VOD_DEPS="$VOD_DEPS $VOD_FEATURE_DEPS"
fi

# libswscale
#
ngx_feature="libswscale"
ngx_feature_name="NGX_HAVE_LIB_SW_SCALE"
ngx_feature_run=no
ngx_feature_incs="#include <libswscale/swscale.h>"
ngx_feature_path=
ngx_feature_libs="-lswscale"
ngx_feature_test="sws_scale(NULL, NULL, NULL, 0, 0, NULL, NULL)"
. auto/feature

if [ $ngx_found = yes ]; then
    ngx_module_libs="$ngx_module_libs -lswscale"
fi

# libavfilter
#
LIB_AV_FILTER=${LIB_AV_FILTER:--lavfilter}

ngx_feature="libavfilter"
ngx_feature_name="NGX_HAVE_LIB_AV_FILTER"
ngx_feature_run=no
ngx_feature_incs="#include <libavfilter/avfilter.h>
                  #include <libavfilter/buffersrc.h>
                  #include <libavfilter/buffersink.h>"
ngx_feature_path=
ngx_feature_libs="$LIB_AV_FILTER"
ngx_feature_test="avfilter_get_by_name(NULL)"
. auto/feature

if [ $ngx_found = yes ]; then
    ngx_module_libs="$ngx_module_libs $LIB_AV_FILTER $LIB_AV_UTIL"
fi

# libxml2
#
ngx_feature="libxml2"
ngx_feature_name="NGX_HAVE_LIBXML2"
ngx_feature_run=no
ngx_feature_incs="#include <libxml/parser.h>
                  #include <libxml/tree.h>"
ngx_feature_path="/usr/include/libxml2"
ngx_feature_libs="-lxml2"
ngx_feature_test="xmlReadMemory(NULL, 0, NULL, NULL, 0);"
. auto/feature

if [ $ngx_found = yes ]; then
    ngx_module_incs="$ngx_module_incs $ngx_feature_path"
    ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
    VOD_FEATURE_SRCS="                                      \
        $ngx_addon_dir/vod/subtitle/dfxp_format.c           \
        "
    VOD_FEATURE_DEPS="                                      \
        $ngx_addon_dir/vod/subtitle/dfxp_format.h           \
        "
    VOD_SRCS="$VOD_SRCS $VOD_FEATURE_SRCS"
    VOD_DEPS="$VOD_DEPS $VOD_FEATURE_DEPS"
fi

VOD_DEPS="$VOD_DEPS                                           \
          $ngx_addon_dir/ngx_async_open_file_cache.h          \
          $ngx_addon_dir/ngx_buffer_cache.h                   \
          $ngx_addon_dir/ngx_buffer_cache_internal.h          \
          $ngx_addon_dir/ngx_child_http_request.h             \
          $ngx_addon_dir/ngx_file_reader.h                    \
          $ngx_addon_dir/ngx_http_vod_conf.h                  \
          $ngx_addon_dir/ngx_http_vod_dash.h                  \
          $ngx_addon_dir/ngx_http_vod_dash_commands.h         \
          $ngx_addon_dir/ngx_http_vod_dash_conf.h             \
          $ngx_addon_dir/ngx_http_vod_hds.h                   \
          $ngx_addon_dir/ngx_http_vod_hds_commands.h          \
          $ngx_addon_dir/ngx_http_vod_hds_conf.h              \
          $ngx_addon_dir/ngx_http_vod_hls.h                   \
          $ngx_addon_dir/ngx_http_vod_hls_commands.h          \
          $ngx_addon_dir/ngx_http_vod_hls_conf.h              \
          $ngx_addon_dir/ngx_http_vod_module.h                \
          $ngx_addon_dir/ngx_http_vod_mss.h                   \
          $ngx_addon_dir/ngx_http_vod_mss_commands.h          \
          $ngx_addon_dir/ngx_http_vod_mss_conf.h              \
          $ngx_addon_dir/ngx_http_vod_request_parse.h         \
          $ngx_addon_dir/ngx_http_vod_status.h                \
          $ngx_addon_dir/ngx_http_vod_submodule.h             \
          $ngx_addon_dir/ngx_http_vod_utils.h                 \
          $ngx_addon_dir/ngx_perf_counters.h                  \
          $ngx_addon_dir/ngx_perf_counters_x.h                \
          $ngx_addon_dir/vod/aes_defs.h                       \
          $ngx_addon_dir/vod/avc_defs.h                       \
          $ngx_addon_dir/vod/avc_parser.h                     \
          $ngx_addon_dir/vod/avc_hevc_parser.h                \
          $ngx_addon_dir/vod/bit_read_stream.h                \
          $ngx_addon_dir/vod/buffer_pool.h                    \
          $ngx_addon_dir/vod/codec_config.h                   \
          $ngx_addon_dir/vod/common.h                         \
          $ngx_addon_dir/vod/dash/dash_packager.h             \
          $ngx_addon_dir/vod/dynamic_buffer.h                 \
          $ngx_addon_dir/vod/filters/audio_filter.h           \
          $ngx_addon_dir/vod/filters/concat_clip.h            \
          $ngx_addon_dir/vod/filters/dynamic_clip.h           \
          $ngx_addon_dir/vod/filters/filter.h                 \
          $ngx_addon_dir/vod/filters/gain_filter.h            \
          $ngx_addon_dir/vod/filters/mix_filter.h             \
          $ngx_addon_dir/vod/filters/rate_filter.h            \
          $ngx_addon_dir/vod/hds/hds_amf0_encoder.h           \
          $ngx_addon_dir/vod/hds/hds_amf0_fields_x.h          \
          $ngx_addon_dir/vod/hds/hds_encryption.h             \
          $ngx_addon_dir/vod/hds/hds_fragment.h               \
          $ngx_addon_dir/vod/hds/hds_manifest.h               \
          $ngx_addon_dir/vod/hevc_parser.h                    \
          $ngx_addon_dir/vod/hls/adts_encoder_filter.h        \
          $ngx_addon_dir/vod/hls/bit_fields.h                 \
          $ngx_addon_dir/vod/hls/buffer_filter.h              \
          $ngx_addon_dir/vod/hls/frame_joiner_filter.h        \
          $ngx_addon_dir/vod/hls/hls_encryption.h             \
          $ngx_addon_dir/vod/hls/hls_muxer.h                  \
          $ngx_addon_dir/vod/hls/id3_encoder_filter.h         \
          $ngx_addon_dir/vod/hls/m3u8_builder.h               \
          $ngx_addon_dir/vod/hls/media_filter.h               \
          $ngx_addon_dir/vod/hls/mp4_to_annexb_filter.h       \
          $ngx_addon_dir/vod/hls/mpegts_encoder_filter.h      \
          $ngx_addon_dir/vod/input/silence_generator.h        \
          $ngx_addon_dir/vod/input/frames_source.h            \
          $ngx_addon_dir/vod/input/frames_source_cache.h      \
          $ngx_addon_dir/vod/input/frames_source_memory.h     \
          $ngx_addon_dir/vod/input/read_cache.h               \
          $ngx_addon_dir/vod/json_parser.h                    \
          $ngx_addon_dir/vod/language_code.h                  \
          $ngx_addon_dir/vod/languages_hash_params.h          \
          $ngx_addon_dir/vod/languages_x.h                    \
          $ngx_addon_dir/vod/manifest_utils.h                 \
          $ngx_addon_dir/vod/media_clip.h                     \
          $ngx_addon_dir/vod/media_format.h                   \
          $ngx_addon_dir/vod/media_set.h                      \
          $ngx_addon_dir/vod/media_set_parser.h               \
          $ngx_addon_dir/vod/mkv/ebml.h                       \
          $ngx_addon_dir/vod/mkv/mkv_builder.h                \
          $ngx_addon_dir/vod/mkv/mkv_defs.h                   \
          $ngx_addon_dir/vod/mkv/mkv_format.h                 \
          $ngx_addon_dir/vod/mp4/mp4_clipper.h                \
          $ngx_addon_dir/vod/mp4/mp4_defs.h                   \
          $ngx_addon_dir/vod/mp4/mp4_format.h                 \
          $ngx_addon_dir/vod/mp4/mp4_fragment.h               \
          $ngx_addon_dir/vod/mp4/mp4_init_segment.h           \
          $ngx_addon_dir/vod/mp4/mp4_muxer.h                  \
          $ngx_addon_dir/vod/mp4/mp4_parser.h                 \
          $ngx_addon_dir/vod/mp4/mp4_parser_base.h            \
          $ngx_addon_dir/vod/mp4/mp4_write_stream.h           \
          $ngx_addon_dir/vod/mss/mss_packager.h               \
          $ngx_addon_dir/vod/subtitle/cap_format.h            \
          $ngx_addon_dir/vod/subtitle/dfxp_format.h           \
          $ngx_addon_dir/vod/subtitle/subtitle_format.h       \
          $ngx_addon_dir/vod/subtitle/ttml_builder.h          \
          $ngx_addon_dir/vod/subtitle/webvtt_builder.h        \
          $ngx_addon_dir/vod/subtitle/webvtt_format.h         \
          $ngx_addon_dir/vod/subtitle/webvtt_format_template.h \
          $ngx_addon_dir/vod/parse_utils.h                    \
          $ngx_addon_dir/vod/read_stream.h                    \
          $ngx_addon_dir/vod/segmenter.h                      \
          $ngx_addon_dir/vod/udrm.h                           \
          $ngx_addon_dir/vod/write_buffer.h                   \
          $ngx_addon_dir/vod/write_buffer_queue.h             \
          $ngx_addon_dir/vod/write_stream.h                   \
          "

VOD_SRCS="$VOD_SRCS                                           \
          $ngx_addon_dir/ngx_async_open_file_cache.c          \
          $ngx_addon_dir/ngx_buffer_cache.c                   \
          $ngx_addon_dir/ngx_child_http_request.c             \
          $ngx_addon_dir/ngx_file_reader.c                    \
          $ngx_addon_dir/ngx_http_vod_conf.c                  \
          $ngx_addon_dir/ngx_http_vod_dash.c                  \
          $ngx_addon_dir/ngx_http_vod_hds.c                   \
          $ngx_addon_dir/ngx_http_vod_hls.c                   \
          $ngx_addon_dir/ngx_http_vod_module.c                \
          $ngx_addon_dir/ngx_http_vod_mss.c                   \
          $ngx_addon_dir/ngx_http_vod_request_parse.c         \
          $ngx_addon_dir/ngx_http_vod_status.c                \
          $ngx_addon_dir/ngx_http_vod_submodule.c             \
          $ngx_addon_dir/ngx_http_vod_utils.c                 \
          $ngx_addon_dir/ngx_perf_counters.c                  \
          $ngx_addon_dir/vod/avc_parser.c                     \
          $ngx_addon_dir/vod/avc_hevc_parser.c                \
          $ngx_addon_dir/vod/buffer_pool.c                    \
          $ngx_addon_dir/vod/codec_config.c                   \
          $ngx_addon_dir/vod/common.c                         \
          $ngx_addon_dir/vod/dash/dash_packager.c             \
          $ngx_addon_dir/vod/dynamic_buffer.c                 \
          $ngx_addon_dir/vod/filters/audio_filter.c           \
          $ngx_addon_dir/vod/filters/concat_clip.c            \
          $ngx_addon_dir/vod/filters/dynamic_clip.c           \
          $ngx_addon_dir/vod/filters/filter.c                 \
          $ngx_addon_dir/vod/filters/gain_filter.c            \
          $ngx_addon_dir/vod/filters/mix_filter.c             \
          $ngx_addon_dir/vod/filters/rate_filter.c            \
          $ngx_addon_dir/vod/hds/hds_amf0_encoder.c           \
          $ngx_addon_dir/vod/hds/hds_fragment.c               \
          $ngx_addon_dir/vod/hds/hds_manifest.c               \
          $ngx_addon_dir/vod/hevc_parser.c                    \
          $ngx_addon_dir/vod/hls/adts_encoder_filter.c        \
          $ngx_addon_dir/vod/hls/buffer_filter.c              \
          $ngx_addon_dir/vod/hls/frame_joiner_filter.c        \
          $ngx_addon_dir/vod/hls/hls_muxer.c                  \
          $ngx_addon_dir/vod/hls/id3_encoder_filter.c         \
          $ngx_addon_dir/vod/hls/m3u8_builder.c               \
          $ngx_addon_dir/vod/hls/mp4_to_annexb_filter.c       \
          $ngx_addon_dir/vod/hls/mpegts_encoder_filter.c      \
          $ngx_addon_dir/vod/input/silence_generator.c        \
          $ngx_addon_dir/vod/input/frames_source_cache.c      \
          $ngx_addon_dir/vod/input/frames_source_memory.c     \
          $ngx_addon_dir/vod/input/read_cache.c               \
          $ngx_addon_dir/vod/json_parser.c                    \
          $ngx_addon_dir/vod/language_code.c                  \
          $ngx_addon_dir/vod/manifest_utils.c                 \
          $ngx_addon_dir/vod/media_format.c                   \
          $ngx_addon_dir/vod/media_set.c                      \
          $ngx_addon_dir/vod/media_set_parser.c               \
          $ngx_addon_dir/vod/mkv/ebml.c                       \
          $ngx_addon_dir/vod/mkv/mkv_builder.c                \
          $ngx_addon_dir/vod/mkv/mkv_defs.c                   \
          $ngx_addon_dir/vod/mkv/mkv_format.c                 \
          $ngx_addon_dir/vod/mp4/mp4_clipper.c                \
          $ngx_addon_dir/vod/mp4/mp4_format.c                 \
          $ngx_addon_dir/vod/mp4/mp4_fragment.c               \
          $ngx_addon_dir/vod/mp4/mp4_init_segment.c           \
          $ngx_addon_dir/vod/mp4/mp4_muxer.c                  \
          $ngx_addon_dir/vod/mp4/mp4_parser.c                 \
          $ngx_addon_dir/vod/mp4/mp4_parser_base.c            \
          $ngx_addon_dir/vod/mss/mss_packager.c               \
          $ngx_addon_dir/vod/subtitle/cap_format.c            \
          $ngx_addon_dir/vod/subtitle/subtitle_format.c       \
          $ngx_addon_dir/vod/subtitle/ttml_builder.c          \
          $ngx_addon_dir/vod/subtitle/webvtt_builder.c        \
          $ngx_addon_dir/vod/subtitle/webvtt_format.c         \
          $ngx_addon_dir/vod/parse_utils.c                    \
          $ngx_addon_dir/vod/segmenter.c                      \
          $ngx_addon_dir/vod/udrm.c                           \
          $ngx_addon_dir/vod/write_buffer.c                   \
          $ngx_addon_dir/vod/write_buffer_queue.c             \
          "

if [ -n "$ngx_module_link" ]; then
    ngx_module_type=HTTP_AUX_FILTER
    ngx_module_name=ngx_http_vod_module
    ngx_module_deps="$VOD_DEPS"
    ngx_module_srcs="$VOD_SRCS"

    . auto/module
else
    HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_vod_module"
    NGX_ADDON_DEPS="$NGX_ADDON_DEPS $VOD_DEPS"
    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $VOD_SRCS"
    CORE_INCS="$CORE_INCS $ngx_module_incs"
    CORE_LIBS="$CORE_LIBS $ngx_module_libs"
fi
