1#!/bin/bash
2
3# Run this script in the top nanopb directory to create a binary package
4# for Linux users.
5
6# Requires: protobuf, python-protobuf, pyinstaller
7
8set -e
9set -x
10
11VERSION=`git describe --always`-linux-x86
12DEST=dist/$VERSION
13
14rm -rf $DEST
15mkdir -p $DEST
16
17# Export the files from newest commit
18git archive HEAD | tar x -C $DEST
19
20# Rebuild the Python .proto files and .pyc
21( cd $DEST/generator; python3 nanopb_generator.py ||: )
22
23# Package the Python libraries
24( cd $DEST/generator; python3 -m PyInstaller nanopb_generator.py )
25( cd $DEST/generator; python3 -m PyInstaller protoc  )
26mv $DEST/generator/dist/nanopb_generator $DEST/generator-bin
27cp $DEST/generator/dist/protoc/protoc $DEST/generator-bin
28
29# Include Google's descriptor.proto and nanopb.proto
30cp -pr $(python3 -c 'import grpc_tools, os.path; print(os.path.dirname(grpc_tools.__file__))')/_proto $DEST/generator-bin/grpc_tools/
31cp -pr $DEST/generator/proto $DEST/generator-bin/proto
32
33# Remove temp files
34rm -rf $DEST/generator/dist $DEST/generator/build $DEST/generator/nanopb_generator.spec
35
36# Make the nanopb generator available as a protoc plugin
37cp $DEST/generator-bin/nanopb_generator $DEST/generator-bin/protoc-gen-nanopb
38
39# Remove debugging symbols to reduce size of package
40( cd $DEST/generator-bin; strip *.so *.so.* )
41
42# Tar it all up
43( cd dist; tar -czf $VERSION.tar.gz $VERSION )
44
45