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

Name:           nanopb
Version:        0.3.9.1
Release:        5%{?dist}.art
License:        Zlib
Summary:        Protocol Buffers with small code size
Url:            https://code.google.com/p/nanopb/
Group:          Development/Languages/Python
Source:         https://nanopb.googlecode.com/files/%{version}.tar.gz
BuildRequires: cmake
BuildRequires:  atomic-protobuf-protobuf atomic-protobuf-protobuf-runtime
BuildRequires:  python
%if 0%{?rhel} == 6
BuildRequires:  python27
%endif
AutoReq: 0

%description
Nanopb is a plain-C implementation of Google's Protocol Buffers data format.
It is targeted at 32 bit microcontrollers, but is also fit for other embedded
systems with tight (2-10 kB ROM, <1 kB RAM) memory constraints. Nanopb supports
static memory allocation, i.e. you don't need a malloc implementation and can
be sure of the memory requirements of your code.

%prep
%setup 

%build
%if 0%{?rhel} == 6
. /opt/rh/python27/enable
%endif
PATH=/opt/atomic/atomic-protobuf/root/usr/bin/:$PATH
export PATH

mkdir build
pushd build 
%cmake  -DCMAKE_VERBOSE_MAKEFILE=ON \
        -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DSYSCONFDIR=%{_sysconfdir} \
        -DLIBDIR=%{_libdir} \
        -DLOCALSTATEDIR=%{_localstatedir} \
	..
make
popd

pushd generator/proto
make
popd

%install

rm -rf $RPM_BUILD_ROOT
pushd build
make install DESTDIR=$RPM_BUILD_ROOT
popd

install -D -m 0644 generator/proto/nanopb.proto %{buildroot}%{python_sitelib}/%{name}/nanopb.proto
install -D -m 0755 generator/nanopb_generator.py %{buildroot}%{python_sitelib}/%{name}/nanopb_generator.py
#install -D -m 0644 generator/nanopb_pb2.py %{buildroot}%{python_sitelib}/%{name}/nanopb_pb2.py
mkdir -p %{buildroot}%{_bindir}
ln -s %{python_sitelib}/%{name}/nanopb_generator.py %{buildroot}%{_bindir}/%{name}


%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)
%doc AUTHORS.txt CHANGELOG.txt CONTRIBUTING.md LICENSE.txt README.md
%{_includedir}/pb*.h
%{_bindir}/nanopb
/usr/lib/cmake/nanopb/*
/usr/lib64/libprotobuf-nanopb.a
/usr/lib/python2.7/site-packages/plugin_pb2.py
# el6 WIP
/usr/lib/python2.6/site-packages/nanopb/nanopb.proto
/usr/lib/python2.6/site-packages/nanopb/nanopb_generator.py
/usr/lib/python2.6/site-packages/nanopb/nanopb_generator.pyc
/usr/lib/python2.6/site-packages/nanopb/nanopb_generator.pyo
/usr/lib/python2.7/site-packages/nanopb_pb2.py
#el7 WIP
#/usr/lib/python2.7/site-packages/nanopb_pb2.py
#/usr/lib/python2.7/site-packages/nanopb_pb2.pyc
#/usr/lib/python2.7/site-packages/nanopb_pb2.pyo
#/usr/lib/python2.7/site-packages/plugin_pb2.py
#/usr/lib/python2.7/site-packages/plugin_pb2.pyc
#/usr/lib/python2.7/site-packages/plugin_pb2.pyo
#/usr/lib/python2.7/site-packages/nanopb/nanopb.proto
#/usr/lib/python2.7/site-packages/nanopb/nanopb_generator.py
#/usr/lib/python2.7/site-packages/nanopb/nanopb_generator.pyc
#/usr/lib/python2.7/site-packages/nanopb/nanopb_generator.pyo


%changelog
* Fri Jul 13 2018 Scott R. Shinn <scott@atomicorp.com>
- init package