#!/bin/bash
local PACKAGE_VERSION=${1-2.5.0}
local PACKAGE_SOURCE=https://protobuf.googlecode.com/files/protobuf-$PACKAGE_VERSION.tar.gz

# don't run the install process if we are in use mode
if [ ! $BASHINATE_USE ]; then
  # if we don't have the latest node version, then install
  log "Checking protobuf version $PACKAGE_VERSION installed";
  if [ ! -e $BASHINATE_INSTALL/protobuf/$PACKAGE_VERSION ]; then
    log "Installing protobuf version $PACKAGE_VERSION"
    hash g++ 2> /dev/null || require packages build-essential
    fetchSource $PACKAGE_SOURCE

    cd $BASHINATE_SOURCE/protobuf-$PACKAGE_VERSION

    # configure 
    log "- configuring"
    ./configure --prefix=$BASHINATE_INSTALL/protobuf/$PACKAGE_VERSION ||
      abort "!!! Unable to configure protobuf build"

    # make and install
    log "- compiling and installing"
    make && make install ||
      abort "!!! Unable to make protobuf $PACKAGE_VERSION"
  fi
fi

# linkBinaries phantomjs/$PHANTOM_VERSION/bin phantomjs