blob: 5a7c34faff35c960286a4a360bbdf82f7f5c437c [file] [log] [blame]
Yang Gaod9569372015-02-19 14:22:52 -08001#
2# Copyright 2015, Google Inc.
3# 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
35LDFLAGS += -L/usr/local/lib -lgrpc -lgrpc++ -lprotobuf -lpthread -ldl
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010036PROTOC = protoc
37GRPC_CPP_PLUGIN = grpc_cpp_plugin
38GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
Yang Gaod9569372015-02-19 14:22:52 -080039
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010040PROTOS_PATH = ../../protos
41
42vpath %.proto $(PROTOS_PATH)
43
44all: system-check greeter_client greeter_server
Yang Gaod9569372015-02-19 14:22:52 -080045
Yang Gao72bc5642015-02-19 14:45:41 -080046greeter_client: helloworld.pb.o greeter_client.o
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010047 $(CXX) $^ $(LDFLAGS) -o $@
Yang Gao72bc5642015-02-19 14:45:41 -080048
49greeter_server: helloworld.pb.o greeter_server.o
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010050 $(CXX) $^ $(LDFLAGS) -o $@
51
52%.pb.cc: %.proto
53 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
Yang Gaod9569372015-02-19 14:22:52 -080054
55clean:
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010056 rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server
Yang Gaod9569372015-02-19 14:22:52 -080057
Nicolas "Pixel" Nobleb7538ee2015-02-20 22:56:43 +010058
59# The following is to test your system and ensure a smoother experience.
60# They are by no means necessary to actually compile a grpc-enabled software.
61
62PROTOC_CMD = which $(PROTOC)
63PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
64PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
65HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
66ifeq ($(HAS_PROTOC),true)
67HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
68endif
69HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
70
71SYSTEM_OK = false
72ifeq ($(HAS_VALID_PROTOC),true)
73ifeq ($(HAS_PLUGIN),true)
74SYSTEM_OK = true
75endif
76endif
77
78system-check:
79ifneq ($(HAS_VALID_PROTOC),true)
80 @echo " DEPENDENCY ERROR"
81 @echo
82 @echo "You don't have protoc 3.0.0 installed in your path."
83 @echo "Please install Google protocol buffers 3.0.0 and its compiler."
84 @echo "You can find it here:"
85 @echo
86 @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-1"
87 @echo
88 @echo "Here is what I get when trying to evaluate your version of protoc:"
89 @echo
90 -$(PROTOC) --version
91 @echo
92 @echo
93endif
94ifneq ($(HAS_PLUGIN),true)
95 @echo " DEPENDENCY ERROR"
96 @echo
97 @echo "You don't have the grpc c++ protobuf plugin installed in your path."
98 @echo "Please install grpc. You can find it here:"
99 @echo
100 @echo " https://github.com/grpc/grpc"
101 @echo
102 @echo "Here is what I get when trying to detect if you have the plugin:"
103 @echo
104 -which $(GRPC_CPP_PLUGIN)
105 @echo
106 @echo
107endif
108ifneq ($(SYSTEM_OK),true)
109 @false
110endif