# 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.5.tar.gz" echo " $ tar -xzvf 1.6.29.5.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 # The compiler needs to know that __sync_add_and_fetch_4 is ok, # and this requires an instruction that didn't exist on i586 or i386. if [ "$uname_arch" = "i686" ]; then FLAG_MARCH='-march=i686' 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 $FLAG_MARCH" case "$NGX_GCC_VER" in 4.8*) # On GCC 4.8 and above, -Wall enables -Wunused-local-typedefs. This breaks # on VerifySizesAreEqual in bit_cast in chromium/src/base/basictypes.h which # has a typedef that is intentionally unused. CFLAGS="$CFLAGS -Wno-unused-local-typedefs" # On GCC 4.8 and above, we get the following compiler warning: # chromium/src/base/memory/scoped_ptr.h:133:7: warning: declaration of ‘class scoped_ptr’ [enabled by default] # Based on discussion at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54055, # this is invalid code, but hasn't been fixed yet in chromium. # Unfortunately, there also does not appear to be a flag for just disabling # that warning, so we add Wno-error to override nginx's default -Werror # option. CFLAGS="$CFLAGS -Wno-error" ;; esac 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( \"

Test

Test Text

\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 \ $ps_src/in_place_resource_recorder.cc \ $mod_pagespeed_dir/net/instaweb/system/loopback_route_fetcher.cc \ $mod_pagespeed_dir/net/instaweb/system/serf_url_async_fetcher.cc" # TODO(jefftk): when the next release of PSOL after 1.6.29.3 comes out, change # $ps_src/in_place_resource_recorder.cc # above to # $mod_pagespeed_dir/net/instaweb/apache/in_place_resource_recorder.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