--- /dev/null
+diff -Naur a/configure.ac b/configure.ac
+--- a/configure.ac 2015-12-30 22:21:46.000000000 +0100
++++ b/configure.ac 2016-04-16 17:46:54.858904639 +0200
+@@ -176,9 +176,9 @@
+ # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
+ # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
+ # too.
+-export CFLAGS
+-export CXXFLAGS
+-AC_CONFIG_SUBDIRS([gmock])
++#export CFLAGS
++#export CXXFLAGS
++#AC_CONFIG_SUBDIRS([gmock])
+
+ AC_CONFIG_FILES([Makefile src/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
+ AC_OUTPUT
+diff -Naur a/Makefile.am b/Makefile.am
+--- a/Makefile.am 2015-12-30 22:21:46.000000000 +0100
++++ b/Makefile.am 2016-04-16 17:46:25.355751203 +0200
+@@ -17,9 +17,10 @@
+ # want "make install" to recurse into gmock since we don't want to overwrite
+ # the installed version of gmock if there is one.
+ check-local:
+- @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock"
+- @cd gmock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la
+- @cd gmock/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
++ @echo "Making of gmock disabled"
++# @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock"
++# @cd gmock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la
++# @cd gmock/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
+
+ # We would like to clean gmock when "make clean" is invoked. But we have to
+ # be careful because clean-local is also invoked during "make distclean", but
+diff -Naur a/src/Makefile.am b/src/Makefile.am
+--- a/src/Makefile.am 2015-12-30 22:21:46.000000000 +0100
++++ b/src/Makefile.am 2016-04-16 17:47:07.026967535 +0200
+@@ -669,11 +669,8 @@
+ protobuf-lite-test test_plugin protobuf-lite-arena-test \
+ $(GZCHECKPROGRAMS)
+ protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
+- ../gmock/gtest/lib/libgtest.la \
+- ../gmock/lib/libgmock.la \
+- ../gmock/lib/libgmock_main.la
+-protobuf_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include \
+- -I$(srcdir)/../gmock/include
++ -L/usr/lib -lgmock -lgmock_main -lgtest
++protobuf_test_CPPFLAGS = -I/usr/include
+ # Disable optimization for tests unless the user explicitly asked for it,
+ # since test_util.cc takes forever to compile with optimization (with GCC).
+ # See configure.ac for more info.
+@@ -753,11 +750,8 @@
+ # Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined.
+ protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
+ libprotoc.la \
+- ../gmock/gtest/lib/libgtest.la \
+- ../gmock/lib/libgmock.la \
+- ../gmock/lib/libgmock_main.la
+-protobuf_lazy_descriptor_test_CPPFLAGS = -I$(srcdir)/../gmock/include \
+- -I$(srcdir)/../gmock/gtest/include \
++ -L/usr/lib -lgmock -lgmock_main -lgtest
++protobuf_lazy_descriptor_test_CPPFLAGS = -I/usr/include \
+ -DPROTOBUF_TEST_NO_DESCRIPTORS
+ protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+ protobuf_lazy_descriptor_test_SOURCES = \
+@@ -788,11 +782,8 @@
+ # gtest when building the test internally our memory sanitizer doesn't detect
+ # memory leaks (don't know why).
+ protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \
+- ../gmock/gtest/lib/libgtest.la \
+- ../gmock/lib/libgmock.la \
+- ../gmock/lib/libgmock_main.la
+-protobuf_lite_arena_test_CPPFLAGS = -I$(srcdir)/../gmock/include \
+- -I$(srcdir)/../gmock/gtest/include
++ -L/usr/lib -lgmock -lgmock_main -lgtest
++protobuf_lite_arena_test_CPPFLAGS = -I/usr/include
+ protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+ protobuf_lite_arena_test_SOURCES = \
+ google/protobuf/lite_arena_unittest.cc \
+@@ -801,8 +792,8 @@
+
+ # Test plugin binary.
+ test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
+- ../gmock/gtest/lib/libgtest.la
+-test_plugin_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include
++ -L/usr/lib -lgtest
++test_plugin_CPPFLAGS = -I/usr/include
+ test_plugin_SOURCES = \
+ google/protobuf/compiler/mock_code_generator.cc \
+ google/protobuf/testing/file.cc \
--- /dev/null
+# Copyright 1999-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+EAPI=6
+
+PYTHON_COMPAT=( python2_7 python3_3 python3_4 python3_5 )
+inherit python-r1 autotools flag-o-matic toolchain-funcs elisp-common multilib-minimal
+
+# If you bump this package, also consider bumping the official language bindings!
+# At the current time these are java and python.
+MY_PV=${PV/_beta2/-beta-2}
+
+DESCRIPTION="Google's Protocol Buffers -- an efficient method of encoding structured data"
+HOMEPAGE="https://github.com/google/protobuf/ https://developers.google.com/protocol-buffers/"
+SRC_URI="https://github.com/google/protobuf/archive/v${MY_PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="Apache-2.0"
+SLOT="0/10"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~sh ~sparc ~x86 ~amd64-linux ~arm-linux ~x86-linux ~x64-macos ~x86-macos"
+IUSE="emacs examples java python static-libs test vim-syntax zlib"
+
+DEPEND="emacs? ( virtual/emacs )
+ zlib? ( >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}] )
+ test? ( dev-cpp/gmock[${MULTILIB_USEDEP}] )"
+# This is provided for backwards compatibility due to (likely incorrect) use in consumers.
+PDEPEND="java? ( dev-java/protobuf-java )
+ python? ( dev-python/protobuf-python[${PYTHON_USEDEP}] )"
+S="${WORKDIR}/${PN}-${MY_PV}"
+PATCHES=( "${FILESDIR}/${PN}-2.5.0-emacs-24.4.patch"
+ "${FILESDIR}/${PN}-2.6.1-protoc-cmdline.patch"
+ "${FILESDIR}/${P}-disable-local-gmock.patch" )
+
+src_prepare() {
+ append-cxxflags -DGOOGLE_PROTOBUF_NO_RTTI
+ default
+ eautoreconf
+}
+
+multilib_src_configure() {
+ local myeconfargs=(
+ $(use_enable static-libs static)
+ $(use_with zlib)
+ )
+ if tc-is-cross-compiler; then
+ # The build system wants `protoc` when building, so we need a copy that
+ # runs on the host. This is more hermetic than relying on the version
+ # installed in the host being the exact same version.
+ mkdir -p "${WORKDIR}"/build || die
+ pushd "${WORKDIR}"/build >/dev/null || die
+ ECONF_SOURCE=${S} econf_build "${myeconfargs[@]}"
+ myeconfargs+=( --with-protoc="${PWD}"/src/protoc )
+ popd >/dev/null || die
+ fi
+ ECONF_SOURCE=${S} econf "${myeconfargs[@]}"
+}
+
+multilib_src_compile() {
+ if tc-is-cross-compiler; then
+ emake -C "${WORKDIR}"/build/src protoc
+ fi
+
+ default
+
+ if use emacs; then
+ elisp-compile "${S}"/editors/protobuf-mode.el
+ fi
+}
+
+multilib_src_test() {
+ emake check
+}
+
+src_install() {
+ multilib-minimal_src_install
+
+ if use vim-syntax; then
+ insinto /usr/share/vim/vimfiles/syntax
+ doins editors/proto.vim
+ insinto /usr/share/vim/vimfiles/ftdetect/
+ doins "${FILESDIR}/proto.vim"
+ fi
+
+ if use emacs; then
+ elisp-install "${PN}" editors/protobuf-mode.el*
+ elisp-site-file-install "${FILESDIR}/70${PN}-gentoo.el"
+ fi
+
+ if use examples; then
+ DOCS+=( examples )
+ fi
+}
+
+pkg_postinst() {
+ use emacs && elisp-site-regen
+}
+
+pkg_postrm() {
+ use emacs && elisp-site-regen
+}