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 17 HOST_SYSTEM = $(shell uname | cut -f 1 -d_) 18 SYSTEM ?= $(HOST_SYSTEM) 19 CXX = g++ 20 CPPFLAGS += `pkg-config --cflags protobuf grpc` 21 CXXFLAGS += -std=c++11 22 ifeq ($(SYSTEM),Darwin) 23 LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ 24 -lgrpc++_reflection\ 25 -ldl 26 else 27 LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\ 28 -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed\ 29 -ldl 30 endif 31 PROTOC = protoc 32 GRPC_CPP_PLUGIN = grpc_cpp_plugin 33 GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` 34 35 PROTOS_PATH = ../../protos 36 37 vpath %.proto $(PROTOS_PATH) 38 39 all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server 40 41 greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o 42 $(CXX) $^ $(LDFLAGS) -o $@ 43 44 greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o 45 $(CXX) $^ $(LDFLAGS) -o $@ 46 47 greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o 48 $(CXX) $^ $(LDFLAGS) -o $@ 49 50 greeter_async_client2: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client2.o 51 $(CXX) $^ $(LDFLAGS) -o $@ 52 53 greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o 54 $(CXX) $^ $(LDFLAGS) -o $@ 55 56 .PRECIOUS: %.grpc.pb.cc 57 %.grpc.pb.cc: %.proto 58 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< 59 60 .PRECIOUS: %.pb.cc 61 %.pb.cc: %.proto 62 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $< 63 64 clean: 65 rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server 66 67 68 # The following is to test your system and ensure a smoother experience. 69 # They are by no means necessary to actually compile a grpc-enabled software. 70 71 PROTOC_CMD = which $(PROTOC) 72 PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 73 PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) 74 HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) 75 ifeq ($(HAS_PROTOC),true) 76 HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) 77 endif 78 HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) 79 80 SYSTEM_OK = false 81 ifeq ($(HAS_VALID_PROTOC),true) 82 ifeq ($(HAS_PLUGIN),true) 83 SYSTEM_OK = true 84 endif 85 endif 86 87 system-check: 88 ifneq ($(HAS_VALID_PROTOC),true) 89 @echo " DEPENDENCY ERROR" 90 @echo 91 @echo "You don't have protoc 3.0.0 installed in your path." 92 @echo "Please install Google protocol buffers 3.0.0 and its compiler." 93 @echo "You can find it here:" 94 @echo 95 @echo " https://github.com/google/protobuf/releases/tag/v3.0.0" 96 @echo 97 @echo "Here is what I get when trying to evaluate your version of protoc:" 98 @echo 99 -$(PROTOC) --version 100 @echo 101 @echo 102 endif 103 ifneq ($(HAS_PLUGIN),true) 104 @echo " DEPENDENCY ERROR" 105 @echo 106 @echo "You don't have the grpc c++ protobuf plugin installed in your path." 107 @echo "Please install grpc. You can find it here:" 108 @echo 109 @echo " https://github.com/grpc/grpc" 110 @echo 111 @echo "Here is what I get when trying to detect if you have the plugin:" 112 @echo 113 -which $(GRPC_CPP_PLUGIN) 114 @echo 115 @echo 116 endif 117 ifneq ($(SYSTEM_OK),true) 118 @false 119 endif 120