blob: 8b6025f3434fb772dbfbcb5c2043c7bec8e60539 [file] [log] [blame]
Yang Gaod9569372015-02-19 14:22:52 -08001#
Craig Tiller6169d5f2016-03-31 07:46:18 -07002# Copyright 2015, Google Inc.
Yang Gaod9569372015-02-19 14:22:52 -08003# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#
31
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010032CXX = g++
Nicolas "Pixel" Noble0118cf02015-03-06 22:42:02 +010033CPPFLAGS += -I/usr/local/include -pthread
34CXXFLAGS += -std=c++11
Yuchen Zeng1c58bd22016-07-07 14:17:32 -070035LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++ grpc` \
Muxi Yan4e3df002016-07-26 13:28:54 -070036 -lgrpc++_reflection \
Yuchen Zeng1c58bd22016-07-07 14:17:32 -070037 -lprotobuf -lpthread -ldl
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010038PROTOC = protoc
39GRPC_CPP_PLUGIN = grpc_cpp_plugin
40GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
Yang Gaod9569372015-02-19 14:22:52 -080041
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010042PROTOS_PATH = ../../protos
43
44vpath %.proto $(PROTOS_PATH)
45
Michael Yeh470cbd12016-05-04 12:39:20 -070046all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server
Yang Gaod9569372015-02-19 14:22:52 -080047
Yang Gao8d7ce532015-04-13 09:34:53 -070048greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010049 $(CXX) $^ $(LDFLAGS) -o $@
Yang Gao72bc5642015-02-19 14:45:41 -080050
Yang Gao8d7ce532015-04-13 09:34:53 -070051greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010052 $(CXX) $^ $(LDFLAGS) -o $@
53
Yang Gaobe8ac562015-04-14 00:15:10 -070054greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o
55 $(CXX) $^ $(LDFLAGS) -o $@
56
Michael Yeh470cbd12016-05-04 12:39:20 -070057greeter_async_client2: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client2.o
58 $(CXX) $^ $(LDFLAGS) -o $@
59
Yang Gaobe8ac562015-04-14 00:15:10 -070060greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o
61 $(CXX) $^ $(LDFLAGS) -o $@
62
David Garcia Quintas6bd7b972016-01-27 19:21:12 -080063.PRECIOUS: %.grpc.pb.cc
Nicolas "Pixel" Noble9efc0832015-04-10 00:15:08 +020064%.grpc.pb.cc: %.proto
65 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
66
David Garcia Quintas6bd7b972016-01-27 19:21:12 -080067.PRECIOUS: %.pb.cc
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010068%.pb.cc: %.proto
Nicolas "Pixel" Noble9efc0832015-04-10 00:15:08 +020069 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
Yang Gaod9569372015-02-19 14:22:52 -080070
71clean:
Michael Yeh470cbd12016-05-04 12:39:20 -070072 rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server
Yang Gaod9569372015-02-19 14:22:52 -080073
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010074
75# The following is to test your system and ensure a smoother experience.
76# They are by no means necessary to actually compile a grpc-enabled software.
77
78PROTOC_CMD = which $(PROTOC)
79PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
80PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
81HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
82ifeq ($(HAS_PROTOC),true)
83HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
84endif
85HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
86
87SYSTEM_OK = false
88ifeq ($(HAS_VALID_PROTOC),true)
89ifeq ($(HAS_PLUGIN),true)
90SYSTEM_OK = true
91endif
92endif
93
94system-check:
95ifneq ($(HAS_VALID_PROTOC),true)
96 @echo " DEPENDENCY ERROR"
97 @echo
98 @echo "You don't have protoc 3.0.0 installed in your path."
99 @echo "Please install Google protocol buffers 3.0.0 and its compiler."
100 @echo "You can find it here:"
101 @echo
Jorge Canizalesf29e3642016-07-01 15:56:57 -0700102 @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-beta-3.3"
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +0100103 @echo
104 @echo "Here is what I get when trying to evaluate your version of protoc:"
105 @echo
106 -$(PROTOC) --version
107 @echo
108 @echo
109endif
110ifneq ($(HAS_PLUGIN),true)
111 @echo " DEPENDENCY ERROR"
112 @echo
113 @echo "You don't have the grpc c++ protobuf plugin installed in your path."
114 @echo "Please install grpc. You can find it here:"
115 @echo
116 @echo " https://github.com/grpc/grpc"
117 @echo
118 @echo "Here is what I get when trying to detect if you have the plugin:"
119 @echo
120 -which $(GRPC_CPP_PLUGIN)
121 @echo
122 @echo
123endif
124ifneq ($(SYSTEM_OK),true)
125 @false
126endif