mkdir mosh
cd mosh

ROOT=`pwd`

echo "==================================="
echo "about to set up everything in $ROOT"
echo "==================================="

mkdir build
mkdir install

cd build
curl -O https://codeload.github.com/google/protobuf/tar.gz/v3.4.0
curl -O https://mosh.org/mosh-1.3.2.tar.gz
tar zxvf v3.4.0
tar zxvf mosh-1.3.2.tar.gz

echo "================="
echo "building protobuf"
echo "================="


cd $ROOT/build/protobuf-3.4.0
export CXXFLAGS="$CXXFLAGS -fPIC"
./autogen.sh
./configure --prefix=$HOME/local --disable-shared
make install


echo "=============" 
echo "building mosh"
echo "============="

cd $ROOT/build/mosh-1.3.2
export PROTOC=$HOME/local/bin/protoc
export protobuf_CFLAGS=-I$HOME/local/include
export protobuf_LIBS=$HOME/local/lib/libprotobuf.a
./autogen.sh
./configure --prefix=$HOME/local
make install

echo "==="
echo "if all was successful, binaries are now in $ROOT/install/mosh/bin"
echo "==="
