Louis Ryan | c42c8c4 | 2015-03-18 16:31:38 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
nmittler | 1dce8df | 2016-02-16 08:47:09 -0800 | [diff] [blame] | 3 | # Build protoc |
zpencer | 53c135a | 2017-10-27 15:31:30 -0700 | [diff] [blame] | 4 | set -evux -o pipefail |
Louis Ryan | c42c8c4 | 2015-03-18 16:31:38 -0700 | [diff] [blame] | 5 | |
Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 6 | DOWNLOAD_DIR=/tmp/source |
Eric Anderson | 80f73a4 | 2016-04-27 15:23:35 -0700 | [diff] [blame] | 7 | INSTALL_DIR="/tmp/protobuf-$PROTOBUF_VERSION/$(uname -s)-$(uname -p)" |
Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 8 | mkdir -p $DOWNLOAD_DIR |
| 9 | |
zpencer | 8970c3a | 2017-10-26 14:26:35 -0700 | [diff] [blame] | 10 | # Start with a sane default |
| 11 | NUM_CPU=4 |
| 12 | if [[ $(uname) == 'Linux' ]]; then |
| 13 | NUM_CPU=$(nproc) |
| 14 | fi |
| 15 | if [[ $(uname) == 'Darwin' ]]; then |
| 16 | NUM_CPU=$(sysctl -n hw.ncpu) |
| 17 | fi |
| 18 | |
Louis Ryan | c42c8c4 | 2015-03-18 16:31:38 -0700 | [diff] [blame] | 19 | # Make protoc |
Eric Anderson | a0acb9b | 2015-03-20 10:26:00 -0700 | [diff] [blame] | 20 | # Can't check for presence of directory as cache auto-creates it. |
Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 21 | if [ -f ${INSTALL_DIR}/bin/protoc ]; then |
Eric Anderson | a0acb9b | 2015-03-20 10:26:00 -0700 | [diff] [blame] | 22 | echo "Not building protobuf. Already built" |
Eric Anderson | 6dc5e80 | 2015-10-15 14:52:24 -0700 | [diff] [blame] | 23 | # TODO(ejona): swap to `brew install --devel protobuf` once it is up-to-date |
Eric Anderson | a0acb9b | 2015-03-20 10:26:00 -0700 | [diff] [blame] | 24 | else |
Kun Zhang | bd23a8d | 2015-08-28 18:47:06 -0700 | [diff] [blame] | 25 | 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 Anderson | a0acb9b | 2015-03-20 10:26:00 -0700 | [diff] [blame] | 27 | ./autogen.sh |
| 28 | # install here so we don't need sudo |
Eric Anderson | 80f73a4 | 2016-04-27 15:23:35 -0700 | [diff] [blame] | 29 | ./configure --prefix="$INSTALL_DIR" |
zpencer | 8970c3a | 2017-10-26 14:26:35 -0700 | [diff] [blame] | 30 | make -j$NUM_CPU |
Eric Anderson | a99e977 | 2015-10-01 11:38:49 -0700 | [diff] [blame] | 31 | make install |
| 32 | popd |
| 33 | fi |
| 34 | |