1# 2# Copyright 2015 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17HOST_SYSTEM = $(shell uname | cut -f 1 -d_) 18SYSTEM ?= $(HOST_SYSTEM) 19CXX = g++ 20CPPFLAGS += `pkg-config --cflags protobuf grpc` 21CXXFLAGS += -std=c++11 22ifeq ($(SYSTEM),Darwin) 23LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\ 24 -lgrpc++_reflection\ 25 -ldl 26else 27LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++`\ 28 -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\ 29 -ldl 30endif 31PROTOC = protoc 32GRPC_CPP_PLUGIN = grpc_cpp_plugin 33GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` 34 35PROTOS_PATH = ../../protos 36 37vpath %.proto $(PROTOS_PATH) 38 39all: system-check route_guide_client route_guide_server 40 41route_guide_client: route_guide.pb.o route_guide.grpc.pb.o route_guide_client.o helper.o 42 $(CXX) $^ $(LDFLAGS) -o $@ 43 44route_guide_server: route_guide.pb.o route_guide.grpc.pb.o route_guide_server.o helper.o 45 $(CXX) $^ $(LDFLAGS) -o $@ 46 47%.grpc.pb.cc: %.proto 48 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< 49 50%.pb.cc: %.proto 51 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $< 52 53clean: 54 rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server 55 56 57# The following is to test your system and ensure a smoother experience. 58# They are by no means necessary to actually compile a grpc-enabled software. 59 60PROTOC_CMD = which $(PROTOC) 61PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 62PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) 63HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) 64ifeq ($(HAS_PROTOC),true) 65HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) 66endif 67HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) 68 69SYSTEM_OK = false 70ifeq ($(HAS_VALID_PROTOC),true) 71ifeq ($(HAS_PLUGIN),true) 72SYSTEM_OK = true 73endif 74endif 75 76system-check: 77ifneq ($(HAS_VALID_PROTOC),true) 78 @echo " DEPENDENCY ERROR" 79 @echo 80 @echo "You don't have protoc 3.0.0 installed in your path." 81 @echo "Please install Google protocol buffers 3.0.0 and its compiler." 82 @echo "You can find it here:" 83 @echo 84 @echo " https://github.com/google/protobuf/releases/tag/v3.0.0" 85 @echo 86 @echo "Here is what I get when trying to evaluate your version of protoc:" 87 @echo 88 -$(PROTOC) --version 89 @echo 90 @echo 91endif 92ifneq ($(HAS_PLUGIN),true) 93 @echo " DEPENDENCY ERROR" 94 @echo 95 @echo "You don't have the grpc c++ protobuf plugin installed in your path." 96 @echo "Please install grpc. You can find it here:" 97 @echo 98 @echo " https://github.com/grpc/grpc" 99 @echo 100 @echo "Here is what I get when trying to detect if you have the plugin:" 101 @echo 102 -which $(GRPC_CPP_PLUGIN) 103 @echo 104 @echo 105endif 106ifneq ($(SYSTEM_OK),true) 107 @false 108endif 109