1204431Sraj#!/bin/bash
2204431Sraj
3204431Sraj# Run this script in the top nanopb directory to create a binary package
4204431Sraj# for Mac OS X users.
5204431Sraj
6204431Sraj# Requires: protobuf, python-protobuf, pyinstaller
7204431Sraj
8204431Srajset -e
9204431Srajset -x
10204431Sraj
11204431SrajVERSION=`git describe --always`-macosx-x86
12204431SrajDEST=dist/$VERSION
13204431Sraj
14204431Srajrm -rf $DEST
15204431Srajmkdir -p $DEST
16204431Sraj
17204431Sraj# Export the files from newest commit
18204431Srajgit archive HEAD | tar x -C $DEST
19204431Sraj
20204431Sraj# Rebuild the Python .proto files
21204431Srajmake -BC $DEST/generator/proto
22204431Sraj
23204431Sraj# Package the Python libraries
24204431Sraj( cd $DEST/generator; pyinstaller nanopb_generator.py )
25204431Srajmv $DEST/generator/dist/nanopb_generator $DEST/generator-bin
26204431Sraj
27204431Sraj# Remove temp files
28204431Srajrm -rf $DEST/generator/dist $DEST/generator/build $DEST/generator/nanopb_generator.spec
29204431Sraj
30204431Sraj# Make the nanopb generator available as a protoc plugin
31204431Srajcp $DEST/generator-bin/nanopb_generator $DEST/generator-bin/protoc-gen-nanopb
32204431Sraj
33204431Sraj# Package the protoc compiler
34204431Srajcp `which protoc` $DEST/generator-bin/protoc.bin
35204431SrajLIBPROTOC=$(otool -L `which protoc` | grep -o '/.*libprotoc[^ ]*')
36204431SrajLIBPROTOBUF=$(otool -L `which protoc` | grep -o '/.*libprotobuf[^ ]*')
37204431Srajcp $LIBPROTOC $LIBPROTOBUF $DEST/generator-bin/
38204431Srajcat > $DEST/generator-bin/protoc << EOF
39204431Sraj#!/bin/bash
40204431SrajSCRIPTDIR=\$(dirname "\$0")
41204431Srajexport DYLD_LIBRARY_PATH=\$SCRIPTDIR
42204431Srajexport PATH=\$SCRIPTDIR:\$PATH
43204431Srajexec "\$SCRIPTDIR/protoc.bin" "\$@"
44204431SrajEOF
45204431Srajchmod +x $DEST/generator-bin/protoc
46204431Sraj
47204431Sraj# Tar it all up
48204431Sraj( cd dist; tar -czf $VERSION.tar.gz $VERSION )
49204431Sraj
50204431Sraj