File protobuf.spec of Package protobuf

#
# spec file for package protobuf
#
# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define sover 15
%define tarname protobuf
# requires gmock, which is not yet in the distribution
#%%define with_check
#%%define with_protobuf_java
#%%define with_protobuf_python2
#%%define with_protobuf_python3
Name:           protobuf
Version:        3.5.0
Release:        0
Summary:        Protocol Buffers - Google's data interchange format
License:        BSD-3-Clause
Group:          Development/Libraries/C and C++
Url:            https://github.com/google/protobuf/
Source0:        https://github.com/google/protobuf/archive/v%{version}.tar.gz#/%{tarname}-%{version}.tar.gz
Source1:        manifest.txt.in
Source2:        baselibs.conf
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?sles_version} && 0%{?suse_version} == 1110
BuildRequires:  gcc48
BuildRequires:  gcc48-c++
%endif
%if %{with protobuf_python2}
BuildRequires:  python-rpm-macros
BuildRequires:  %{python2_prefix}-devel
BuildRequires:  %{python2_prefix}-python-dateutil
BuildRequires:  %{python2_prefix}-python-gflags
BuildRequires:  %{python2_prefix}-pytz
BuildRequires:  %{python2_prefix}-setuptools
%endif
%if %{with_protobuf_python3}
BuildRequires:  python-rpm-macros
BuildRequires:  python3-devel
BuildRequires:  python3-python-dateutil
BuildRequires:  python3-python-gflags
BuildRequires:  python3-pytz
BuildRequires:  python3-setuptools
%endif
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  libtool
BuildRequires:  pkgconfig
BuildRequires:  zlib-devel
%if %{with check}
BuildRequires:  libgmock-devel >= 1.7.0
%endif
%if %{with java}
BuildRequires:  java-devel >= 1.6.0
%endif

%description
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotobuf%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotoc%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotoc%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf-lite%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotobuf-lite%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package devel
Summary:        Header files, libraries and development documentation for %{name}
Group:          Development/Libraries/C and C++
Requires:       gcc-c++
Requires:       libprotobuf%{sover} = %{version}
Requires:       libprotobuf-lite%{sover}
Requires:       zlib-devel
Conflicts:      protobuf2-devel
Provides:       libprotobuf-devel = %{version}

%description devel
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%if %{with protobuf_java}
%package -n %{name}-java
Summary:        Java Bindings for Google Protocol Buffers
Group:          Development/Libraries/Java
Requires:       java >= 1.6.0

%description -n %{name}-java
This package contains the Java bindings for Google Protocol Buffers.
%endif

%if %{with protobuf_python2}
%package -n python2-%{name}
Summary:        Python2 Bindings for Google Protocol Buffers
Group:          Development/Libraries/Python
Provides:       python-%{name} = %{version}
Obsoletes:      python-%{name} < %{version}

%description -n python2-%{name}
This package contains the Python bindings for Google Protocol Buffers.
%endif

%if %{with protobuf_python3}
%package -n python3-%{name}
Summary:        Python3 Bindings for Google Protocol Buffers
Group:          Development/Libraries/Python

%description -n python3-%{name}
This package contains the Python bindings for Google Protocol Buffers.
%endif

%prep

%setup -q -n %{tarname}-%{version}
mkdir gmock

%if %{with python2} || %{with python3} 
# only needed for test suite which we don't call anyways.
# googleapis is broken on sle12
sed -i '/apputils/d' python/setup.py
sed -i '/google_test_dir/d' python/setup.py
%endif
# kill shebang that we do not really want
sed -i -e '/env python/d' python/google/protobuf/internal/*.py

%build
%if 0%{?sles_version} && 0%{?suse_version} == 1110
export CC=gcc-4.8
export CXX=g++-4.8
%endif
autoreconf -fvi
%configure \
	--disable-static

make %{?_smp_mflags}

%if %{with java}
pushd java
../src/protoc --java_out=core/src/main/java -I../src ../src/google/protobuf/descriptor.proto
mkdir classes
javac $extra_java_flags -d classes core/src/main/java/com/google/protobuf/*.java
sed -e 's/@VERSION@/%{version}/' < %{SOURCE1} > manifest.txt
jar cfm %{name}-java-%{version}.jar manifest.txt -C classes com
popd
%endif

pushd python
%python_build
popd

%if %{with check}
%check
make %{?_smp_mflags} check
%endif

%install
%make_install
install -Dm 0644 editors/proto.vim %{buildroot}%{_datadir}/vim/site/syntax/proto.vim
# no need for that
find %{buildroot} -type f -name "*.la" -delete -print

%if %{with java}
pushd java
install -D -m 0644 %{name}-java-%{version}.jar %{buildroot}%{_javadir}/%{name}-java-%{version}.jar
ln -s %{name}-java-%{version}.jar %{buildroot}%{_javadir}/%{name}-java.jar
ln -s %{name}-java-%{version}.jar %{buildroot}%{_javadir}/%{name}.jar
popd
%endif

pushd python
%python_install
popd
%python_expand %fdupes %{buildroot}%{$python_sitelib}

%post -n libprotobuf%{sover} -p /sbin/ldconfig
%postun -n libprotobuf%{sover} -p /sbin/ldconfig
%post -n libprotoc%{sover} -p /sbin/ldconfig
%postun -n libprotoc%{sover} -p /sbin/ldconfig
%post -n libprotobuf-lite%{sover} -p /sbin/ldconfig
%postun -n libprotobuf-lite%{sover} -p /sbin/ldconfig

%files -n libprotobuf%{sover}
%defattr(-, root, root)
%license LICENSE
%{_libdir}/libprotobuf.so.%{sover}*

%files -n libprotoc%{sover}
%defattr(-, root, root)
%{_libdir}/libprotoc.so.%{sover}*

%files -n libprotobuf-lite%{sover}
%defattr(-, root, root)
%{_libdir}/libprotobuf-lite.so.%{sover}*

%files devel
%defattr(-, root, root)
%doc CHANGES.txt CONTRIBUTORS.txt README.md
%{_bindir}/protoc
%{_includedir}/google
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_datadir}/vim

%if %{with java}
%files -n %{name}-java
%defattr(-, root, root)
%{_javadir}/protobuf*
%endif

%if %{with python2}
%files -n python2-%{name}
%defattr(-, root, root)
%license LICENSE
%{python2_sitelib}/*
%endif

%if %{with python3}
%files -n python3-%{name}
%defattr(-, root, root)
%license LICENSE
%{python3_sitelib}/*
%endif

%changelog