summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-29 14:50:05 +0900
committerSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-30 13:32:57 +0900
commitaea13caea6ffc5a373fbfd5157c57d026b9f9a7a (patch)
treef0f3eeb4798001e319e192ed5a21ed61a52c20fd
parente314f126c1c5dc81c0d8ab33a4b450a10674052c (diff)
grpc: Improve building tools and docs for C++ client
This patch includes the following fixes: * update Makefile for protobuf 3.3.0 / gRPC 1.4.1 * make build.sh which generates stub codes and builds GoBGP shared library (instead, remove those operations from docs) Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r--docs/sources/grpc-client.md18
-rw-r--r--tools/grpc/cpp/Makefile16
-rw-r--r--tools/grpc/cpp/build.sh11
3 files changed, 30 insertions, 15 deletions
diff --git a/docs/sources/grpc-client.md b/docs/sources/grpc-client.md
index 3cb8e55c..088f6d60 100644
--- a/docs/sources/grpc-client.md
+++ b/docs/sources/grpc-client.md
@@ -79,19 +79,13 @@ We use .so compilation with golang, please use only 1.5 or newer version of Go L
['tools/grpc/cpp/gobgp_api_client.cc'](https://github.com/osrg/gobgp/blob/master/tools/grpc/cpp/gobgp_api_client.cc) shows an example for getting neighbor's information.
-Clone this repository and build API example:
+We provide ['tools/grpc/cpp/build.sh'](https://github.com/osrg/gobgp/blob/master/tools/grpc/cpp/build.sh) to build this sample code.
+This script also generates stub codes and builds GoBGP shared library.
+
+Let's build the sample code:
```bash
-export PATH="$PATH:/opt//grpc/bin:/opt/protobuf_3.0.0_alpha4/bin/"
-
-cd /usr/src
-git clone https://github.com/osrg/gobgp.git
-cd gobgp/gobgp/lib
-go build -buildmode=c-shared -o libgobgp.so *.go
-cp libgobgp.h /usr/src/gobgp/tools/grpc/cpp
-cp libgobgp.so /usr/src/gobgp/tools/grpc/cpp
-cp /usr/src/gobgp/api/gobgp.proto /usr/src/gobgp/tools/grpc/cpp/gobgp_api_client.proto
-cd /usr/src/gobgp/tools/grpc/cpp
-make
+$ cd $GOPATH/src/github.com/osrg/gobgp/tools/grpc/cpp
+$ bash build.sh
```
### Let's run it:
diff --git a/tools/grpc/cpp/Makefile b/tools/grpc/cpp/Makefile
index 2fcb5c8c..d50df9d9 100644
--- a/tools/grpc/cpp/Makefile
+++ b/tools/grpc/cpp/Makefile
@@ -1,7 +1,17 @@
+HOST_SYSTEM = $(shell uname | cut -f 1 -d_)
+SYSTEM ?= $(HOST_SYSTEM)
CXX = g++
-CPPFLAGS += -I/opt/protobuf_3.0.0_alpha4/include -I/opt/grpc/include -pthread
+CPPFLAGS += -I/usr/local/include -pthread
CXXFLAGS += -std=c++11
-LDFLAGS += -L/opt/grpc/lib -L/opt/protobuf_3.0.0_alpha4/lib -lgrpc++_unsecure -lgrpc -lgpr -lprotobuf -lpthread -ldl
+ifeq ($(SYSTEM),Darwin)
+LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++` \
+ -lgrpc++_reflection \
+ -lprotobuf -lpthread -ldl
+else
+LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++` \
+ -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \
+ -lprotobuf -lpthread -ldl
+endif
PROTOC = protoc
GRPC_CPP_PLUGIN = grpc_cpp_plugin
GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
@@ -13,7 +23,7 @@ vpath %.proto $(PROTOS_PATH)
all: system-check gobgp_api_client
gobgp_api_client: gobgp_api_client.pb.o gobgp_api_client.grpc.pb.o gobgp_api_client.o
- $(CXX) $^ $(LDFLAGS) -L. -lgobgp -o $@
+ $(CXX) $^ $(LDFLAGS) -L. -lgobgp -o $@
%.grpc.pb.cc: %.proto
$(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
diff --git a/tools/grpc/cpp/build.sh b/tools/grpc/cpp/build.sh
new file mode 100644
index 00000000..f1c7a92c
--- /dev/null
+++ b/tools/grpc/cpp/build.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+GOBGP_PATH=${GOPATH}/src/github.com/osrg/gobgp
+
+cd ${GOBGP_PATH}/gobgp/lib
+go build -buildmode=c-shared -o libgobgp.so *.go
+cd ${GOBGP_PATH}/tools/grpc/cpp
+ln -s ${GOBGP_PATH}/gobgp/lib/libgobgp.h
+ln -s ${GOBGP_PATH}/gobgp/lib/libgobgp.so
+ln -s ${GOBGP_PATH}/api/gobgp.proto gobgp_api_client.proto
+make