blob: 11f2a00cc8909b2d4701bdd62e647f81e08cb280 [file] [log] [blame]
Yang Gao7c7e9c32015-02-20 10:34:02 -08001#
Craig Tiller6169d5f2016-03-31 07:46:18 -07002# Copyright 2015, Google Inc.
Yang Gao7c7e9c32015-02-20 10:34:02 -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
Yang Gao56215452015-02-20 16:01:15 -080032CXX = g++
Nicolas "Pixel" Noble0118cf02015-03-06 22:42:02 +010033CPPFLAGS += -I/usr/local/include -pthread
34CXXFLAGS += -std=c++11
Nicolas "Pixel" Noble81159e52016-04-23 00:42:03 +020035LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++` -lprotobuf -lpthread -ldl
Yang Gao56215452015-02-20 16:01:15 -080036PROTOC = protoc
37GRPC_CPP_PLUGIN = grpc_cpp_plugin
38GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)`
Yang Gao7c7e9c32015-02-20 10:34:02 -080039
Yang Gao56215452015-02-20 16:01:15 -080040PROTOS_PATH = ../../protos
41
42vpath %.proto $(PROTOS_PATH)
43
44all: system-check route_guide_client route_guide_server
Yang Gao7c7e9c32015-02-20 10:34:02 -080045
Yang Gaob10d00e2015-04-13 09:40:38 -070046route_guide_client: route_guide.pb.o route_guide.grpc.pb.o route_guide_client.o helper.o
Yang Gao56215452015-02-20 16:01:15 -080047 $(CXX) $^ $(LDFLAGS) -o $@
Yang Gao7c7e9c32015-02-20 10:34:02 -080048
Yang Gaob10d00e2015-04-13 09:40:38 -070049route_guide_server: route_guide.pb.o route_guide.grpc.pb.o route_guide_server.o helper.o
Yang Gao56215452015-02-20 16:01:15 -080050 $(CXX) $^ $(LDFLAGS) -o $@
51
Nicolas "Pixel" Noble9efc0832015-04-10 00:15:08 +020052%.grpc.pb.cc: %.proto
53 $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $<
54
Yang Gao56215452015-02-20 16:01:15 -080055%.pb.cc: %.proto
Nicolas "Pixel" Noble9efc0832015-04-10 00:15:08 +020056 $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $<
Yang Gao7c7e9c32015-02-20 10:34:02 -080057
58clean:
Yang Gao56215452015-02-20 16:01:15 -080059 rm -f *.o *.pb.cc *.pb.h route_guide_client route_guide_server
Yang Gao7c7e9c32015-02-20 10:34:02 -080060
Yang Gao56215452015-02-20 16:01:15 -080061
62# The following is to test your system and ensure a smoother experience.
63# They are by no means necessary to actually compile a grpc-enabled software.
64
65PROTOC_CMD = which $(PROTOC)
66PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3
67PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN)
68HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false)
69ifeq ($(HAS_PROTOC),true)
70HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false)
71endif
72HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false)
73
74SYSTEM_OK = false
75ifeq ($(HAS_VALID_PROTOC),true)
76ifeq ($(HAS_PLUGIN),true)
77SYSTEM_OK = true
78endif
79endif
80
81system-check:
82ifneq ($(HAS_VALID_PROTOC),true)
83 @echo " DEPENDENCY ERROR"
84 @echo
85 @echo "You don't have protoc 3.0.0 installed in your path."
86 @echo "Please install Google protocol buffers 3.0.0 and its compiler."
87 @echo "You can find it here:"
88 @echo
Przemysław Sobalaea9a0312016-01-27 14:07:09 +010089 @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-beta-2"
Yang Gao56215452015-02-20 16:01:15 -080090 @echo
91 @echo "Here is what I get when trying to evaluate your version of protoc:"
92 @echo
93 -$(PROTOC) --version
94 @echo
95 @echo
96endif
97ifneq ($(HAS_PLUGIN),true)
98 @echo " DEPENDENCY ERROR"
99 @echo
100 @echo "You don't have the grpc c++ protobuf plugin installed in your path."
101 @echo "Please install grpc. You can find it here:"
102 @echo
103 @echo " https://github.com/grpc/grpc"
104 @echo
105 @echo "Here is what I get when trying to detect if you have the plugin:"
106 @echo
107 -which $(GRPC_CPP_PLUGIN)
108 @echo
109 @echo
110endif
111ifneq ($(SYSTEM_OK),true)
112 @false
113endif