| # Copyright 2012 Google Inc. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # Environment Variables (Optional): |
| # MOD_PAGESPEED_DIR: absolute path to the mod_pagespeed/src directory |
| # PSOL_BINARY: absolute path to pagespeed_automatic.a |
| |
| mod_pagespeed_dir="${MOD_PAGESPEED_DIR:-unset}" |
| if [ "$mod_pagespeed_dir" = "unset" ] ; then |
| mod_pagespeed_dir="$ngx_addon_dir/psol/include" |
| build_from_source=false |
| |
| if [ ! -e "$mod_pagespeed_dir" ] ; then |
| echo "ngx_pagespeed: pagespeed optimization library not found:" |
| echo "" |
| echo " You need to separately download the pagespeed library:" |
| echo "" |
| echo " $ cd /path/to/ngx_pagespeed" |
| echo " $ wget https://dl.google.com/dl/page-speed/psol/1.6.29.3.tar.gz" |
| echo " $ tar -xzvf 1.6.29.3.tar.gz # expands to psol/" |
| echo "" |
| echo " Or see the installation instructions:" |
| echo " https://github.com/pagespeed/ngx_pagespeed#how-to-build" |
| exit 1 |
| fi |
| |
| else |
| build_from_source=true |
| fi |
| |
| echo "mod_pagespeed_dir=$mod_pagespeed_dir" |
| echo "build_from_source=$build_from_source" |
| |
| ngx_feature="psol" |
| ngx_feature_name="" |
| ngx_feature_run=no |
| ngx_feature_incs=" |
| #include \"net/instaweb/htmlparse/public/html_parse.h\" |
| #include \"net/instaweb/htmlparse/public/html_writer_filter.h\" |
| #include \"net/instaweb/util/public/string.h\" |
| #include \"net/instaweb/util/public/string_writer.h\" |
| #include \"net/instaweb/util/public/null_message_handler.h\" |
| " |
| |
| os_name='unknown_os' |
| arch_name='unknown_arch' |
| uname_os=`uname` |
| uname_arch=`uname -m` |
| |
| if [ $uname_os = 'Linux' ]; then |
| os_name='linux' |
| elif [ $uname_os = 'Darwin' ]; then |
| os_name='mac' |
| else |
| echo "OS not supported: $uname_os" |
| exit 1 |
| fi |
| |
| if [ $uname_arch = 'x86_64' -o $uname_arch = 'amd64' ]; then |
| arch_name='x64' |
| elif [ $uname_arch = 'x86_32' -o $uname_arch = 'i686' \ |
| -o $uname_arch = 'i386' ]; then |
| arch_name='ia32' |
| else |
| echo "Architecture not supported: $uname_arch" |
| exit 1 |
| fi |
| |
| if [ "$NGX_DEBUG" = "YES" ]; then |
| buildtype=Debug |
| else |
| buildtype=Release |
| fi |
| |
| # Building with HTTPS fetching enabled pulls in a version of OpenSSL that causes |
| # linker errors, so disable it here. |
| CFLAGS="$CFLAGS -DSERF_HTTPS_FETCHING=0" |
| |
| pagespeed_include="\ |
| $mod_pagespeed_dir \ |
| $mod_pagespeed_dir/third_party/chromium/src \ |
| $mod_pagespeed_dir/third_party/google-sparsehash/src \ |
| $mod_pagespeed_dir/third_party/google-sparsehash/gen/arch/$os_name/$arch_name/include \ |
| $mod_pagespeed_dir/third_party/protobuf/src \ |
| $mod_pagespeed_dir/third_party/re2/src \ |
| $mod_pagespeed_dir/out/$buildtype/obj/gen \ |
| $mod_pagespeed_dir/third_party/apr/src/include \ |
| $mod_pagespeed_dir/third_party/aprutil/src/include \ |
| $mod_pagespeed_dir/third_party/apr/gen/arch/$os_name/$arch_name/include \ |
| $mod_pagespeed_dir/third_party/aprutil/gen/arch/$os_name/$arch_name/include" |
| ngx_feature_path="$pagespeed_include" |
| |
| if $build_from_source ; then |
| psol_library_binaries="\ |
| $mod_pagespeed_dir/net/instaweb/automatic/pagespeed_automatic.a \ |
| $mod_pagespeed_dir/out/$buildtype/obj.target/third_party/serf/libserf.a \ |
| $mod_pagespeed_dir/out/$buildtype/obj.target/third_party/aprutil/libaprutil.a \ |
| $mod_pagespeed_dir/out/$buildtype/obj.target/third_party/apr/libapr.a" |
| else |
| psol_library_dir="$ngx_addon_dir/psol/lib/$buildtype/$os_name/$arch_name" |
| psol_library_binaries="\ |
| $psol_library_dir/pagespeed_automatic.a \ |
| $psol_library_dir/libserf.a \ |
| $psol_library_dir/libaprutil.a \ |
| $psol_library_dir/libapr.a" |
| fi |
| |
| pagespeed_libs="-lstdc++ $psol_library_binaries -lrt -pthread -lm" |
| ngx_feature_libs="$pagespeed_libs" |
| ngx_feature_test=" |
| GoogleString output_buffer; |
| net_instaweb::StringWriter write_to_string(&output_buffer); |
| |
| net_instaweb::NullMessageHandler handler; |
| net_instaweb::HtmlParse html_parse(&handler); |
| net_instaweb::HtmlWriterFilter html_writer_filter(&html_parse); |
| |
| html_writer_filter.set_writer(&write_to_string); |
| html_parse.AddFilter(&html_writer_filter); |
| |
| html_parse.StartParse(\"http:example.com\"); |
| html_parse.ParseText( |
| \"<html ><body ><h1 >Test</h1 ><p>Test Text</p></body></html>\n\"); |
| html_parse.FinishParse(); |
| |
| printf(\"parsed as: %s\", output_buffer.c_str())" |
| |
| # Test whether we have pagespeed and can compile and link against it. |
| . "$ngx_addon_dir/cpp_feature" |
| |
| if [ $ngx_found = yes ]; then |
| ps_src="$ngx_addon_dir/src" |
| ngx_addon_name=ngx_pagespeed |
| NGX_ADDON_DEPS="$NGX_ADDON_DEPS \ |
| $ps_src/log_message_handler.h \ |
| $ps_src/ngx_base_fetch.h \ |
| $ps_src/ngx_caching_headers.h \ |
| $ps_src/ngx_fetch.h \ |
| $ps_src/ngx_list_iterator.h \ |
| $ps_src/ngx_message_handler.h \ |
| $ps_src/ngx_pagespeed.h \ |
| $ps_src/ngx_request_context.h \ |
| $ps_src/ngx_rewrite_driver_factory.h \ |
| $ps_src/ngx_rewrite_options.h \ |
| $ps_src/ngx_server_context.h \ |
| $ps_src/ngx_thread_system.h \ |
| $ps_src/ngx_url_async_fetcher.h \ |
| $ps_src/pthread_shared_mem.h" |
| NGX_ADDON_SRCS="$NGX_ADDON_SRCS \ |
| $ps_src/log_message_handler.cc \ |
| $ps_src/ngx_base_fetch.cc \ |
| $ps_src/ngx_caching_headers.cc \ |
| $ps_src/ngx_fetch.cc \ |
| $ps_src/ngx_list_iterator.cc \ |
| $ps_src/ngx_message_handler.cc \ |
| $ps_src/ngx_pagespeed.cc \ |
| $ps_src/ngx_request_context.cc \ |
| $ps_src/ngx_rewrite_driver_factory.cc \ |
| $ps_src/ngx_rewrite_options.cc \ |
| $ps_src/ngx_server_context.cc \ |
| $ps_src/ngx_thread_system.cc \ |
| $ps_src/ngx_url_async_fetcher.cc \ |
| $ps_src/pthread_shared_mem.cc \ |
| $mod_pagespeed_dir/out/$buildtype/obj/gen/data2c_out/instaweb/net/instaweb/system/console_out.cc \ |
| $mod_pagespeed_dir/out/$buildtype/obj/gen/data2c_out/instaweb/net/instaweb/system/console_css_out.cc \ |
| $mod_pagespeed_dir/net/instaweb/system/add_headers_fetcher.cc \ |
| $mod_pagespeed_dir/net/instaweb/system/loopback_route_fetcher.cc \ |
| $mod_pagespeed_dir/net/instaweb/system/serf_url_async_fetcher.cc" |
| # Make pagespeed run immediately before gzip. |
| HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\ |
| sed "s/$HTTP_GZIP_FILTER_MODULE/$HTTP_GZIP_FILTER_MODULE $ngx_addon_name/") |
| # Make the etag header filter run immediately after gzip. |
| HTTP_FILTER_MODULES=$(echo $HTTP_FILTER_MODULES |\ |
| sed "s/$HTTP_GZIP_FILTER_MODULE/ngx_pagespeed_etag_filter $HTTP_GZIP_FILTER_MODULE/") |
| CORE_LIBS="$CORE_LIBS $pagespeed_libs" |
| CORE_INCS="$CORE_INCS $pagespeed_include" |
| else |
| cat << END |
| $0: error: module ngx_pagespeed requires the pagespeed optimization library |
| END |
| exit 1 |
| fi |
| |
| have=NGX_PAGESPEED . auto/have |