blob: 7a0fe5027d1417c4990fd40e1529cb87fc7e3216 [file] [log] [blame]
Louis Ryanc42c8c42015-03-18 16:31:38 -07001#!/bin/bash
2#
nmittler1dce8df2016-02-16 08:47:09 -08003# Build protoc
zpencer53c135a2017-10-27 15:31:30 -07004set -evux -o pipefail
Louis Ryanc42c8c42015-03-18 16:31:38 -07005
Kun Zhangbd23a8d2015-08-28 18:47:06 -07006DOWNLOAD_DIR=/tmp/source
Eric Anderson80f73a42016-04-27 15:23:35 -07007INSTALL_DIR="/tmp/protobuf-$PROTOBUF_VERSION/$(uname -s)-$(uname -p)"
Kun Zhangbd23a8d2015-08-28 18:47:06 -07008mkdir -p $DOWNLOAD_DIR
9
zpencer8970c3a2017-10-26 14:26:35 -070010# Start with a sane default
11NUM_CPU=4
12if [[ $(uname) == 'Linux' ]]; then
13 NUM_CPU=$(nproc)
14fi
15if [[ $(uname) == 'Darwin' ]]; then
16 NUM_CPU=$(sysctl -n hw.ncpu)
17fi
18
Louis Ryanc42c8c42015-03-18 16:31:38 -070019# Make protoc
Eric Andersona0acb9b2015-03-20 10:26:00 -070020# Can't check for presence of directory as cache auto-creates it.
Kun Zhangbd23a8d2015-08-28 18:47:06 -070021if [ -f ${INSTALL_DIR}/bin/protoc ]; then
Eric Andersona0acb9b2015-03-20 10:26:00 -070022 echo "Not building protobuf. Already built"
Eric Anderson6dc5e802015-10-15 14:52:24 -070023# TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date
Eric Andersona0acb9b2015-03-20 10:26:00 -070024else
Kun Zhangbd23a8d2015-08-28 18:47:06 -070025 wget -O - https://github.com/google/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz | tar xz -C $DOWNLOAD_DIR
26 pushd $DOWNLOAD_DIR/protobuf-${PROTOBUF_VERSION}
Eric Andersona0acb9b2015-03-20 10:26:00 -070027 ./autogen.sh
28 # install here so we don't need sudo
zpencerfbc079d2018-02-14 12:53:11 -080029 ./configure --disable-shared --prefix="$INSTALL_DIR"
zpencer8970c3a2017-10-26 14:26:35 -070030 make -j$NUM_CPU
Eric Andersona99e9772015-10-01 11:38:49 -070031 make install
32 popd
33fi
34