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