Permalink
Browse files

Brotli: bundle Brotli library.

Change-Id: Idbefeebe40b0a5ac87d8572758618396a563c46e
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information...
PiotrSikora committed Dec 2, 2016
1 parent 1252981 commit bfd2885b2da4d763fed18f49216bb935223cd34b
Showing with 128 additions and 176 deletions.
  1. +3 −0 .gitmodules
  2. +0 −12 README.md
  3. +124 −164 config
  4. +1 −0 deps/brotli
@@ -0,0 +1,3 @@
[submodule "deps/brotli"]
path = deps/brotli
url = https://github.com/google/brotli.git
@@ -21,18 +21,6 @@ Both Brotli library and nginx module are under active development.
$ ./configure --add-module=/path/to/ngx_brotli
$ make && make install

ngx_brotli filter module depends on
[libbrotli](https://github.com/bagder/libbrotli),
which must be installed on the target system for it to work.

Alternatively, ngx_brotli static module can be compiled into nginx by itself
with `NGX_BROTLI_STATIC_MODULE_ONLY=1` defined in the environment:

$ cd nginx-1.x.x
$ export NGX_BROTLI_STATIC_MODULE_ONLY=1
$ ./configure --add-module=/path/to/ngx_brotli
$ make && make install

## Configuration directives

### `brotli_static`
288 config
@@ -24,191 +24,151 @@

ngx_addon_name=ngx_brotli

#
# static module (no dependencies)
#
if [ -z "$ngx_module_link" ]; then
cat << END

if [ -n "$ngx_module_link" ]; then
# nginx-1.9.11+
ngx_module_type=HTTP
ngx_module_name=ngx_http_brotli_static_module
ngx_module_incs=
ngx_module_deps=
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_brotli_static_module.c"
ngx_module_libs=

. auto/module
else
HTTP_MODULES="$HTTP_MODULES \
ngx_http_brotli_static_module"

NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/src/ngx_http_brotli_static_module.c"
fi

have=NGX_HTTP_GZIP . auto/have
have=NGX_HTTP_BROTLI_STATIC_MODULE . auto/have
$0: error: Brotli module requires recent version of NGINX (1.9.11+).

if [ -n "$NGX_BROTLI_STATIC_MODULE_ONLY" ]; then
return
END
exit 1
fi

#
# filter module (depends on Brotli library)
# HTTP static module
#

# <brotli/encode.h>

ngx_feature_name=
ngx_feature_run=no
ngx_feature_incs="#include <brotli/encode.h>"
ngx_feature_test="BrotliEncoderCreateInstance(NULL, NULL, NULL)"

# auto-discovery
ngx_feature="Brotli library"
ngx_feature_path=
ngx_feature_libs="-lbrotlienc -lm"
. auto/feature

if [ $ngx_found = no ]; then
# FreeBSD, OpenBSD
ngx_feature="Brotli library in /usr/local/"
ngx_feature_path="/usr/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lbrotlienc -lm"
else
ngx_feature_libs="-L/usr/local/lib -lbrotlienc -lm"
fi
. auto/feature
fi
ngx_module_type=HTTP
ngx_module_name=ngx_http_brotli_static_module
ngx_module_incs=
ngx_module_deps=
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_brotli_static_module.c"
ngx_module_libs=
ngx_module_order=

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

if [ $ngx_found = no ]; then
# MacPorts
ngx_feature="Brotli library in /opt/local/"
ngx_feature_path="/opt/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lbrotlienc -lm"
else
ngx_feature_libs="-L/opt/local/lib -lbrotlienc -lm"
fi
. auto/feature
fi
have=NGX_HTTP_GZIP . auto/have
have=NGX_HTTP_BROTLI_STATIC . auto/have
have=NGX_HTTP_BROTLI_STATIC_MODULE . auto/have # deprecated

# <brotli/enc/encode.h>
#
# HTTP filter module with Brotli library
#

if [ $ngx_found = no ]; then
ngx_feature_name=NGX_HAVE_BROTLI_ENC_ENCODE_H
ngx_feature_run=no
ngx_feature_incs="#include <brotli/enc/encode.h>"
ngx_feature_test="BrotliEncoderCreateInstance(NULL, NULL, NULL)"
brotli="$ngx_addon_dir/deps/brotli"

# auto-discovery
ngx_feature="Brotli library"
ngx_feature_path=
ngx_feature_libs="-lbrotlienc -lm"
. auto/feature
fi
if [ ! -f "$brotli/include/brotli/encode.h" ]; then
cat << END

if [ $ngx_found = no ]; then
# FreeBSD, OpenBSD
ngx_feature="Brotli library in /usr/local/"
ngx_feature_path="/usr/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lbrotlienc -lm"
else
ngx_feature_libs="-L/usr/local/lib -lbrotlienc -lm"
fi
. auto/feature
fi
$0: error: \
Brotli library is missing from the $brotli directory.

if [ $ngx_found = no ]; then
# NetBSD
ngx_feature="Brotli library in /usr/pkg/"
ngx_feature_path="/usr/pkg/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lbrotlienc -lm"
else
ngx_feature_libs="-L/usr/pkg/lib -lbrotlienc -lm"
fi
. auto/feature
fi
Please make sure that the git submodule has been checked out:

if [ $ngx_found = no ]; then
# MacPorts
ngx_feature="Brotli library in /opt/local/"
ngx_feature_path="/opt/local/include"
if [ $NGX_RPATH = YES ]; then
ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lbrotlienc -lm"
else
ngx_feature_libs="-L/opt/local/lib -lbrotlienc -lm"
fi
. auto/feature
fi
cd $ngx_addon_dir && git submodule update --init && cd $PWD

if [ $ngx_found = no ]; then
echo "$0: error: ngx_brotli filter module requires Brotli library."
END
exit 1
fi

if [ $HTTP_GZIP = YES ]; then
next=ngx_http_gzip_filter_module
elif echo $HTTP_FILTER_MODULES | grep ngx_pagespeed_etag_filter >/dev/null; then
next=ngx_pagespeed_etag_filter
else
next=ngx_http_range_header_filter_module
fi

if [ -n "$ngx_module_link" ]; then
# nginx-1.9.11+
ngx_module_type=HTTP_FILTER
ngx_module_name=ngx_http_brotli_filter_module
ngx_module_incs="$ngx_feature_path"
ngx_module_deps=
ngx_module_srcs="$ngx_addon_dir/src/ngx_http_brotli_filter_module.c"
ngx_module_libs="$ngx_feature_libs"
ngx_module_order="$ngx_module_name \
ngx_pagespeed \
ngx_http_postpone_filter_module \
ngx_http_ssi_filter_module \
ngx_http_charset_filter_module \
ngx_http_xslt_filter_module \
ngx_http_image_filter_module \
ngx_http_sub_filter_module \
ngx_http_addition_filter_module \
ngx_http_gunzip_filter_module \
ngx_http_userid_filter_module \
ngx_http_headers_filter_module"

. auto/module

if [ $ngx_module_link != DYNAMIC ]; then
# ngx_module_order doesn't work with static modules,
# so we must re-order filters here.
HTTP_FILTER_MODULES=`echo $HTTP_FILTER_MODULES \
| sed "s/$ngx_module_name//" \
| sed "s/$next/$next $ngx_module_name/"`
ngx_module_type=HTTP_FILTER
ngx_module_name=ngx_http_brotli_filter_module
ngx_module_incs="$brotli/include"
ngx_module_deps="$brotli/common/constants.h \
$brotli/common/dictionary.h \
$brotli/common/version.h \
$brotli/enc/backward_references.h \
$brotli/enc/backward_references_inc.h \
$brotli/enc/bit_cost.h \
$brotli/enc/bit_cost_inc.h \
$brotli/enc/block_encoder_inc.h \
$brotli/enc/block_splitter.h \
$brotli/enc/block_splitter_inc.h \
$brotli/enc/brotli_bit_stream.h \
$brotli/enc/cluster.h \
$brotli/enc/cluster_inc.h \
$brotli/enc/command.h \
$brotli/enc/compress_fragment.h \
$brotli/enc/compress_fragment_two_pass.h \
$brotli/enc/context.h \
$brotli/enc/dictionary_hash.h \
$brotli/enc/entropy_encode.h \
$brotli/enc/entropy_encode_static.h \
$brotli/enc/fast_log.h \
$brotli/enc/find_match_length.h \
$brotli/enc/hash_forgetful_chain_inc.h \
$brotli/enc/hash.h \
$brotli/enc/hash_longest_match_inc.h \
$brotli/enc/hash_longest_match_quickly_inc.h \
$brotli/enc/histogram.h \
$brotli/enc/histogram_inc.h \
$brotli/enc/literal_cost.h \
$brotli/enc/memory.h \
$brotli/enc/metablock.h \
$brotli/enc/metablock_inc.h \
$brotli/enc/port.h \
$brotli/enc/prefix.h \
$brotli/enc/quality.h \
$brotli/enc/ringbuffer.h \
$brotli/enc/static_dict.h \
$brotli/enc/static_dict_lut.h \
$brotli/enc/utf8_util.h \
$brotli/enc/write_bits.h"
ngx_module_srcs="$brotli/common/dictionary.c \
$brotli/enc/backward_references.c \
$brotli/enc/bit_cost.c \
$brotli/enc/block_splitter.c \
$brotli/enc/brotli_bit_stream.c \
$brotli/enc/cluster.c \
$brotli/enc/compress_fragment.c \
$brotli/enc/compress_fragment_two_pass.c \
$brotli/enc/encode.c \
$brotli/enc/entropy_encode.c \
$brotli/enc/histogram.c \
$brotli/enc/literal_cost.c \
$brotli/enc/memory.c \
$brotli/enc/metablock.c \
$brotli/enc/static_dict.c \
$brotli/enc/utf8_util.c \
$ngx_addon_dir/src/ngx_http_brotli_filter_module.c"
ngx_module_libs="-lm"
ngx_module_order="$ngx_module_name \
ngx_pagespeed \
ngx_http_postpone_filter_module \
ngx_http_ssi_filter_module \
ngx_http_charset_filter_module \
ngx_http_xslt_filter_module \
ngx_http_image_filter_module \
ngx_http_sub_filter_module \
ngx_http_addition_filter_module \
ngx_http_gunzip_filter_module \
ngx_http_userid_filter_module \
ngx_http_headers_filter_module \
ngx_http_copy_filter_module \
ngx_http_range_body_filter_module \
ngx_http_not_modified_filter_module \
ngx_http_slice_filter_module"

. auto/module

if [ "$ngx_module_link" != DYNAMIC ]; then
# ngx_module_order doesn't work with static modules,
# so we must re-order filters here.

if [ "$HTTP_GZIP" = YES ]; then
next=ngx_http_gzip_filter_module
elif echo $HTTP_FILTER_MODULES | grep pagespeed_etag_filter >/dev/null; then
next=ngx_pagespeed_etag_filter
else
next=ngx_http_range_header_filter_module
fi
else
CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"

HTTP_FILTER_MODULES=`echo $HTTP_FILTER_MODULES \
| sed "s/$next/$next ngx_http_brotli_filter_module/"`

NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/src/ngx_http_brotli_filter_module.c"
| sed "s/$ngx_module_name//" \
| sed "s/$next/$next $ngx_module_name/"`
fi

have=NGX_HTTP_BROTLI_FILTER_MODULE . auto/have
CFLAGS="$CFLAGS -Wno-deprecated-declarations"

have=NGX_HTTP_BROTLI_FILTER . auto/have
have=NGX_HTTP_BROTLI_FILTER_MODULE . auto/have # deprecated
Submodule brotli added at 222564

0 comments on commit bfd2885

Please sign in to comment.