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