Imported Debian patch 1.11.33.4-1
diff --git a/debian/README.Debian b/debian/README.Debian
new file mode 100644
index 0000000..b2b1d6a
--- /dev/null
+++ b/debian/README.Debian
@@ -0,0 +1,14 @@
+modpagespeed for Debian
+----------------------
+
+This is a build of mod_pagespeed for Debian which dynamically links to
+system-provided libraries as much as possible --- the usual practice
+for packaged software. This contrasts with the .deb's provided on
+mod_pagespeed site which basically statically link everything so they
+can install on a wide variety of systems.
+
+There is one downside: apachectrl graceful will not be able to load
+changed versions of the module .so, due to limitations on unloading
+imposed by dynamically linking to libprotobuf.
+
+ -- Maksim Orlovich <morlovich@google.com>  Tue, 22 Nov 2016 16:50:08 +0000
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..a70cc76
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+modpagespeed (1.11.33.4-1) unstable; urgency=medium
+
+  * Initial release (Closes: #602316)
+
+ -- Jeff Kaufman <jefftk@google.com>  Tue, 22 Nov 2016 16:50:08 +0000
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..78e37a5
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,20 @@
+Source: modpagespeed
+Section: web
+Priority: optional
+Maintainer: Jeff Kaufman <jefftk@google.com>
+Build-Depends: debhelper (>= 9), pkg-config, libapr1-dev, apache2-dev, dh-apache2,
+ libpng-dev, libicu-dev, gperf, libjpeg9-dev, zlib1g-dev, protobuf-compiler, libprotobuf-dev, libwebp-dev, 
+ libre2-dev, googletest, libgif-dev, libjsoncpp-dev, libgflags-dev
+Standards-Version: 3.9.8
+Homepage: https://developers.google.com/speed/pagespeed/module/
+Vcs-Git: https://github.com/pagespeed/mod_pagespeed.git
+Vcs-Browser: https://github.com/pagespeed/mod_pagespeed
+
+Package: libapache2-mod-pagespeed
+Architecture: i386 amd64
+Depends: ${shlibs:Depends}, ${misc:Depends}, apache2-api-20120211, ca-certificates
+Description: Apache module for rewriting web pages for efficiency
+ mod_pagespeed optimizes web pages and resources as they flow through your
+ server, saving its optimizations in a cache. Core optimizations include
+ longcaching, minifying, combining, and inlining, which it can apply to
+ JavaScript, CSS, and images.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..9ee3f84
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,282 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: modpagespeed
+Source: <https://github.com/pagespeed/mod_pagespeed>
+
+Files: *
+Copyright: 2016 Google Inc.
+License: Apache-2.0
+
+Files: src/third_party/aprutil/apr_memcache2.*
+Copyright: Apache Software Foundation
+License: Apache-2.0
+
+Files: src/third_party/base64/*
+Copyright: 2004-2008 René Nyffenegger
+License: Zlib
+
+Files: src/third_party/chromium/*
+Copyright: 2014 The Chromium Authors
+License: BSD-3-clause
+
+Files: src/third_party/chromium/src/base/third_party/dmg_fp/*
+Copyright: 1991, 2000, 2001 by Lucent Technologies
+License: dtoac
+
+Files: src/third_party/chromium/src/base/third_party/dynamic_annotations/*
+Copyright: 2008-2009 Google Inc.
+License: BSD-variant
+
+Files: src/third_party/chromium/src/base/third_party/icu/*
+       src/third_party/chromium/src/base/i18n/icu_string_conversions.cc
+Copyright: 1995-2009 International Business Machines Corporation and others
+License: ICU
+
+Files: src/third_party/chromium/src/base/third_party/nspr/*
+Copyright: 1998-2000 Netscape Communications Corporation
+           2011 Google Inc.
+License: MPL-1.1 or GPL-2+ or LGPL-2.1+
+
+Files: src/third_party/chromium/src/base/third_party/superfasthash/*
+Copyright: 2010 Paul Hsieh
+License: BSD-3-clause
+
+Files: src/third_party/chromium/src/base/third_party/symbolize/*
+Copyright: 2006 Google Inc.
+License: BSD-3-clause
+
+Files: src/third_party/chromium/src/base/third_party/valgrind/*
+Copyright: 2000-2010 Julian Seward
+License: libbz2
+
+Files: src/third_party/chromium/src/googleurl/*
+Copyright: 2007 Google Inc.
+License: BSD-3-clause
+
+Files: src/third_party/chromium/src/googleurl/src/url_parse.cc
+Copyright: 1998 Netscape Communications Corporation
+License: MPL-1.1 or GPL-2+ or LGPL-2.1+
+
+Files: src/third_party/closure_library/*
+Copyright: 2006-2013 The Closure Library Authors
+License: Apache-2.0
+
+Files: src/third_party/domain_registry_provider/*
+Copyright: 2011 Google Inc.
+License: Apache-2.0
+
+Files: src/third_party/domain_registry_provider/src/third_party/effective_tld_names/*
+Copyright: 2007–16 Mozilla Foundation
+License: MPL-2.0
+
+Files: src/third_party/google-sparsehash/*
+Copyright: 2005 Google Inc.
+License: BSD-3-clause
+
+Files: src/third_party/libwebp/*
+Copyright: 2010 Google Inc.
+License: BSD-3-clause
+
+Files: src/third_party/modp_b64/*
+Copyright: 2005, 2006  Nick Galbreath -- nickg [at] modp [dot] com
+License: BSD-3-clause
+
+Files: src/third_party/optipng/*
+Copyright: 2001-2012 Cosmin Truta and the Contributing Authors
+License: Zlib
+
+Files: src/third_party/rdestl/*
+Copyright: 2007 Maciej Sinilo
+License: Expat
+
+Files: src/third_party/serf/*
+Copyright: 2002-2012 Justin Erenkrantz and Greg Stein
+License: Apache-2.0
+
+License: Apache-2.0
+ 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
+ .
+ https://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.
+ .
+ On Debian systems, the complete text of the Apache version 2.0 license
+ can be found in "/usr/share/common-licenses/Apache-2.0".
+
+License: Expat
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+ .
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+
+License: Zlib
+ For the purpose of copyright and licensing, the list of Contributing
+ Authors is available in the accompanying AUTHORS file.
+ .
+ This software is provided 'as-is', without any express or implied
+ warranty.  In no event will the author(s) be held liable for any damages
+ arising from the use of this software.
+ .
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+ .
+ 1. The origin of this software must not be misrepresented; you must not
+    claim that you wrote the original software.  If you use this software
+    in a product, an acknowledgment in the product documentation would be
+    appreciated but is not required.
+ .
+ 2. Altered source versions must be plainly marked as such, and must not
+    be misrepresented as being the original software.
+ .
+ 3. This notice may not be removed or altered from any source distribution.
+
+License: BSD-variant
+ Copyright (c) 2008-2009, Google Inc.
+ All rights reserved.
+ .
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ .
+ * Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+ * Neither the name of Google Inc. nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+License: BSD-3-clause
+ Copyright (c) <YEAR>, <OWNER> All rights reserved.
+ .
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ .
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ .
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation 
+ and/or other materials provided with the distribution.
+ .
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without 
+ specific prior written permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ THE POSSIBILITY OF SUCH DAMAGE.
+
+License: libbz2
+ Copyright (C) 2000-2008 Julian Seward.  All rights reserved.
+ .
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ .
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ .
+ 2. The origin of this software must not be misrepresented; you must 
+    not claim that you wrote the original software.  If you use this 
+    software in a product, an acknowledgment in the product 
+    documentation would be appreciated but is not required.
+ 3. Altered source versions must be plainly marked as such, and must
+    not be misrepresented as being the original software.
+ 4. The name of the author may not be used to endorse or promote 
+    products derived from this software without specific prior written 
+    permission.
+ .
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+License: dtoac
+ The author of this software is David M. Gay.
+ .
+ Copyright (c) 1991, 2000, 2001 by Lucent Technologies.
+ .
+ Permission to use, copy, modify, and distribute this software for any
+ purpose without fee is hereby granted, provided that this entire notice
+ is included in all copies of any software which is or includes a copy
+ or modification of this software and in all copies of the supporting
+ documentation for such software.
+ .
+ THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ WARRANTY.  IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
+ REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+
+License: ICU
+ Copyright (c) 1995-2009 International Business Machines Corporation and others
+ All rights reserved.
+ .
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, and/or sell copies of the Software, and to permit persons
+ to whom the Software is furnished to do so, provided that the above
+ copyright notice(s) and this permission notice appear in all copies of
+ the Software and that both the above copyright notice(s) and this
+ permission notice appear in supporting documentation.
+ .
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY
+ SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ .
+ Except as contained in this notice, the name of a copyright holder
+ shall not be used in advertising or otherwise to promote the sale, use
+ or other dealings in this Software without prior written authorization
+ of the copyright holder.
diff --git a/debian/libapache2-mod-pagespeed.apache2 b/debian/libapache2-mod-pagespeed.apache2
new file mode 100644
index 0000000..32e5460
--- /dev/null
+++ b/debian/libapache2-mod-pagespeed.apache2
@@ -0,0 +1,4 @@
+mod src/out/Release/mod_pagespeed.so
+mod debian/pagespeed.load
+mod src/out/Release/install/common/pagespeed.conf
+conf src/net/instaweb/genfiles/conf/pagespeed_libraries.conf
diff --git a/debian/pagespeed.load b/debian/pagespeed.load
new file mode 100644
index 0000000..a534597
--- /dev/null
+++ b/debian/pagespeed.load
@@ -0,0 +1 @@
+LoadModule pagespeed_module /usr/lib/apache2/modules/mod_pagespeed.so
diff --git a/debian/patches/abi-sanity.patch b/debian/patches/abi-sanity.patch
new file mode 100644
index 0000000..80fd88a
--- /dev/null
+++ b/debian/patches/abi-sanity.patch
@@ -0,0 +1,16 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Remove C++ ABI override.
+  This is problematic for linking against system libraries.
+--- a/src/build/common.gypi
++++ b/src/build/common.gypi
+@@ -155,7 +155,9 @@
+ 
+     'defines': [ 'CHROMIUM_REVISION=<(chromium_revision)',
+                  # See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
+-                 '_GLIBCXX_USE_CXX11_ABI=0',
++                 # Don't want to mess with this on Debian, since we want to link against
++                 # packages of protobuf and the like.
++                 # '_GLIBCXX_USE_CXX11_ABI=0',
+                  '__STDC_LIMIT_MACROS',],
+ 
+     # We don't want -std=gnu++0x (enabled by some versions of libpagespeed)
diff --git a/debian/patches/add-missing-zlib-includes.patch b/debian/patches/add-missing-zlib-includes.patch
new file mode 100644
index 0000000..6be616a
--- /dev/null
+++ b/debian/patches/add-missing-zlib-includes.patch
@@ -0,0 +1,37 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Add #include <zlib.h> when needed
+--- a/src/net/instaweb/rewriter/image.cc
++++ b/src/net/instaweb/rewriter/image.cc
+@@ -56,6 +56,8 @@
+ #else
+ #include "third_party/libpng/src/png.h"
+ #endif
++
++#include <zlib.h>
+ }
+ 
+ using pagespeed::image_compression::AnalyzeImage;
+--- a/src/pagespeed/kernel/image/image_converter.cc
++++ b/src/pagespeed/kernel/image/image_converter.cc
+@@ -30,6 +30,9 @@
+ #else
+ #include "third_party/libpng/src/png.h"
+ #endif
++
++#include <zlib.h>
++
+ }  // extern "C"
+ 
+ #include "base/logging.h"
+--- a/src/pagespeed/kernel/image/png_optimizer_test.cc
++++ b/src/pagespeed/kernel/image/png_optimizer_test.cc
+@@ -37,6 +37,9 @@
+ #else
+ #include "third_party/libpng/src/png.h"
+ #endif
++
++#include <zlib.h>
++
+ }
+ 
+ namespace {
diff --git a/debian/patches/disable-mem-debug-cc.patch b/debian/patches/disable-mem-debug-cc.patch
new file mode 100644
index 0000000..e3dcf9d
--- /dev/null
+++ b/debian/patches/disable-mem-debug-cc.patch
@@ -0,0 +1,16 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Disable mem_debug.cc
+ This only matters for debug builds, but it totally breaks them;
+ it's unworkable with a proper dynamically linked build.
+
+--- a/src/pagespeed/kernel/base/mem_debug.cc
++++ b/src/pagespeed/kernel/base/mem_debug.cc
+@@ -51,7 +51,7 @@
+ // are not included in Release builds, type:
+ //   nm out/Debug/libmod_pagespeed.so   | /usr/bin/c++filt |grep 'operator new'
+ //   nm out/Release/libmod_pagespeed.so | /usr/bin/c++filt |grep 'operator new'
+-#ifndef NDEBUG
++#if 0
+ 
+ #include <cstdlib>
+ #include "base/logging.h"
diff --git a/debian/patches/external-protobuf.patch b/debian/patches/external-protobuf.patch
new file mode 100644
index 0000000..934c2af
--- /dev/null
+++ b/debian/patches/external-protobuf.patch
@@ -0,0 +1,13 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Export the right target in protobuf.gyp when using system protobuf
+--- a/src/third_party/protobuf/protobuf.gyp
++++ b/src/third_party/protobuf/protobuf.gyp
+@@ -495,7 +495,7 @@
+     }, { # use_system_protobuf==1
+       'targets': [
+         {
+-          'target_name': 'protobuf_lite',
++          'target_name': 'protobuf_full_do_not_use',
+           'type': 'none',
+           'direct_dependent_settings': {
+             'cflags': [
diff --git a/debian/patches/gflags-native.patch b/debian/patches/gflags-native.patch
new file mode 100644
index 0000000..6619d61
--- /dev/null
+++ b/debian/patches/gflags-native.patch
@@ -0,0 +1,76 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system gflags
+
+--- a/src/third_party/gflags/gflags.gyp
++++ b/src/third_party/gflags/gflags.gyp
+@@ -13,66 +13,15 @@
+ # limitations under the License.
+ 
+ {
+-  'variables': {
+-    'gflags_root': '<(DEPTH)/third_party/gflags',
+-    'conditions': [
+-      ['OS=="win"', {
+-        'gflags_gen_arch_root': '<(gflags_root)/gen/win',
+-      }, {
+-        'gflags_gen_arch_root': '<(gflags_root)/gen/posix',
+-      }],
+-    ],
+-  },
+   'targets': [
+     {
+       'target_name': 'gflags',
+-      'type': 'static_library',
+-      'include_dirs': [
+-        '<(gflags_gen_arch_root)/include/private',  # For config.h
+-        '<(gflags_gen_arch_root)/include',  # For configured files.
+-        '<(gflags_root)/src',  # For everything else.
+-      ],
+-      'defines': [
+-        # These macros exist so flags and symbols are properly
+-        # exported when building DLLs. Since we don't build DLLs, we
+-        # need to disable them.
+-        'GFLAGS_DLL_DECL=',
+-        'GFLAGS_DLL_DECLARE_FLAG=',
+-        'GFLAGS_DLL_DEFINE_FLAG=',
+-      ],
+-      'direct_dependent_settings': {
+-        'include_dirs': [
+-          '<(gflags_gen_arch_root)/include',  # For configured files.
+-          '<(gflags_root)/src',  # For everything else.
+-        ],
+-        'defines': [
+-          'GFLAGS_DLL_DECL=',
+-          'GFLAGS_DLL_DECLARE_FLAG=',
+-          'GFLAGS_DLL_DEFINE_FLAG=',
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-lgflags',
+         ],
+       },
+-      'sources': [
+-        'src/gflags.cc',
+-        'src/gflags_completions.cc',
+-        'src/gflags_reporting.cc',
+-      ],
+-      'conditions': [
+-        ['OS=="win"', {
+-          'sources': [
+-            'src/windows/port.cc',
+-          ],
+-          # Suppress warnings about WIN32_LEAN_AND_MEAN and size_t truncation.
+-          'msvs_disabled_warnings': [4005, 4267],
+-        }],
+-        # TODO(andrew): Look into fixing this warning upstream:
+-        # http://code.google.com/p/webrtc/issues/detail?id=760
+-        ['clang==1', {
+-          'cflags!': ['-Wheader-hygiene',],
+-          'xcode_settings': {
+-            'WARNING_CFLAGS!': ['-Wheader-hygiene',],
+-          },
+-        }],
+-      ],
+     },
+   ],
+ }
diff --git a/debian/patches/giflib-native.patch b/debian/patches/giflib-native.patch
new file mode 100644
index 0000000..b9a0e98
--- /dev/null
+++ b/debian/patches/giflib-native.patch
@@ -0,0 +1,141 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system giflib
+
+--- a/src/pagespeed/kernel/image/gif_reader.cc
++++ b/src/pagespeed/kernel/image/gif_reader.cc
+@@ -41,7 +41,7 @@
+ #endif
+ #endif
+ 
+-#include "third_party/giflib/lib/gif_lib.h"
++#include "gif_lib.h"
+ }
+ 
+ #if GIFLIB_MAJOR < 5 || (GIFLIB_MAJOR == 5 && GIFLIB_MINOR == 0)
+--- a/src/pagespeed/kernel/image/gif_reader.h
++++ b/src/pagespeed/kernel/image/gif_reader.h
+@@ -31,7 +31,7 @@
+ #include "pagespeed/kernel/image/scanline_utils.h"
+ 
+ extern "C" {
+-#include "third_party/giflib/lib/gif_lib.h"
++#include "gif_lib.h"
+ 
+ #ifdef USE_SYSTEM_LIBPNG
+ #include "png.h"                                               // NOLINT
+--- a/src/pagespeed/kernel/image/gif_square.h
++++ b/src/pagespeed/kernel/image/gif_square.h
+@@ -27,7 +27,7 @@
+ #include "pagespeed/kernel/image/image_util.h"
+ 
+ extern "C" {
+-#include "third_party/giflib/lib/gif_lib.h"
++#include "gif_lib.h"
+ }
+ 
+ namespace net_instaweb {
+--- a/src/third_party/giflib/giflib.gyp
++++ b/src/third_party/giflib/giflib.gyp
+@@ -13,92 +13,24 @@
+ # limitations under the License.
+ 
+ {
+-  'variables': {
+-    'pagespeed_root': '../..',
+-    'giflib_root': '<(pagespeed_root)/third_party/giflib',
+-    'giflib_src_root': '<(giflib_root)/lib',
+-    'giflib_gen_arch_root': '<(giflib_root)/gen/arch/<(OS)/<(target_arch)',
+-  },
+   'targets': [
+     {
+-      'target_name': 'giflib_core',
+-      'type': '<(library)',
+-      'sources': [
+-        'lib/gifalloc.c',
+-        'lib/gif_err.c',
+-      ]
+-    },
+-    {
+       'target_name': 'dgiflib',
+-      'type': '<(library)',
+-      'sources': [
+-        'lib/dgif_lib.c',
+-      ],
+-      'dependencies': [
+-        'giflib_core',
+-      ],
+-      'include_dirs': [
+-        '<(giflib_src_root)',
+-        '<(giflib_gen_arch_root)/include',
+-        '<(giflib_gen_arch_root)/include/private',
+-      ],
+-      'defines': [
+-        # We assume that int is 32bit on all platforms. This is the
+-        # same assumption made in basictypes.h.
+-        'UINT32=unsigned int',
+-        '_GBA_NO_FILEIO',
+-      ],
+-      'direct_dependent_settings': {
+-        'include_dirs': [
+-          '<(giflib_src_root)',
+-          '<(giflib_gen_arch_root)/include',
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-lgif',
+         ],
+-      },
+-      'xcode_settings': {
+-        'WARNING_CFLAGS': [
+-          '-Wno-pointer-sign',
+-        ],
+-      },
+-      'cflags': [
+-        '-Wno-pointer-sign',
+-      ],
++      }
+     },
+     {
+       'target_name': 'egiflib',
+-      'type': '<(library)',
+-      'sources': [
+-        'lib/egif_lib.c',
+-        'lib/gif_hash.c'
+-      ],
+-      'dependencies': [
+-        'giflib_core',
+-      ],
+-      'include_dirs': [
+-        '<(giflib_src_root)',
+-        '<(giflib_gen_arch_root)/include',
+-        '<(giflib_gen_arch_root)/include/private',
+-      ],
+-      'defines': [
+-        # We assume that int is 32bit on all platforms. This is the
+-        # same assumption made in basictypes.h.
+-        'UINT32=unsigned int',
+-        '_GBA_NO_FILEIO',
+-        'HAVE_FCNTL_H',
+-      ],
+-      'direct_dependent_settings': {
+-        'include_dirs': [
+-          '<(giflib_src_root)',
+-          '<(giflib_gen_arch_root)/include',
+-        ],
+-      },
+-      'xcode_settings': {
+-        'WARNING_CFLAGS': [
+-          '-Wno-pointer-sign',
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-lgif',
+         ],
+-      },
+-      'cflags': [
+-        '-Wno-pointer-sign',
+-      ],
++      }
+     },
+   ],
+ }
diff --git a/debian/patches/gmock-native.patch b/debian/patches/gmock-native.patch
new file mode 100644
index 0000000..454d05f
--- /dev/null
+++ b/debian/patches/gmock-native.patch
@@ -0,0 +1,362 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system gmock + gtest
+--- a/src/testing/gmock.gyp
++++ b/src/testing/gmock.gyp
+@@ -7,55 +7,11 @@
+     {
+       'target_name': 'gmock',
+       'type': 'static_library',
+-      'dependencies': [
+-        'gtest.gyp:gtest',
+-      ],
+       'sources': [
+-        # Sources based on files in r173 of gmock.
+-        'gmock/include/gmock/gmock-actions.h',
+-        'gmock/include/gmock/gmock-cardinalities.h',
+-        'gmock/include/gmock/gmock-generated-actions.h',
+-        'gmock/include/gmock/gmock-generated-function-mockers.h',
+-        'gmock/include/gmock/gmock-generated-matchers.h',
+-        'gmock/include/gmock/gmock-generated-nice-strict.h',
+-        'gmock/include/gmock/gmock-matchers.h',
+-        'gmock/include/gmock/gmock-spec-builders.h',
+-        'gmock/include/gmock/gmock.h',
+-        'gmock/include/gmock/internal/gmock-generated-internal-utils.h',
+-        'gmock/include/gmock/internal/gmock-internal-utils.h',
+-        'gmock/include/gmock/internal/gmock-port.h',
+-        'gmock/src/gmock-all.cc',
+-        'gmock/src/gmock-cardinalities.cc',
+-        'gmock/src/gmock-internal-utils.cc',
+-        'gmock/src/gmock-matchers.cc',
+-        'gmock/src/gmock-spec-builders.cc',
+-        'gmock/src/gmock.cc',
+-        'gmock_mutant.h',  # gMock helpers
+-      ],
+-      'sources!': [
+-        'gmock/src/gmock-all.cc',  # Not needed by our build.
++        '/usr/src/googletest/googlemock/src/gmock-all.cc',
+       ],
+       'include_dirs': [
+-        'gmock',
+-        'gmock/include',
+-      ],
+-      'direct_dependent_settings': {
+-        'include_dirs': [
+-          'gmock/include',  # So that gmock headers can find themselves.
+-        ],
+-      },
+-      'export_dependent_settings': [
+-        'gtest.gyp:gtest',
+-      ],
+-    },
+-    {
+-      'target_name': 'gmock_main',
+-      'type': 'static_library',
+-      'dependencies': [
+-        'gmock',
+-      ],
+-      'sources': [
+-        'gmock/src/gmock_main.cc',
++        '/usr/src/googletest/googlemock/',
+       ],
+     },
+   ],
+--- a/src/testing/gtest.gyp
++++ b/src/testing/gtest.gyp
+@@ -8,238 +8,27 @@
+       'target_name': 'gtest',
+       'type': 'static_library',
+       'sources': [
+-        'gtest/include/gtest/gtest-death-test.h',
+-        'gtest/include/gtest/gtest-message.h',
+-        'gtest/include/gtest/gtest-param-test.h',
+-        'gtest/include/gtest/gtest-printers.h',
+-        'gtest/include/gtest/gtest-spi.h',
+-        'gtest/include/gtest/gtest-test-part.h',
+-        'gtest/include/gtest/gtest-typed-test.h',
+-        'gtest/include/gtest/gtest.h',
+-        'gtest/include/gtest/gtest_pred_impl.h',
+-        'gtest/include/gtest/internal/gtest-death-test-internal.h',
+-        'gtest/include/gtest/internal/gtest-filepath.h',
+-        'gtest/include/gtest/internal/gtest-internal.h',
+-        'gtest/include/gtest/internal/gtest-linked_ptr.h',
+-        'gtest/include/gtest/internal/gtest-param-util-generated.h',
+-        'gtest/include/gtest/internal/gtest-param-util.h',
+-        'gtest/include/gtest/internal/gtest-port.h',
+-        'gtest/include/gtest/internal/gtest-string.h',
+-        'gtest/include/gtest/internal/gtest-tuple.h',
+-        'gtest/include/gtest/internal/gtest-type-util.h',
+-        'gtest/src/gtest-all.cc',
+-        'gtest/src/gtest-death-test.cc',
+-        'gtest/src/gtest-filepath.cc',
+-        'gtest/src/gtest-internal-inl.h',
+-        'gtest/src/gtest-port.cc',
+-        'gtest/src/gtest-printers.cc',
+-        'gtest/src/gtest-test-part.cc',
+-        'gtest/src/gtest-typed-test.cc',
+-        'gtest/src/gtest.cc',
+-        'multiprocess_func_list.cc',
+-        'multiprocess_func_list.h',
+-        'platform_test.h',
+-      ],
+-      'sources!': [
+-        'gtest/src/gtest-all.cc',  # Not needed by our build.
++        '/usr/src/googletest/googletest/src/gtest-all.cc',
+       ],
+       'include_dirs': [
+-        'gtest',
+-        'gtest/include',
+-      ],
+-      'dependencies': [
+-        'gtest_prod',
++        '/usr/src/googletest/googletest/',
+       ],
+-      'defines': [
+-        # In order to allow regex matches in gtest to be shared between Windows
+-        # and other systems, we tell gtest to always use it's internal engine.
+-        'GTEST_HAS_POSIX_RE=0',
+-      ],
+-      'all_dependent_settings': {
+-        'defines': [
+-          'GTEST_HAS_POSIX_RE=0',
+-        ],
+-      },
+-      'conditions': [
+-        ['OS == "mac" or OS == "ios"', {
+-          'sources': [
+-            'gtest_mac.h',
+-            'gtest_mac.mm',
+-            'platform_test_mac.mm'
+-          ],
+-          'link_settings': {
+-            'libraries': [
+-              '$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
+-            ],
+-          },
+-        }],
+-        ['OS == "ios"', {
+-          'dependencies' : [
+-            '<(DEPTH)/testing/iossim/iossim.gyp:iossim#host',
+-          ],
+-          'direct_dependent_settings': {
+-            'target_conditions': [
+-              # Turn all tests into bundles on iOS because that's the only
+-              # type of executable supported for iOS.
+-              ['_type=="executable"', {
+-                'variables': {
+-                  # Use a variable so the path gets fixed up so it is always
+-                  # correct when INFOPLIST_FILE finally gets set.
+-                  'ios_unittest_info_plist_path':
+-                    '<(DEPTH)/testing/gtest_ios/unittest-Info.plist',
+-                },
+-                'mac_bundle': 1,
+-                'xcode_settings': {
+-                  'BUNDLE_ID_TEST_NAME':
+-                    '>!(echo ">(_target_name)" | sed -e "s/_//g")',
+-                  'INFOPLIST_FILE': '>(ios_unittest_info_plist_path)',
+-                },
+-                'mac_bundle_resources': [
+-                  '<(ios_unittest_info_plist_path)',
+-                  '<(DEPTH)/testing/gtest_ios/Default-568h@2x.png',
+-                ],
+-                'mac_bundle_resources!': [
+-                  '<(ios_unittest_info_plist_path)',
+-                ],
+-              }],
+-            ],
+-          },
+-        }],
+-        ['OS=="ios" and asan==1', {
+-          'direct_dependent_settings': {
+-            'target_conditions': [
+-              # Package the ASan runtime dylib into the test app bundles.
+-              ['_type=="executable"', {
+-                'postbuilds': [
+-                  {
+-                    'variables': {
+-                      # Define copy_asan_dylib_path in a variable ending in
+-                      # _path so that gyp understands it's a path and
+-                      # performs proper relativization during dict merging.
+-                      'copy_asan_dylib_path':
+-                        '<(DEPTH)/build/mac/copy_asan_runtime_dylib.sh',
+-                    },
+-                    'postbuild_name': 'Copy ASan runtime dylib',
+-                    'action': [
+-                      '>(copy_asan_dylib_path)',
+-                    ],
+-                  },
+-                ],
+-              }],
+-            ],
+-          },
+-        }],
+-        ['os_posix == 1', {
+-          'defines': [
+-            # gtest isn't able to figure out when RTTI is disabled for gcc
+-            # versions older than 4.3.2, and assumes it's enabled.  Our Mac
+-            # and Linux builds disable RTTI, and cannot guarantee that the
+-            # compiler will be 4.3.2. or newer.  The Mac, for example, uses
+-            # 4.2.1 as that is the latest available on that platform.  gtest
+-            # must be instructed that RTTI is disabled here, and for any
+-            # direct dependents that might include gtest headers.
+-            'GTEST_HAS_RTTI=0',
+-          ],
+-          'direct_dependent_settings': {
+-            'defines': [
+-              'GTEST_HAS_RTTI=0',
+-            ],
+-          },
+-        }],
+-        ['OS=="android" and android_app_abi=="x86"', {
+-          'defines': [
+-            'GTEST_HAS_CLONE=0',
+-          ],
+-          'direct_dependent_settings': {
+-            'defines': [
+-              'GTEST_HAS_CLONE=0',
+-            ],
+-          },
+-        }],
+-        ['OS=="android"', {
+-          # We want gtest features that use tr1::tuple, but we currently
+-          # don't support the variadic templates used by libstdc++'s
+-          # implementation. gtest supports this scenario by providing its
+-          # own implementation but we must opt in to it.
+-          'defines': [
+-            'GTEST_USE_OWN_TR1_TUPLE=1',
+-            # GTEST_USE_OWN_TR1_TUPLE only works if GTEST_HAS_TR1_TUPLE is set.
+-            # gtest r625 made it so that GTEST_HAS_TR1_TUPLE is set to 0
+-            # automatically on android, so it has to be set explicitly here.
+-            'GTEST_HAS_TR1_TUPLE=1',
+-          ],
+-          'direct_dependent_settings': {
+-            'defines': [
+-              'GTEST_USE_OWN_TR1_TUPLE=1',
+-              'GTEST_HAS_TR1_TUPLE=1',
+-            ],
+-          },
+-        }],
+-        ['OS=="win" and (MSVS_VERSION=="2012" or MSVS_VERSION=="2012e")', {
+-          'defines': [
+-            '_VARIADIC_MAX=10',
+-          ],
+-          'direct_dependent_settings': {
+-            'defines': [
+-              '_VARIADIC_MAX=10',
+-            ],
+-          },
+-        }],
+-      ],
+-      'direct_dependent_settings': {
+-        'defines': [
+-          'UNIT_TEST',
+-        ],
+-        'include_dirs': [
+-          'gtest/include',  # So that gtest headers can find themselves.
+-        ],
+-        'target_conditions': [
+-          ['_type=="executable"', {
+-            'test': 1,
+-            'conditions': [
+-              ['OS=="mac"', {
+-                'run_as': {
+-                  'action????': ['${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}'],
+-                },
+-              }],
+-              ['OS=="ios"', {
+-                'variables': {
+-                  # Use a variable so the path gets fixed up so it is always
+-                  # correct when the action finally gets used.
+-                  'ios_run_unittest_script_path':
+-                    '<(DEPTH)/testing/gtest_ios/run-unittest.sh',
+-                },
+-                'run_as': {
+-                  'action????': ['>(ios_run_unittest_script_path)'],
+-                },
+-              }],
+-              ['OS=="win"', {
+-                'run_as': {
+-                  'action????': ['$(TargetPath)', '--gtest_print_time'],
+-                },
+-              }],
+-            ],
+-          }],
+-        ],
+-        'msvs_disabled_warnings': [4800],
+-      },
+     },
+     {
+       'target_name': 'gtest_main',
+       'type': 'static_library',
++      'sources': [
++        '/usr/src/googletest/googletest/src/gtest_main.cc',
++      ],
+       'dependencies': [
+         'gtest',
+       ],
+-      'sources': [
+-        'gtest/src/gtest_main.cc',
+-      ],
+     },
+     {
+       'target_name': 'gtest_prod',
+-      'toolsets': ['host', 'target'],
+       'type': 'none',
+-      'sources': [
+-        'gtest/include/gtest/gtest_prod.h',
++      'dependencies': [
++        'gtest',
+       ],
+     },
+   ],
+--- a/src/pagespeed/kernel/base/gtest.h
++++ b/src/pagespeed/kernel/base/gtest.h
+@@ -22,7 +22,7 @@
+ 
+ #include "pagespeed/kernel/base/string.h"
+ #include "pagespeed/kernel/base/string_util.h"
+-#include "testing/gtest/include/gtest/gtest.h"
++#include "gtest/gtest.h"
+ 
+ namespace net_instaweb {
+ 
+--- a/src/pagespeed/kernel/base/gtest_prod.h
++++ b/src/pagespeed/kernel/base/gtest_prod.h
+@@ -20,6 +20,6 @@
+ #define PAGESPEED_KERNEL_BASE_GTEST_PROD_H_
+ 
+ 
+-#include "testing/gtest/include/gtest/gtest_prod.h"
++#include "gtest/gtest_prod.h"
+ 
+ #endif  // PAGESPEED_KERNEL_BASE_GTEST_PROD_H_
+--- a/src/third_party/chromium/src/base/gtest_prod_util.h
++++ b/src/third_party/chromium/src/base/gtest_prod_util.h
+@@ -5,7 +5,7 @@
+ #ifndef BASE_GTEST_PROD_UTIL_H_
+ #define BASE_GTEST_PROD_UTIL_H_
+ 
+-#include "testing/gtest/include/gtest/gtest_prod.h"
++#include "gtest/gtest_prod.h"
+ 
+ // This is a wrapper for gtest's FRIEND_TEST macro that friends
+ // test with all possible prefixes. This is very helpful when changing the test
+--- a/src/third_party/css_parser/src/testing/base/public/gunit.h
++++ b/src/third_party/css_parser/src/testing/base/public/gunit.h
+@@ -16,6 +16,6 @@
+ #ifndef TESTING_BASE_PUBLIC_GUNIT_H_
+ #define TESTING_BASE_PUBLIC_GUNIT_H_
+ 
+-#include "testing/gtest/include/gtest/gtest.h"
++#include "gtest/gtest.h"
+ 
+ #endif  // TESTING_BASE_PUBLIC_GUNIT_H_
+--- a/src/third_party/css_parser/src/testing/production_stub/public/gunit_prod.h
++++ b/src/third_party/css_parser/src/testing/production_stub/public/gunit_prod.h
+@@ -16,6 +16,6 @@
+ #ifndef WEBUTIL_CSS_OPEN_SOURCE_TESTING_PRODUCTION_STUB_PUBLIC_GUNIT_PROD_H_
+ #define WEBUTIL_CSS_OPEN_SOURCE_TESTING_PRODUCTION_STUB_PUBLIC_GUNIT_PROD_H_
+ 
+-#include "testing/gtest/include/gtest/gtest_prod.h"
++#include "gtest/gtest_prod.h"
+ 
+ #endif  // WEBUTIL_CSS_OPEN_SOURCE_TESTING_PRODUCTION_STUB_PUBLIC_GUNIT_PROD_H_
diff --git a/debian/patches/icu-native-includes.patch b/debian/patches/icu-native-includes.patch
new file mode 100644
index 0000000..9ecf50e
--- /dev/null
+++ b/debian/patches/icu-native-includes.patch
@@ -0,0 +1,36 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Pick up system ICU includes; don't look for bundled ones.
+--- a/src/third_party/chromium/src/base/i18n/icu_string_conversions.cc
++++ b/src/third_party/chromium/src/base/i18n/icu_string_conversions.cc
+@@ -11,11 +11,11 @@
+ #include "base/memory/scoped_ptr.h"
+ #include "base/strings/string_util.h"
+ #include "base/strings/utf_string_conversions.h"
+-#include "third_party/icu/source/common/unicode/ucnv.h"
+-#include "third_party/icu/source/common/unicode/ucnv_cb.h"
+-#include "third_party/icu/source/common/unicode/ucnv_err.h"
+-#include "third_party/icu/source/common/unicode/unorm.h"
+-#include "third_party/icu/source/common/unicode/ustring.h"
++#includ  <unicode/ucnv.h>
++#include <unicode/ucnv_cb.h>
++#include <unicode/ucnv_err.h>
++#include <unicode/unorm.h>
++#include <unicode/ustring.h>
+ 
+ namespace base {
+ 
+--- a/src/url/url_canon_icu.cc
++++ b/src/url/url_canon_icu.cc
+@@ -9,9 +9,9 @@
+ 
+ #include "base/lazy_instance.h"
+ #include "base/logging.h"
+-#include "third_party/icu/source/common/unicode/ucnv.h"
+-#include "third_party/icu/source/common/unicode/ucnv_cb.h"
+-#include "third_party/icu/source/common/unicode/uidna.h"
++#include <unicode/ucnv.h>
++#include <unicode/ucnv_cb.h>
++#include <unicode/uidna.h>
+ #include "third_party/chromium/src/googleurl/src/url_canon_icu.h"
+ #include "third_party/chromium/src/googleurl/src/url_canon_internal.h"  // for _itoa_s
+ 
diff --git a/debian/patches/increase-test-fuzzyness.patch b/debian/patches/increase-test-fuzzyness.patch
new file mode 100644
index 0000000..444838e
--- /dev/null
+++ b/debian/patches/increase-test-fuzzyness.patch
@@ -0,0 +1,92 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Relax image size comparisons in compression tests
+
+--- a/src/net/instaweb/rewriter/image_rewrite_filter_test.cc
++++ b/src/net/instaweb/rewriter/image_rewrite_filter_test.cc
+@@ -1244,7 +1244,7 @@
+     // optimized image may change value slightly. To be resistant to such
+     // change, we check the content size in a ragne, in stead of the exact
+     // value. The range is defined by variable "threshold".
+-    const int threshold = 30;
++    const int threshold = 200;
+     int content_length = response_content.length();
+     EXPECT_LE(expected_content_length - threshold, content_length)
+         << content_length;
+--- a/src/pagespeed/kernel/image/image_converter_test.cc
++++ b/src/pagespeed/kernel/image/image_converter_test.cc
+@@ -317,7 +317,7 @@
+         &message_handler_));
+ 
+     // Verify that the size matches.
+-    EXPECT_EQ(kValidImages[i].compressed_size, out.size())
++    EXPECT_NEAR(kValidImages[i].compressed_size, out.size(), 20)
+         << "size mismatch for " << kValidImages[i].filename;
+     // Verify that out put image type matches.
+ 
+@@ -371,7 +371,7 @@
+     ASSERT_TRUE(ImageConverter::ConvertPngToJpeg(
+         *png_struct_reader_, in, options, &out, &message_handler_));
+     // Verify that the size matches.
+-    EXPECT_EQ(kValidGifImages[i].jpeg_size, out.size())
++    EXPECT_NEAR(kValidGifImages[i].jpeg_size, out.size(), 10)
+         << "output size mismatch for " << kValidGifImages[i].filename;
+   }
+ }
+--- a/src/pagespeed/kernel/image/jpeg_optimizer_test.cc
++++ b/src/pagespeed/kernel/image/jpeg_optimizer_test.cc
+@@ -148,7 +148,7 @@
+         << kValidImages[i].filename;
+     EXPECT_EQ(kValidImages[i].original_size, src_data.size())
+         << kValidImages[i].filename;
+-    EXPECT_EQ(kValidImages[i].lossy_compressed_size, dest_data.size())
++    EXPECT_NEAR(kValidImages[i].lossy_compressed_size, dest_data.size(), 500)
+         << kValidImages[i].filename;
+   }
+ }
+@@ -168,13 +168,13 @@
+                                       &message_handler_));
+   size_t lossy_420_size =
+       kValidImages[test_422_file_idx].lossy_compressed_size;
+-  EXPECT_EQ(lossy_420_size, dest_data.size()) << src_filename;
++  EXPECT_NEAR(lossy_420_size, dest_data.size(), 10) << src_filename;
+   AssertColorSampling(dest_data, 2, 2);
+ 
+   // Calling optimize with ColorSampling::YUV420 will give samping as 420.
+   AssertJpegOptimizeWithSampling(src_data, &dest_data,
+                                  pagespeed::image_compression::YUV420, 2, 2);
+-  EXPECT_EQ(lossy_420_size, dest_data.size()) << src_filename;
++  EXPECT_NEAR(lossy_420_size, dest_data.size(), 5) << src_filename;
+ 
+   // Calling optimize with ColorSampling::RETAIN will leave samping as 422.
+   AssertJpegOptimizeWithSampling(src_data, &dest_data,
+@@ -328,8 +328,8 @@
+         << kValidImages[i].filename;
+     EXPECT_EQ(kValidImages[i].original_size, src_data.size())
+         << kValidImages[i].filename;
+-    EXPECT_EQ(kValidImages[i].progressive_and_lossy_compressed_size,
+-              dest_data.size()) << kValidImages[i].filename;
++    EXPECT_NEAR(kValidImages[i].progressive_and_lossy_compressed_size,
++                dest_data.size(), 500) << kValidImages[i].filename;
+   }
+ }
+ 
+--- a/src/pagespeed/kernel/image/png_optimizer_test.cc
++++ b/src/pagespeed/kernel/image/png_optimizer_test.cc
+@@ -501,7 +501,7 @@
+ 
+   ASSERT_TRUE(PngOptimizer::OptimizePng(*reader, in, &out, &message_handler))
+       << info.filename;
+-  EXPECT_EQ(info.compressed_size_default, out.size()) << info.filename;
++  EXPECT_NEAR(info.compressed_size_default, out.size(), 10) << info.filename;
+   AssertPngEq(ref, out, info.filename, in_rgba);
+ 
+   ASSERT_TRUE(png_reader.GetAttributes(
+@@ -511,7 +511,7 @@
+ 
+   ASSERT_TRUE(PngOptimizer::OptimizePngBestCompression(*reader, in, &out,
+       &message_handler)) << info.filename;
+-  EXPECT_EQ(info.compressed_size_best, out.size()) << info.filename;
++  EXPECT_NEAR(info.compressed_size_best, out.size(), 10) << info.filename;
+   AssertPngEq(ref, out, info.filename, in_rgba);
+ 
+   ASSERT_TRUE(png_reader.GetAttributes(
diff --git a/debian/patches/jpeg-reader-test-fuzzy-match.patch b/debian/patches/jpeg-reader-test-fuzzy-match.patch
new file mode 100644
index 0000000..a7c9613
--- /dev/null
+++ b/debian/patches/jpeg-reader-test-fuzzy-match.patch
@@ -0,0 +1,20 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Fuzzy comparison for JPEG decoding results (test only)
+--- a/src/pagespeed/kernel/image/jpeg_reader_test.cc
++++ b/src/pagespeed/kernel/image/jpeg_reader_test.cc
+@@ -66,10 +66,11 @@
+     GoogleString jpeg_image, png_image;
+     ReadTestFile(kJpegTestDir, kValidJpegImages[i], "jpg", &jpeg_image);
+     ReadTestFile(kJpegTestDir, kValidJpegImages[i], "png", &png_image);
+-    DecodeAndCompareImages(IMAGE_PNG, png_image.c_str(), png_image.length(),
+-                           IMAGE_JPEG, jpeg_image.c_str(), jpeg_image.length(),
+-                           false,  // ignore_transparent_rgb
+-                           &message_handler);
++    DecodeAndCompareImagesByPSNR(IMAGE_PNG, png_image.c_str(), png_image.length(),
++                                 IMAGE_JPEG, jpeg_image.c_str(), jpeg_image.length(),
++                                 45,  // PSNR goal
++                                 false,  // ignore_transparent_rgb
++                                 &message_handler);
+   }
+ }
+ 
diff --git a/debian/patches/libpng-no-private.patch b/debian/patches/libpng-no-private.patch
new file mode 100644
index 0000000..a0542a5
--- /dev/null
+++ b/debian/patches/libpng-no-private.patch
@@ -0,0 +1,143 @@
+From: Maks Orlovich <morlovich@google.com>
+Subject: Stop using private libpng data, but rather the public API.
+ This is needed to build on Debian sid against system libpng, which is always 1.6.
+ Also stop using png_sizeof, it's the same as sizeof in practice,
+ and is gone in 1.6.
+Origin: upstream, https://github.com/pagespeed/mod_pagespeed/commit/2fcfa08ce1c168c3669067c2047cbc8875d677a2
+--- a/src/pagespeed/kernel/image/gif_reader.cc
++++ b/src/pagespeed/kernel/image/gif_reader.cc
+@@ -108,7 +108,10 @@
+                           int transparent_palette_index,
+                           MessageHandler* handler) {
+   const int num_trans = transparent_palette_index + 1;
+-  if (num_trans <= 0 || num_trans > info_ptr->num_palette) {
++  png_colorp palette;
++  int num_palette = 0;
++  png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
++  if (num_trans <= 0 || num_trans > num_palette) {
+     PS_LOG_INFO(handler, "Transparent palette index out of bounds.");
+     return false;
+   }
+@@ -177,12 +180,13 @@
+     return false;
+   }
+ 
++  png_bytepp rows = png_get_rows(png_ptr, info_ptr);
+   if (gif_file->Image.Interlace == 0) {
+     // Not interlaced. Read each line into the PNG buffer.
+     for (GifWord i = 0; i < height; ++i) {
+       if (DGifGetLine(gif_file,
+                       static_cast<GifPixelType*>(
+-                          &info_ptr->row_pointers[row + i][pixel]),
++                          &rows[row + i][pixel]),
+                       width) == GIF_ERROR) {
+         PS_DLOG_INFO(handler, "Failed to DGifGetLine");
+         return false;
+@@ -197,7 +201,7 @@
+            j += kInterlaceJumps[i]) {
+         if (DGifGetLine(gif_file,
+                         static_cast<GifPixelType*>(
+-                            &info_ptr->row_pointers[j][pixel]),
++                            &rows[j][pixel]),
+                         width) == GIF_ERROR) {
+           PS_DLOG_INFO(handler, "Failed to DGifGetLine");
+           return false;
+@@ -206,7 +210,7 @@
+     }
+   }
+ 
+-  info_ptr->valid |= PNG_INFO_IDAT;
++  png_set_rows(png_ptr, info_ptr, rows);
+   return true;
+ }
+ 
+@@ -274,23 +278,22 @@
+     return 0;
+   }
+ 
+-#ifdef PNG_FREE_ME_SUPPORTED
+   png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
+-#endif
+-  if (info_ptr->row_pointers == NULL) {
++  if (png_get_rows(png_ptr, info_ptr) == NULL) {
++    png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
++
+     // Allocate the array of pointers to each row.
+     const png_size_t row_pointers_size =
+-        info_ptr->height * png_sizeof(png_bytep);
+-    info_ptr->row_pointers = static_cast<png_bytepp>(
++        height * sizeof(png_bytep);
++    png_bytepp row_pointers = static_cast<png_bytepp>(
+         png_malloc(png_ptr, row_pointers_size));
+-    memset(info_ptr->row_pointers, 0, row_pointers_size);
+-#ifdef PNG_FREE_ME_SUPPORTED
+-    info_ptr->free_me |= PNG_FREE_ROWS;
+-#endif
++    memset(row_pointers, 0, row_pointers_size);
++    png_set_rows(png_ptr, info_ptr, row_pointers);
++    png_data_freer(png_ptr, info_ptr, PNG_DESTROY_WILL_FREE_DATA, PNG_FREE_ROWS);
+ 
+     // Allocate memory for each row.
+-    for (png_uint_32 row = 0; row < info_ptr->height; ++row) {
+-      info_ptr->row_pointers[row] =
++    for (png_uint_32 row = 0; row < height; ++row) {
++      row_pointers[row] =
+           static_cast<png_bytep>(png_malloc(png_ptr, row_size));
+     }
+   }
+@@ -327,14 +330,17 @@
+     return false;
+   }
+ 
++  png_bytepp rgb_row_pointers = png_get_rows(rgb_png_ptr, rgb_info_ptr);
++  png_bytepp pal_row_pointers = png_get_rows(paletted_png_ptr,
++                                             paletted_info_ptr);
+   for (png_uint_32 row = 0; row < height; ++row) {
+-    png_bytep rgb_next_byte = rgb_info_ptr->row_pointers[row];
++    png_bytep rgb_next_byte = rgb_row_pointers[row];
+     if (have_alpha) {
+       // Make the row opaque initially.
+       memset(rgb_next_byte, 0xff, row_size);
+     }
+     for (png_uint_32 column = 0; column < width; ++column) {
+-      png_byte palette_entry = paletted_info_ptr->row_pointers[row][column];
++      png_byte palette_entry = pal_row_pointers[row][column];
+       if (have_alpha &&
+           (palette_entry == static_cast<png_byte>(transparent_palette_index))) {
+         // Transparent: clear RGBA bytes.
+@@ -346,7 +352,7 @@
+       rgb_next_byte += bytes_per_pixel;
+     }
+   }
+-  rgb_info_ptr->valid |= PNG_INFO_IDAT;
++  png_set_rows(rgb_png_ptr, rgb_info_ptr, rgb_row_pointers);
+   return true;
+ }
+ 
+@@ -358,7 +364,7 @@
+                   bool require_opaque,
+                   MessageHandler* handler) {
+   if (static_cast<png_size_t>(gif_file->SHeight) >
+-      PNG_UINT_32_MAX/png_sizeof(png_bytep)) {
++      PNG_UINT_32_MAX/sizeof(png_bytep)) {
+     PS_DLOG_INFO(handler, "GIF image is too big to process.");
+     return false;
+   }
+@@ -407,12 +413,11 @@
+   }
+ 
+   // Fill the rows with the background color.
+-  memset(paletted_info_ptr->row_pointers[0],
+-         gif_file->SBackGroundColor, row_size);
+-  for (png_uint_32 row = 1; row < paletted_info_ptr->height; ++row) {
+-    memcpy(paletted_info_ptr->row_pointers[row],
+-           paletted_info_ptr->row_pointers[0],
+-           row_size);
++  png_bytepp row_pointers = png_get_rows(paletted_png_ptr, paletted_info_ptr);
++  png_uint_32 height = png_get_image_height(paletted_png_ptr, paletted_info_ptr);
++  memset(row_pointers[0], gif_file->SBackGroundColor, row_size);
++  for (png_uint_32 row = 1; row < height; ++row) {
++    memcpy(row_pointers[row], row_pointers[0], row_size);
+   }
+ 
+   int transparent_palette_index = -1;
diff --git a/debian/patches/libpng-padding-init.patch b/debian/patches/libpng-padding-init.patch
new file mode 100644
index 0000000..da3befc
--- /dev/null
+++ b/debian/patches/libpng-padding-init.patch
@@ -0,0 +1,49 @@
+From: Maks Orlovich <morlovich@google.com>
+Subject: Provide a custom allocation wrapper for libpng, that mostly just uses
+ malloc, but makes sure that padding bytes at very end are deterministically
+ zero.
+ .
+ Reason: Testing on native builds on Debian Sid suggested that *something* in
+ our compression stack was apparently letting some of the padding bytes
+ influence the output. (Noticeable on PngOptimizerTest.ValidPngs).
+ This works around the issue.
+Origin: upstream, https://github.com/pagespeed/mod_pagespeed/commit/a99ea36b31e78abd24ec83cb0b7cbde407f4e517
+--- a/src/pagespeed/kernel/image/png_optimizer.cc
++++ b/src/pagespeed/kernel/image/png_optimizer.cc
+@@ -49,6 +49,28 @@
+ 
+ namespace {
+ 
++// A wrapper that ensures that any padding bytes are initialized
++// deterministically.
++void* PngWrapMalloc(png_structp ptr, png_size_t size) {
++  if ((size & 7) == 0) {
++    return malloc(size);
++  } else {
++    png_size_t extra = 8 - (size & 7);
++    png_size_t rounded = size + extra;
++    DCHECK_NE(rounded, 0);
++    if (rounded == 0) {
++      return nullptr;
++    }
++    char* p = reinterpret_cast<char*>(malloc(rounded));
++    memset(p + (rounded - 8), 0, 8);
++    return p;
++  }
++}
++
++static void PngWrapFree(png_structp, png_voidp ptr) {
++  free(ptr);
++}
++
+ // we use these four combinations because different images seem to benefit from
+ // different parameters and this combination of 4 seems to work best for a large
+ // set of PNGs from the web.
+@@ -184,6 +206,7 @@
+     info_ptr_ = png_create_info_struct(png_ptr_);
+   }
+ 
++  png_set_mem_fn(png_ptr_, nullptr, &PngWrapMalloc, &PngWrapFree);
+   png_set_error_fn(png_ptr_, message_handler_, &PngErrorFn, &PngWarningFn);
+ }
+ 
diff --git a/debian/patches/libpng16-compat.patch b/debian/patches/libpng16-compat.patch
new file mode 100644
index 0000000..0425c07
--- /dev/null
+++ b/debian/patches/libpng16-compat.patch
@@ -0,0 +1,62 @@
+From: Maks Orlovich <morlovich@google.com>
+Subject: libpng1.6 compat: don't call png_read_update_info twice.
+ (From libpng docs on changes in 1.6.x:
+ "The library now issues an error if the application attempts to set a
+ transform after it calls png_read_update_info() or if it attempts to call
+ both png_read_update_info() and png_start_read_image() or to call either
+ of them more than once.")
+Origin: upstream, https://github.com/pagespeed/mod_pagespeed/commit/06fb3c1604b0c89c7db9118e3dcff246cdfd8b84
+--- a/src/pagespeed/kernel/image/png_optimizer.cc
++++ b/src/pagespeed/kernel/image/png_optimizer.cc
+@@ -974,29 +974,25 @@
+   // Set up callbacks for interlacing (progressive) image.
+   png_set_interlace_handling(png_ptr);
+ 
++  if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
++      (color_type == PNG_COLOR_TYPE_GRAY &&
++       png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) {
++    // Expand Gray_Alpha (and Gray + tRNS which will be turned into
++    // Gray_Alpaha by png_set_expand) to RGBA.
++    png_set_gray_to_rgb(png_ptr);
++  }
++
++  // Expand paletted colors into true RGB triplets.
++  if (color_type == PNG_COLOR_TYPE_PALETTE) {
++    png_set_palette_to_rgb(png_ptr);
++  }
++
+   // Update the reader struct after setting the transformations.
+   png_read_update_info(png_ptr, info_ptr);
+ 
+   // Get the updated color type.
+   color_type = png_get_color_type(png_ptr, info_ptr);
+ 
+-  if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
+-      color_type == PNG_COLOR_TYPE_PALETTE) {
+-    if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+-      // Expand Gray_Alpha to RGBA.
+-      png_set_gray_to_rgb(png_ptr);
+-    } else {
+-      // Expand paletted colors into true RGB triplets.
+-      png_set_palette_to_rgb(png_ptr);
+-    }
+-
+-    // Update the reader struct after modifying the transformations.
+-    png_read_update_info(png_ptr, info_ptr);
+-
+-    // Get the updated color type.
+-    color_type = png_get_color_type(png_ptr, info_ptr);
+-  }
+-
+   // Determine the pixel format and the number of channels.
+   switch (color_type) {
+     case PNG_COLOR_TYPE_GRAY:
+@@ -1158,7 +1154,7 @@
+   }
+ 
+   if (png_image == NULL) {
+-    PS_LOG_DFATAL(message_handler_, "Ouput PNG image cannot be NULL.");
++    PS_LOG_DFATAL(message_handler_, "Output PNG image cannot be NULL.");
+     return false;
+   }
+   return true;
diff --git a/debian/patches/libwebp-native.patch b/debian/patches/libwebp-native.patch
new file mode 100644
index 0000000..b5e964a
--- /dev/null
+++ b/debian/patches/libwebp-native.patch
@@ -0,0 +1,286 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system libwebp
+--- a/src/build/libwebp.gyp
++++ b/src/build/libwebp.gyp
+@@ -6,184 +6,31 @@
+   'targets': [
+     {
+       'target_name': 'libwebp_dec',
+-      'type': 'static_library',
+-      'dependencies' : [
+-        'libwebp_dsp',
+-        'libwebp_dsp_neon',
+-        'libwebp_utils',
+-      ],
+-      'include_dirs': ['.'],
+-      'sources': [
+-        '<(DEPTH)/third_party/libwebp/src/dec/alpha.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/buffer.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/frame.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/idec.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/io.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/quant.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/tree.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/vp8.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/vp8l.c',
+-        '<(DEPTH)/third_party/libwebp/src/dec/webp.c',
+-      ],
+-    },
+-    {
+-      'target_name': 'libwebp_demux',
+-      'type': 'static_library',
+-      'include_dirs': ['.'],
+-      'sources': [
+-        'demux/demux.c',
+-      ],
+-    },
+-    {
+-      'target_name': 'libwebp_dsp',
+-      'type': 'static_library',
+-      'include_dirs': ['.'],
+-      'sources': [
+-        '<(DEPTH)/third_party/libwebp/src/dsp/alpha_processing.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/cpu.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/dec.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/dec_clip_tables.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/dec_mips32.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/dec_sse2.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/enc.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/enc_avx2.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/enc_mips32.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/enc_sse2.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/lossless.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/lossless_mips32.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/lossless_sse2.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/upsampling.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/upsampling_sse2.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/yuv.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/yuv_mips32.c',
+-        '<(DEPTH)/third_party/libwebp/src/dsp/yuv_sse2.c',
+-      ],
+-#      'conditions': [
+-#        ['OS == "android"', {
+-#          'includes': [ 'android/cpufeatures.gypi' ],
+-#        }],
+-#        ['order_profiling != 0', {
+-#          'target_conditions' : [
+-#            ['_toolset=="target"', {
+-#              'cflags!': [ '-finstrument-functions' ],
+-#            }],
+-#          ],
+-#        }],
+-#      ],
+-    },
+-    {
+-      'target_name': 'libwebp_dsp_neon',
+-      'conditions': [
+-        ['target_arch == "arm" and arm_version >= 7 and (arm_neon == 1 or arm_neon_optional == 1)', {
+-          'type': 'static_library',
+-          'include_dirs': ['.'],
+-          'sources': [
+-            '<(DEPTH)/third_party/libwebp/src/dsp/dec_neon.c',
+-            '<(DEPTH)/third_party/libwebp/src/dsp/enc_neon.c',
+-            '<(DEPTH)/third_party/libwebp/src/dsp/lossless_neon.c',
+-            '<(DEPTH)/third_party/libwebp/src/dsp/upsampling_neon.c',
+-          ],
+-          # behavior similar to *.c.neon in an Android.mk
+-          'cflags!': [ '-mfpu=vfpv3-d16' ],
+-          'cflags': [ '-mfpu=neon' ],
+-        },{  # "target_arch != "arm" or arm_version < 7"
+-          'type': 'none',
+-        }],
+-        ['order_profiling != 0', {
+-          'target_conditions' : [
+-            ['_toolset=="target"', {
+-              'cflags!': [ '-finstrument-functions' ],
+-            }],
+-          ],
+-        }],
+-      ],
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-lwebp',
++        ],
++      },
+     },
+     {
+       'target_name': 'libwebp_enc',
+-      'type': 'static_library',
+-      'include_dirs': ['.'],
+-      'sources': [
+-        '<(DEPTH)/third_party/libwebp/src/enc/alpha.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/analysis.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/backward_references.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/config.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/cost.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/filter.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/frame.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/histogram.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/iterator.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/picture.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/picture_csp.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/picture_psnr.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/picture_rescale.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/picture_tools.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/quant.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/syntax.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/token.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/tree.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/vp8l.c',
+-        '<(DEPTH)/third_party/libwebp/src/enc/webpenc.c',
+-      ],
+-    },
+-    {
+-      'target_name': 'libwebp_utils',
+-      'type': 'static_library',
+-      'include_dirs': ['.'],
+-      'sources': [
+-        '<(DEPTH)/third_party/libwebp/src/utils/bit_reader.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/bit_writer.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/color_cache.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/filters.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/huffman.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/huffman_encode.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/quant_levels.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/quant_levels_dec.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/random.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/rescaler.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/thread.c',
+-        '<(DEPTH)/third_party/libwebp/src/utils/utils.c',
+-      ],
+-    },
+-    {
+-      'target_name': 'libwebp_mux',
+-      'type': 'static_library',
+-      'include_dirs': ['.'],
+-      'sources': [
+-        '<(DEPTH)/third_party/libwebp/src/mux/muxedit.c',
+-        '<(DEPTH)/third_party/libwebp/src/mux/muxinternal.c',
+-        '<(DEPTH)/third_party/libwebp/src/mux/muxread.c',
+-      ],
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-lwebpmux',
++          '-lwebp',
++        ],
++      },
+     },
+     {
+       'target_name': 'libwebp_enc_mux',
+       'type': 'static_library',
+       'dependencies': [
+-        'libwebp_mux',
++        'libwebp_enc'
+       ],
+-      'include_dirs': [
+-        '<(DEPTH)/third_party/libwebp/src',
+-      ],
+-    'sources': [
++      'sources': [
+         '<(DEPTH)/third_party/libwebp/examples/gif2webp_util.c',
+-        ],
+-    },
+-    {
+-      'target_name': 'libwebp',
+-      'type': 'none',
+-      'dependencies' : [
+-        'libwebp_dec',
+-        'libwebp_demux',
+-        'libwebp_dsp',
+-        'libwebp_dsp_neon',
+-        'libwebp_enc',
+-        'libwebp_enc_mux',
+-        'libwebp_utils',
+-      ],
+-      'direct_dependent_settings': {
+-        'include_dirs': ['.'],
+-      },
+-      'conditions': [
+-        ['OS!="win"', {'product_name': 'webp'}],
+       ],
+     },
+   ],
+--- a/src/net/instaweb/rewriter/image.cc
++++ b/src/net/instaweb/rewriter/image.cc
+@@ -50,11 +50,7 @@
+ #include "pagespeed/kernel/image/webp_optimizer.h"
+ 
+ extern "C" {
+-#ifdef USE_SYSTEM_LIBWEBP
+ #include "webp/decode.h"
+-#else
+-#include "third_party/libwebp/src/webp/decode.h"
+-#endif
+ #ifdef USE_SYSTEM_LIBPNG
+ #include "png.h"  // NOLINT
+ #else
+--- a/src/net/instaweb/rewriter/webp_optimizer.cc
++++ b/src/net/instaweb/rewriter/webp_optimizer.cc
+@@ -28,14 +28,8 @@
+ #include "pagespeed/kernel/image/jpeg_utils.h"
+ 
+ extern "C" {
+-#ifdef USE_SYSTEM_LIBWEBP
+ #include "webp/encode.h"
+ #include "webp/decode.h"
+-#else
+-#include "third_party/libwebp/src/webp/encode.h"
+-#include "third_party/libwebp/src/webp/decode.h"
+-#endif
+-// TODO(jmaessen): open source imports & build of libwebp.
+ }
+ 
+ extern "C" {
+--- a/src/net/instaweb/rewriter/webp_optimizer_test.cc
++++ b/src/net/instaweb/rewriter/webp_optimizer_test.cc
+@@ -25,12 +25,8 @@
+ #include "pagespeed/kernel/base/string_util.h"  // for StrCat
+ #include "pagespeed/kernel/image/test_utils.h"
+ 
+-#ifdef USE_SYSTEM_LIBWEBP
+ #include "webp/encode.h"
+ #include "webp/decode.h"
+-#else
+-#include "third_party/libwebp/src/webp/decode.h"
+-#endif
+ 
+ namespace net_instaweb {
+ 
+--- a/src/pagespeed/kernel/image/image_util.cc
++++ b/src/pagespeed/kernel/image/image_util.cc
+@@ -18,7 +18,7 @@
+ 
+ #include "pagespeed/kernel/image/image_util.h"
+ 
+-#include "third_party/libwebp/src/webp/decode.h"
++#include "webp/decode.h"
+ 
+ #include "pagespeed/kernel/base/countdown_timer.h"
+ #include "pagespeed/kernel/base/message_handler.h"
+--- a/src/pagespeed/kernel/image/webp_optimizer.cc
++++ b/src/pagespeed/kernel/image/webp_optimizer.cc
+@@ -23,11 +23,7 @@
+ #include "pagespeed/kernel/image/scanline_utils.h"
+ 
+ extern "C" {
+-#ifdef USE_SYSTEM_LIBWEBP
+ #include "webp/decode.h"
+-#else
+-#include "third_party/libwebp/src/webp/decode.h"
+-#endif
+ }
+ 
+ namespace pagespeed {
+--- a/src/pagespeed/kernel/image/webp_optimizer.h
++++ b/src/pagespeed/kernel/image/webp_optimizer.h
+@@ -21,7 +21,7 @@
+ 
+ // For libwebp, encode.h must be included before gif2webp_util.h.
+ #include <cstddef>
+-#include "third_party/libwebp/src/webp/encode.h"
++#include "webp/encode.h"
+ #include "third_party/libwebp/examples/gif2webp_util.h"
+ #include "pagespeed/kernel/base/basictypes.h"
+ #include "pagespeed/kernel/base/scoped_ptr.h"
diff --git a/debian/patches/native-jsoncpp.patch b/debian/patches/native-jsoncpp.patch
new file mode 100644
index 0000000..026ad82
--- /dev/null
+++ b/debian/patches/native-jsoncpp.patch
@@ -0,0 +1,47 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system jsoncpp
+--- a/src/pagespeed/kernel/base/json.h
++++ b/src/pagespeed/kernel/base/json.h
+@@ -20,6 +20,6 @@
+ #define PAGESPEED_KERNEL_BASE_JSON_H_
+ 
+ 
+-#include "third_party/jsoncpp/src/include/json/json.h"
++#include "jsoncpp/json/json.h"
+ 
+ #endif  // PAGESPEED_KERNEL_BASE_JSON_H_
+--- a/src/third_party/jsoncpp/jsoncpp.gyp
++++ b/src/third_party/jsoncpp/jsoncpp.gyp
+@@ -13,26 +13,15 @@
+ # limitations under the License.
+ 
+ {
+-  'variables': {
+-    'jsoncpp_root': '<(DEPTH)/third_party/jsoncpp/src',
+-  },
+   'targets': [
+     {
+       'target_name': 'jsoncpp',
+-      'type': '<(library)',
+-      'include_dirs': [
+-        '<(jsoncpp_root)/include',
+-      ],
+-      'sources': [
+-        'src/src/lib_json/json_batchallocator.h',
+-        'src/src/lib_json/json_internalarray.inl',
+-        'src/src/lib_json/json_internalmap.inl',
+-        'src/src/lib_json/json_reader.cpp',
+-        'src/src/lib_json/json_tool.h',
+-        'src/src/lib_json/json_value.cpp',
+-        'src/src/lib_json/json_valueiterator.inl',
+-        'src/src/lib_json/json_writer.cpp',
+-      ],
++      'type': 'none',
++      'all_dependent_settings': {
++        'libraries': [
++          '-ljsoncpp'
++        ],
++      },
+     },
+   ],
+ }
diff --git a/debian/patches/pagespeed-conf-access-style.patch b/debian/patches/pagespeed-conf-access-style.patch
new file mode 100644
index 0000000..54c42f2
--- /dev/null
+++ b/debian/patches/pagespeed-conf-access-style.patch
@@ -0,0 +1,30 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Convert default pagespeed.conf to new-style ACLs
+--- a/src/install/common/pagespeed.conf.template
++++ b/src/install/common/pagespeed.conf.template
+@@ -318,23 +318,12 @@
+     # ModPagespeedUsePerVHostStatistics is enabled.  In that case,
+     # /pagespeed_global_admin sees aggregated data across all vhosts,
+     # and the /pagespeed_admin sees data only for a particular vhost.
+-    #
+-    # You may insert other "Allow from" lines to add hosts you want to
+-    # allow to look at generated statistics.  Another possibility is
+-    # to comment out the "Order" and "Allow" options from the config
+-    # file, to allow any client that can reach your server to access
+-    # and change server state, such as statistics, caches, and
+-    # messages.  This might be appropriate in an experimental setup.
+     <Location /pagespeed_admin>
+-        Order allow,deny
+-        Allow from localhost
+-        Allow from 127.0.0.1
++        Require local
+         SetHandler pagespeed_admin
+     </Location>
+     <Location /pagespeed_global_admin>
+-        Order allow,deny
+-        Allow from localhost
+-        Allow from 127.0.0.1
++        Require local
+         SetHandler pagespeed_global_admin
+     </Location>
+ 
diff --git a/debian/patches/proto-crash-fix.patch b/debian/patches/proto-crash-fix.patch
new file mode 100644
index 0000000..0575466
--- /dev/null
+++ b/debian/patches/proto-crash-fix.patch
@@ -0,0 +1,69 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Prevent crashes at startup with dynamically linked protobuf
+
+--- a/src/net/instaweb/rewriter/process_context.cc
++++ b/src/net/instaweb/rewriter/process_context.cc
+@@ -62,10 +62,10 @@
+   // starting up.
+   ShutDownCommandLineFlags();
+ 
+-  // The protobuf shutdown infrastructure is lazily initialized in a threadsafe
+-  // manner.  See third_party/protobuf/src/google/protobuf/stubs/common.cc,
+-  // function InitShutdownFunctionsOnce.
++#if 0
++  // See comments in ApacheProcessContext ctor for why we can't use this here.
+   google::protobuf::ShutdownProtobufLibrary();
++#endif
+ 
+   url::Shutdown();
+   HtmlKeywords::ShutDown();
+--- a/src/net/instaweb/mod_pagespeed.gyp
++++ b/src/net/instaweb/mod_pagespeed.gyp
+@@ -29,6 +29,9 @@
+       'dependencies+': [
+         '<(DEPTH)/third_party/httpd/httpd.gyp:include',
+       ],
++      'libraries': [
++        '-ldl',
++      ],
+     },
+     {
+       'target_name': 'mod_pagespeed_ap24',
+--- a/src/pagespeed/apache/mod_instaweb.cc
++++ b/src/pagespeed/apache/mod_instaweb.cc
+@@ -19,6 +19,7 @@
+ // that mod_pagespeed needs to do to be an Apache module.
+ 
+ #include <unistd.h>
++#include <dlfcn.h>
+ 
+ #include <cerrno>
+ #include <cstddef>
+@@ -304,6 +305,27 @@
+ class ApacheProcessContext {
+  public:
+   ApacheProcessContext() : apache_cmds_(NULL) {
++    // One of our dependencies is Protocol Buffers. Dynamically linking
++    // to them causes a problem if the following sequence of steps happens:
++    //
++    // 1) unload mod_pagespeed.so
++    // 2) libprotobuf.so sticks around.
++    // 3) load mod_pagespeed.so again
++    //
++    // When that occurs, a lot of global state ends up being out of sync
++    // between the two .so's regardless of what we do.
++    //
++    // Oh, and w/o this patch, this happens at server startup. Steps 1 and 3
++    // happen because this is just how Apache + apr work. Step 2 is because it
++    // turns out that libprotobuf triggers something called STB_GNU_UNIQUE,
++    // which, among other things, prevents the library from being unloaded.
++    // (Even if that wasn't there, another client could potentially keep
++    //  libprotobuf.so around just via refcount).
++    //
++    // The result being, we can't let ourselves be unloaded... so this asks
++    // the dynamic linker to bump the refcount... and sadly hardcodes our path.
++    dlopen("/usr/lib/apache2/modules/mod_pagespeed.so", RTLD_GLOBAL | RTLD_NOW);
++
+     ApacheRewriteDriverFactory::Initialize();
+     InstallCommands();
+   }
diff --git a/debian/patches/protoc-configurable-path.patch b/debian/patches/protoc-configurable-path.patch
new file mode 100644
index 0000000..01d4d1d
--- /dev/null
+++ b/debian/patches/protoc-configurable-path.patch
@@ -0,0 +1,47 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Permit configuring external protoc
+ (Trunk too different to upstream this particular change)
+--- a/src/net/instaweb/instaweb.gyp
++++ b/src/net/instaweb/instaweb.gyp
+@@ -35,7 +35,7 @@
+   'variables': {
+     'instaweb_root': '../..',
+     'protoc_out_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/instaweb',
+-    'protoc_executable':
++    'protoc_executable%':
+         '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
+     'compiled_js_dir': '<(SHARED_INTERMEDIATE_DIR)/closure_out/instaweb',
+     'data2c_out_dir': '<(SHARED_INTERMEDIATE_DIR)/data2c_out/instaweb',
+--- a/src/net/instaweb/protoc.gypi
++++ b/src/net/instaweb/protoc.gypi
+@@ -30,7 +30,7 @@
+       'action': [
+         'bash',
+         '-c',
+-        'cat <(instaweb_root)/<(instaweb_protoc_subdir)/<(RULE_INPUT_NAME) | sed \'s!"third_party/pagespeed!"pagespeed!\' | sed \'s!// \[opensource\] !!\' > <(protoc_out_dir)/<(instaweb_protoc_subdir)/<(RULE_INPUT_ROOT).proto && <(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX) --proto_path=<(protoc_out_dir)/ <(protoc_out_dir)/<(instaweb_protoc_subdir)/<(RULE_INPUT_ROOT).proto --cpp_out=<(protoc_out_dir)',
++        'cat <(instaweb_root)/<(instaweb_protoc_subdir)/<(RULE_INPUT_NAME) | sed \'s!"third_party/pagespeed!"pagespeed!\' | sed \'s!// \[opensource\] !!\' > <(protoc_out_dir)/<(instaweb_protoc_subdir)/<(RULE_INPUT_ROOT).proto && <(protoc_executable) --proto_path=<(protoc_out_dir)/ <(protoc_out_dir)/<(instaweb_protoc_subdir)/<(RULE_INPUT_ROOT).proto --cpp_out=<(protoc_out_dir)',
+       ],
+     },
+   ],
+--- a/src/pagespeed/kernel.gyp
++++ b/src/pagespeed/kernel.gyp
+@@ -16,7 +16,7 @@
+   'variables': {
+     'instaweb_root': '..',
+     'protoc_out_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/instaweb',
+-    'protoc_executable':
++    'protoc_executable%':
+         '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
+     'data2c_out_dir': '<(SHARED_INTERMEDIATE_DIR)/data2c_out/instaweb',
+     'data2c_exe':
+--- a/src/pagespeed/opt.gyp
++++ b/src/pagespeed/opt.gyp
+@@ -20,7 +20,7 @@
+     # errors.
+     'chromium_code': 1,
+     'protoc_out_dir': '<(SHARED_INTERMEDIATE_DIR)/protoc_out/instaweb',
+-    'protoc_executable':
++    'protoc_executable%':
+         '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)protoc<(EXECUTABLE_SUFFIX)',
+     'compiled_js_dir': '<(SHARED_INTERMEDIATE_DIR)/closure_out/instaweb',
+     'data2c_out_dir': '<(SHARED_INTERMEDIATE_DIR)/data2c_out/instaweb',
diff --git a/debian/patches/re2-native.patch b/debian/patches/re2-native.patch
new file mode 100644
index 0000000..d58e2e8
--- /dev/null
+++ b/debian/patches/re2-native.patch
@@ -0,0 +1,134 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Build against system re2
+ This also disables building of the speed_test executable, which was pulling in a re2
+ file for some microbenchmark utilities.
+--- a/src/build/all.gyp
++++ b/src/build/all.gyp
+@@ -56,7 +56,6 @@
+         '../net/instaweb/instaweb_core.gyp:*',
+         '../net/instaweb/instaweb_apr.gyp:*',
+         '../net/instaweb/test.gyp:mod_pagespeed_test',
+-        '../net/instaweb/test.gyp:mod_pagespeed_speed_test',
+         'install.gyp:*',
+       ]
+     },
+--- a/src/net/instaweb/test.gyp
++++ b/src/net/instaweb/test.gyp
+@@ -481,41 +481,6 @@
+       ],
+     },
+     {
+-      'target_name': 'mod_pagespeed_speed_test',
+-      'type': 'executable',
+-      'dependencies': [
+-        'test_util',
+-        '<(DEPTH)/net/instaweb/instaweb.gyp:instaweb_console_css_data2c',
+-        '<(DEPTH)/net/instaweb/instaweb.gyp:instaweb_console_js_data2c',
+-        '<(DEPTH)/pagespeed/kernel.gyp:pthread_system',
+-        '<(DEPTH)/pagespeed/kernel.gyp:pagespeed_base_core',
+-        '<(DEPTH)/pagespeed/kernel.gyp:pagespeed_http',
+-        '<(DEPTH)/pagespeed/kernel.gyp:proto_util',
+-        '<(DEPTH)/third_party/css_parser/css_parser.gyp:css_parser',
+-        '<(DEPTH)/third_party/re2/re2.gyp:re2_bench_util',
+-      ],
+-      'include_dirs': [
+-        '<(DEPTH)',
+-        '<(DEPTH)/third_party/css_parser/src',
+-      ],
+-      'sources': [
+-        'rewriter/css_minify_speed_test.cc',
+-        'rewriter/domain_lawyer_speed_test.cc',
+-        'rewriter/image_speed_test.cc',
+-        'rewriter/javascript_minify_speed_test.cc',
+-        'rewriter/rewrite_driver_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/base/fast_wildcard_group_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/base/file_system_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/base/string_multi_map_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/base/wildcard_group.cc',
+-        '<(DEPTH)/pagespeed/kernel/cache/compressed_cache_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/cache/lru_cache_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/html/html_parse_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/util/deque_speed_test.cc',
+-        '<(DEPTH)/pagespeed/kernel/util/url_escaper_speed_test.cc',
+-      ],
+-    },
+-    {
+       'target_name': 'css_minify_main',
+       'type': 'executable',
+       'sources': [
+--- a/src/pagespeed/kernel/util/re2.h
++++ b/src/pagespeed/kernel/util/re2.h
+@@ -21,7 +21,7 @@
+ 
+ #include "pagespeed/kernel/base/string_util.h"
+ 
+-#include "third_party/re2/src/re2/re2.h"
++#include "re2/re2.h"
+ 
+ using re2::RE2;
+ 
+--- a/src/third_party/re2/re2.gyp
++++ b/src/third_party/re2/re2.gyp
+@@ -15,60 +15,15 @@
+ # Author: gagansingh@google.com (Gagandeep Singh)
+ 
+ {
+-  'variables': {
+-    're2_root': '<(DEPTH)/third_party/re2',
+-  },
+   'targets': [
+     {
+       'target_name': 're2',
+       'type': '<(library)',
+-      'include_dirs': [
+-        '<(re2_root)/src/',
+-      ],
+       'all_dependent_settings': {
+-        'include_dirs': [
+-          '<(DEPTH)/third_party/re2/src/',
++        'libraries': [
++          '-lre2',
+         ],
+       },
+-      'sources': [
+-        'src/re2/bitstate.cc',
+-        'src/re2/compile.cc',
+-        'src/re2/dfa.cc',
+-        'src/re2/filtered_re2.cc',
+-        'src/re2/mimics_pcre.cc',
+-        'src/re2/nfa.cc',
+-        'src/re2/onepass.cc',
+-        'src/re2/parse.cc',
+-        'src/re2/perl_groups.cc',
+-        'src/re2/prefilter.cc',
+-        'src/re2/prefilter_tree.cc',
+-        'src/re2/prog.cc',
+-        'src/re2/re2.cc',
+-        'src/re2/regexp.cc',
+-        'src/re2/set.cc',
+-        'src/re2/simplify.cc',
+-        'src/re2/stringpiece.cc',
+-        'src/re2/tostring.cc',
+-        'src/re2/unicode_casefold.cc',
+-        'src/re2/unicode_groups.cc',
+-        'src/util/hash.cc',
+-        'src/util/logging.cc',
+-        'src/util/pcre.cc',
+-        'src/util/rune.cc',
+-        'src/util/strutil.cc',
+-        'src/util/stringprintf.cc',
+-        'src/util/valgrind.cc',
+-      ],
+-    },
+-    {
+-      'target_name': 're2_bench_util',
+-      'type': '<(library)',
+-      'include_dirs': [
+-        '<(re2_root)/src/',
+-      ],
+-      'sources': [
+-        'src/util/benchmark.cc',
+-      ],
+     },
+   ],
+ }
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..6657d78
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,20 @@
+protoc-configurable-path.patch
+external-protobuf.patch
+re2-native.patch
+gmock-native.patch
+giflib-native.patch
+libwebp-native.patch
+abi-sanity.patch
+native-jsoncpp.patch
+libpng-no-private.patch
+add-missing-zlib-includes.patch
+gflags-native.patch
+libpng16-compat.patch
+pagespeed-conf-access-style.patch
+jpeg-reader-test-fuzzy-match.patch
+icu-native-includes.patch
+libpng-padding-init.patch
+increase-test-fuzzyness.patch
+disable-mem-debug-cc.patch
+proto-crash-fix.patch
+test-hacking.patch
diff --git a/debian/patches/test-hacking.patch b/debian/patches/test-hacking.patch
new file mode 100644
index 0000000..73d6619
--- /dev/null
+++ b/debian/patches/test-hacking.patch
@@ -0,0 +1,132 @@
+Author: Maks Orlovich <morlovich@google.com>
+Description: Tweaks to make integration tests runnable
+ Those are not run by the rules file since they are not self-contained,
+ and touch the system config heavily, but it's good to have the 
+ option when developing the package.
+ .
+ The invocation is roughly, from src/install:
+ sudo ubuntu.sh apache_vm_system_tests
+--- a/src/pagespeed/automatic/system_tests/image_quality_and_response.sh
++++ b/src/pagespeed/automatic/system_tests/image_quality_and_response.sh
+@@ -48,8 +48,8 @@
+   # for accommodating image encoder version difference.
+   local LENGTH="$(extract_headers $FETCH_UNTIL_OUTFILE | scrape_content_length)"
+   if [ "$EXPECTED_CONTENT_LENGTH" != "$UNOPTIMIZED" ]; then
+-    local MIN_LENGTH=`expr $EXPECTED_CONTENT_LENGTH - 30`
+-    local MAX_LENGTH=`expr $EXPECTED_CONTENT_LENGTH + 30`
++    local MIN_LENGTH=`expr $EXPECTED_CONTENT_LENGTH - 400`
++    local MAX_LENGTH=`expr $EXPECTED_CONTENT_LENGTH + 400`
+     check [ $LENGTH -ge $MIN_LENGTH ]
+     check [ $LENGTH -le $MAX_LENGTH ]
+   fi
+--- a/src/pagespeed/automatic/system_tests/image_resize.sh
++++ b/src/pagespeed/automatic/system_tests/image_resize.sh
+@@ -19,7 +19,7 @@
+ #
+ IMAGE="/120x150xPuzzle2.jpg.pagespeed.ic.*.webp"
+ check_from "$(< $HTML_FETCHED)" grep -q $IMAGE
+-check_file_size "$WGET_DIR$IMAGE" -le 2340
++check_file_size "$WGET_DIR$IMAGE" -le 2400
+ #
+ IMAGE="/90xNxIronChef2.gif.pagespeed.ic.*.webp"
+ check_from "$(< $HTML_FETCHED)" grep -q $IMAGE
+--- a/src/pagespeed/system/system_test.sh
++++ b/src/pagespeed/system/system_test.sh
+@@ -293,12 +293,12 @@
+   FILTERED="${PROXY_PATH}/A.yellow.css.pagespeed.cf.KM5K8SbHQL.css"
+ 
+   # We should be able to fetch the original ...
+-  echo  http_proxy=$SECONDARY_HOSTNAME $WGET --save-headers -O - $ORIGINAL
+-  OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET --save-headers -O - $ORIGINAL 2>&1)
++  echo  http_proxy=$SECONDARY_HOSTNAME $WGET -q --save-headers -O - $ORIGINAL
++  OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET -q --save-headers -O - $ORIGINAL 2>&1)
+   check_200_http_response "$OUT"
+   # ... AND the rewritten version.
+-  echo  http_proxy=$SECONDARY_HOSTNAME $WGET --save-headers -O - $FILTERED
+-  OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET --save-headers -O - $FILTERED 2>&1)
++  echo  http_proxy=$SECONDARY_HOSTNAME $WGET -q --save-headers -O - $FILTERED
++  OUT=$(http_proxy=$SECONDARY_HOSTNAME $WGET -q --save-headers -O - $FILTERED 2>&1)
+   check_200_http_response "$OUT"
+ fi
+ 
+--- a/src/install/Makefile
++++ b/src/install/Makefile
+@@ -161,9 +161,6 @@
+ # separately into a mods-enabled directory, and the .conf file is loaded
+ # independently.
+ MODS_ENABLED_INSTALL_COMMANDS = \
+-	rm -f $(MODS_ENABLED_DIR)/pagespeed.load ; \
+-	cp -f $(STAGING_DIR)/pagespeed.load $(MODS_AVAILABLE_DIR) ; \
+-	cd $(MODS_ENABLED_DIR) && ln -s ../mods-available/pagespeed.load ; \
+ 	rm -f $(MODS_ENABLED_DIR)/headers.load ; \
+ 	cd $(MODS_ENABLED_DIR) && ln -s ../mods-available/headers.load ; \
+ 	rm -f $(MODS_ENABLED_DIR)/deflate.load ; \
+@@ -439,8 +436,8 @@
+ 	cat common/pagespeed.load.template | \
+ 	    sed s~@@APACHE_MODULEDIR@@~$(APACHE_MODULES)~ | \
+ 	    sed s/@@COMMENT_OUT_DEFLATE@@// > $(STAGING_DIR)/pagespeed.load
+-	cp -f $(LIBRARY_CONF_SOURCE) $(STAGING_DIR)/pagespeed_libraries.conf
+-	$(MODS_ENABLED_STAGING_COMMANDS)
++	#cp -f $(LIBRARY_CONF_SOURCE) $(STAGING_DIR)/pagespeed_libraries.conf
++	#$(MODS_ENABLED_STAGING_COMMANDS)
+ 	cp -rp mod_pagespeed_example mod_pagespeed_test $(STAGING_DIR)
+ 
+ staging : staging_except_module
+@@ -451,8 +448,8 @@
+ install_except_module : mod_pagespeed_file_root
+ 	$(MODS_ENABLED_INSTALL_COMMANDS)
+ 	cat $(CONF_SOURCES) > $(APACHE_CONF_DIR)/pagespeed.conf
+-	cp -f $(STAGING_DIR)/pagespeed_libraries.conf \
+-	      $(APACHE_CONF_D)/pagespeed_libraries.conf
++	#cp -f $(STAGING_DIR)/pagespeed_libraries.conf \
++	#      $(APACHE_CONF_D)/pagespeed_libraries.conf
+ 	rm -rf $(APACHE_DOC_ROOT)/mod_pagespeed_example \
+ 	       $(APACHE_DOC_ROOT)/mod_pagespeed_test
+ 	cp -r $(STAGING_DIR)/mod_pagespeed_example \
+@@ -574,6 +571,8 @@
+ 
+ apache_debug_restart :
+ 	$(APACHE_CONTROL_PROGRAM) restart
++	# Sleep to avoid systemd getting worried about overly frequent restarts
++	sleep 1
+ 
+ apache_debug_stop : stop
+ 
+--- a/src/install/ubuntu.sh
++++ b/src/install/ubuntu.sh
+@@ -19,6 +19,7 @@
+     APACHE_PROGRAM=/usr/sbin/apache2 \
+     APACHE_ROOT=/etc/apache2 \
+     APACHE_STOP_COMMAND=stop \
++    APACHE_HTTPS_DOMAIN=127.0.0.1:8443 \
+     BINDIR=/usr/local/bin \
+     SSL_CERT_DIR=/etc/ssl/certs \
+     SSL_CERT_FILE_COMMAND= \
+--- a/src/install/Makefile.tests
++++ b/src/install/Makefile.tests
+@@ -44,7 +44,7 @@
+ 	$(MAKE) FAST_RESTART=1 apache_debug_downstream_caching_test
+ 	$(MAKE) FAST_RESTART=1 apache_debug_per_vhost_stats_test
+ 	$(MAKE) FAST_RESTART=1 apache_debug_memcached_test
+-	$(MAKE) FAST_RESTART=1 apache_debug_leak_test
++	#$(MAKE) FAST_RESTART=1 apache_debug_leak_test
+ 	$(MAKE) FAST_RESTART=1 apache_debug_rewrite_test
+ 	$(MAKE) FAST_RESTART=1 apache_debug_proxy_test
+ 	$(MAKE) FAST_RESTART=1 apache_debug_slurp_test
+--- a/src/install/debug.conf.template
++++ b/src/install/debug.conf.template
+@@ -9,6 +9,14 @@
+ # ports via semanage.  Any new ports should thus be added to the Makefile in
+ # this directory, target enable_ports_and_file_access.
+ 
++# Config tweaks for Debian
++AddType image/webp webp
++AddHandler fcgid-script .php
++FCGIWrapper /usr/bin/php-cgi .php
++<Directory @@APACHE_DOC_ROOT@@>
++  Options +ExecCGI
++</Directory>
++
+ # We don't enable XHTML in the default pagespeed.conf.  For the
+ # add_instrumentation xhtml tests to work, though, we have to enable
+ # it here.  If we change pagespeed.conf.template to enable XHTML by
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..77cd252
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,43 @@
+#!/usr/bin/make -f
+# See debhelper(7) (uncomment to enable)
+# output every command that modifies files on the build system.
+export DH_VERBOSE = 1
+
+
+# see FEATURE AREAS in dpkg-buildflags(1)
+#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
+
+# see ENVIRONMENT in dpkg-buildflags(1)
+# package maintainers to append CFLAGS
+#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
+# package maintainers to append LDFLAGS
+#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
+
+
+%:
+	dh $@ --with apache2
+
+override_dh_auto_configure:
+	./generate.sh -Dsystem_include_path_apr=/usr/include/apr-1.0 -Dsystem_include_path_httpd=/usr/include/apache2 -Duse_system_protobuf=1 -Dprotoc_executable=/usr/bin/protoc
+
+override_dh_auto_build:
+	cd src && $(MAKE) BUILDTYPE=Release V=1 -j4
+	cat ./src/out/Release/install/common/pagespeed.conf.template \
+	  | sed s#@@MOD_PAGESPEED_CACHE@@#/var/cache/mod_pagespeed# \
+	  | sed s#@@MOD_PAGESPEED_LOG@@#/var/log/pagespeed# \
+	  | sed s#@@SSL_CERT_FILE_COMMAND@@## \
+	  | sed s#@@SSL_CERT_DIR@@#/etc/ssl/certs# \
+	  > ./src/out/Release/install/common/pagespeed.conf
+	cp ./src/out/Release/libmod_pagespeed.so ./src/out/Release/mod_pagespeed.so
+
+override_dh_auto_clean:
+	-rm -rf src/out/
+	-rm src/Makefile
+	-rm src/third_party/chromium/src/base/cpu_patched.cc
+	-find src -name '*.mk' -delete
+	-find src -name '*.Makefile' -delete
+	-find src -name '*.pyc' -delete
+
+override_dh_auto_test:
+	src/out/Release/mod_pagespeed_test
+	src/out/Release/pagespeed_automatic_test
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)