51c30b1d5ef3bd0e6acf75513a773159b15e45c5
[gentoo.git] / dev-libs / protobuf / protobuf-3.11.4.ebuild
1 # Copyright 2008-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="7"
5
6 inherit autotools elisp-common flag-o-matic multilib-minimal toolchain-funcs
7
8 if [[ "${PV}" == "9999" ]]; then
9         inherit git-r3
10
11         EGIT_REPO_URI="https://github.com/protocolbuffers/protobuf"
12         EGIT_SUBMODULES=()
13 fi
14
15 DESCRIPTION="Google's Protocol Buffers - Extensible mechanism for serializing structured data"
16 HOMEPAGE="https://developers.google.com/protocol-buffers/ https://github.com/protocolbuffers/protobuf"
17 if [[ "${PV}" == "9999" ]]; then
18         SRC_URI=""
19 else
20         SRC_URI="https://github.com/protocolbuffers/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
21 fi
22
23 LICENSE="BSD"
24 SLOT="0/22"
25 KEYWORDS="~alpha amd64 arm ~arm64 ~hppa ~ia64 ~mips ppc ppc64 s390 sparc x86 ~amd64-linux ~x86-linux ~x64-macos ~x86-macos"
26 IUSE="emacs examples static-libs test zlib"
27 RESTRICT="!test? ( test )"
28
29 BDEPEND="emacs? ( app-editors/emacs:* )"
30 DEPEND="test? ( >=dev-cpp/gtest-1.9[${MULTILIB_USEDEP}] )
31         zlib? ( sys-libs/zlib[${MULTILIB_USEDEP}] )"
32 RDEPEND="emacs? ( app-editors/emacs:* )
33         zlib? ( sys-libs/zlib[${MULTILIB_USEDEP}] )"
34
35 PATCHES=(
36         "${FILESDIR}/${PN}-3.11.0-disable_no-warning-test.patch"
37         "${FILESDIR}/${PN}-3.11.0-system_libraries.patch"
38         "${FILESDIR}/${PN}-3.11.0-protoc_input_output_files.patch"
39 )
40
41 DOCS=(CHANGES.txt CONTRIBUTORS.txt README.md)
42
43 src_prepare() {
44         default
45         eautoreconf
46 }
47
48 src_configure() {
49         append-cppflags -DGOOGLE_PROTOBUF_NO_RTTI
50
51         if tc-ld-is-gold; then
52                 # https://sourceware.org/bugzilla/show_bug.cgi?id=24527
53                 tc-ld-disable-gold
54         fi
55
56         multilib-minimal_src_configure
57 }
58
59 multilib_src_configure() {
60         local options=(
61                 $(use_enable static-libs static)
62                 $(use_with zlib)
63         )
64
65         if tc-is-cross-compiler; then
66                 # Build system uses protoc when building, so protoc copy runnable on host is needed.
67                 mkdir -p "${WORKDIR}/build" || die
68                 pushd "${WORKDIR}/build" > /dev/null || die
69                 ECONF_SOURCE="${S}" econf_build "${options[@]}"
70                 options+=(--with-protoc="$(pwd)/src/protoc")
71                 popd > /dev/null || die
72         fi
73
74         ECONF_SOURCE="${S}" econf "${options[@]}"
75 }
76
77 src_compile() {
78         multilib-minimal_src_compile
79
80         if use emacs; then
81                 elisp-compile editors/protobuf-mode.el
82         fi
83 }
84
85 multilib_src_compile() {
86         if tc-is-cross-compiler; then
87                 emake -C "${WORKDIR}/build/src" protoc
88         fi
89
90         default
91 }
92
93 multilib_src_test() {
94         emake check
95 }
96
97 multilib_src_install_all() {
98         find "${D}" -name "*.la" -type f -delete || die
99
100         insinto /usr/share/vim/vimfiles/syntax
101         doins editors/proto.vim
102         insinto /usr/share/vim/vimfiles/ftdetect
103         doins "${FILESDIR}/proto.vim"
104
105         if use emacs; then
106                 elisp-install ${PN} editors/protobuf-mode.el*
107                 elisp-site-file-install "${FILESDIR}/70${PN}-gentoo.el"
108         fi
109
110         if use examples; then
111                 DOCS+=(examples)
112                 docompress -x /usr/share/doc/${PF}/examples
113         fi
114
115         einstalldocs
116 }
117
118 pkg_postinst() {
119         use emacs && elisp-site-regen
120 }
121
122 pkg_postrm() {
123         use emacs && elisp-site-regen
124 }