#!/bin/bash
git clone https://gitlab.rosc.org.cn/maqun001/grpc.git
apt-get update
apt install -y build-essential autoconf libtool pkg-config
apt-get install automake make g++ unzip
apt-get install libflags-dev libgtest-dev
apt-get install clang libc++-dev
apt-get install cmake
cd grpc
# Install absl
mkdir -p "third_party/abseil-cpp/cmake/build"
pushd "third_party/abseil-cpp/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make install
popd
# Install protobuf
mkdir -p "third_party/protobuf/cmake/build"
pushd "third_party/protobuf/cmake/build"
cmake -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ..
make install
popd
#install c-ares
mkdir -p "third_party/cares/cares/cmake/build"
pushd "third_party/cares/cares/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release ../..
make install
popd
# Install re2
mkdir -p "third_party/re2/cmake/build"
pushd "third_party/re2/cmake/build"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make -j4 install
popd
#install grpc
mkdir -p "cmake/build"
pushd "cmake/build"
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \
-DgRPC_RE2_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DgRPC_ZLIB_PROVIDER=package \
../..
make
make install
popd
# build helloworld example using cmake
#mkdir -p "examples/cpp/helloworld/cmake/build"
#pushd "examples/cpp/helloworld/cmake/build"
#cmake ../..
#make
#popd
#cd ..
#git clone https://gitlab.rosc.org.cn/maqun001/hyy_controller_grpc.git