Skip to content

Instantly share code, notes, and snippets.

@crast
Created April 30, 2012 16:47
Show Gist options
  • Save crast/2559949 to your computer and use it in GitHub Desktop.
Save crast/2559949 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Test Edit
# Builds and installs the python bindings for protobuf
# If $INSTALL_PROTOC is set, also installs the protobuf lib and
# The protobuf tools. Set $PROTOC_PREFIX to customise that.
#
# To install to a virtualenv, pass the path to the virtualenv as
# the first argument to this script:
# $ install_protobuf.sh $HOME/live/python_env
PROTOBUF_VERSION=2.4.1
set -o errexit
if [ "$1" != "" ]; then
source "$1/bin/activate"
fi
WORK_DIR=$(mktemp -d -t build.XXXX)
trap "echo -e 'Build failed, see ${WORK_DIR}/build.out'" ERR
cd "$WORK_DIR"
echo "Fetching protobuf sources.."
wget --no-verbose http://protobuf.googlecode.com/files/protobuf-${PROTOBUF_VERSION}.tar.bz2
tar -jxf protobuf-${PROTOBUF_VERSION}.tar.bz2
cd protobuf-${PROTOBUF_VERSION}
if which -s protoc && [[ "$(protoc --version)" == *${PROTOBUF_VERSION}* ]]; then
echo "We already have protoc, going to skip the compile phase."
else
echo -n "Configuring...."
./configure --prefix="${PROTOC_PREFIX:=/usr/local}" > build.out
echo "OK"
echo -n "Building..."
make >> build.out
echo "OK"
if [ "$INSTALL_PROTOC" != "" ]; then
make install >> build.out
fi
fi
cd python
echo -n "Installing python bindings..."
python setup.py install >> ../build.out
echo "OK"
rm -rf -- "${WORK_DIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment