Skip to content

Instantly share code, notes, and snippets.

@superalsrk
Forked from mjpitz/protobuf-closure.sh
Created November 12, 2016 08:27
Show Gist options
  • Save superalsrk/48c167461a069e9cfd755bb4876c2e88 to your computer and use it in GitHub Desktop.
Save superalsrk/48c167461a069e9cfd755bb4876c2e88 to your computer and use it in GitHub Desktop.
Easily create a protobuf plugin for closure objects
#!/bin/bash
############################################################
# First, you must build the library files for the protobuf
# tool. In order to do this, follow the steps below in the
# source directory for protobuf.
#
# 1. ./autogen.sh
# 2. ./configure
# 3. make
#
# Once this has been done, execute this script to generate
# the javascript builder.
############################################################
TARGET_DIR=~/.dotfiles/bin
#TARGET_DIR=/usr/local/bin
# Store the current working directory for later
CWD=`pwd`
# Get the source to compile the plugin
PROTOBUF_SRC=$CWD/protobuf
if [ ! -d $PROTOBUF_SRC ]; then
git clone https://github.com/google/protobuf.git
fi
# Download the plugin if necessary
PLUGIN_SRC=$CWD/protobuf-plugin-closure/protobuf
if [ ! -d $PLUGIN_SRC ]; then
git clone https://code.google.com/p/protobuf-plugin-closure
fi
cd $PROTOBUF_SRC
./autogen.sh
./configure
make
cd $PLUGIN_SRC
CXXFLAGS="-I . -I $PROTOBUF_SRC/src"
LDFLAGS="-lpthread -lprotoc -lprotobuf"
SRC="js/javascript_package.pb.cc \
js/int64_encoding.pb.cc"
SRC_GEN_JS="$SRC \
js/code_generator.cc \
js/protoc_gen_js.cc"
SRC_CC_JS="$SRC \
ccjs/code_generator.cc \
ccjs/protoc_gen_ccjs.cc"
protoc $CXXFLAGS --cpp_out=. js/javascript_package.proto js/int64_encoding.proto
c++ $CXXFLAGS $SRC_GEN_JS $LDFLAGS -o protoc-gen-js
c++ $CXXFLAGS $SRC_CC_JS $LDFLAGS -o protoc-gen-ccjs
mv protoc-gen-js $TARGET_DIR/protoc-gen-js
mv protoc-gen-ccjs $TARGET_DIR/protoc-gen-ccjs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment