Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 1 | # |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 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 | |
Muxi Yan | cd0d8ae | 2016-07-26 14:13:46 -0700 | [diff] [blame] | 32 | HOST_SYSTEM = $(shell uname | cut -f 1 -d_) |
| 33 | SYSTEM ?= $(HOST_SYSTEM) |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 34 | CXX = g++ |
Nicolas "Pixel" Noble | 0118cf0 | 2015-03-06 22:42:02 +0100 | [diff] [blame] | 35 | CPPFLAGS += -I/usr/local/include -pthread |
| 36 | CXXFLAGS += -std=c++11 |
Muxi Yan | cd0d8ae | 2016-07-26 14:13:46 -0700 | [diff] [blame] | 37 | ifeq ($(SYSTEM),Darwin) |
Yuchen Zeng | 1c58bd2 | 2016-07-07 14:17:32 -0700 | [diff] [blame] | 38 | LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++ grpc` \ |
Muxi Yan | 4e3df00 | 2016-07-26 13:28:54 -0700 | [diff] [blame] | 39 | -lgrpc++_reflection \ |
Yuchen Zeng | 1c58bd2 | 2016-07-07 14:17:32 -0700 | [diff] [blame] | 40 | -lprotobuf -lpthread -ldl |
Muxi Yan | cd0d8ae | 2016-07-26 14:13:46 -0700 | [diff] [blame] | 41 | else |
| 42 | LDFLAGS += -L/usr/local/lib `pkg-config --libs grpc++ grpc` \ |
| 43 | -Wl,--no-as-needed -lgrpc++_reflection -Wl,--as-needed \ |
| 44 | -lprotobuf -lpthread -ldl |
| 45 | endif |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 46 | PROTOC = protoc |
| 47 | GRPC_CPP_PLUGIN = grpc_cpp_plugin |
| 48 | GRPC_CPP_PLUGIN_PATH ?= `which $(GRPC_CPP_PLUGIN)` |
Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 49 | |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 50 | PROTOS_PATH = ../../protos |
| 51 | |
| 52 | vpath %.proto $(PROTOS_PATH) |
| 53 | |
Michael Yeh | 470cbd1 | 2016-05-04 12:39:20 -0700 | [diff] [blame] | 54 | all: system-check greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server |
Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 55 | |
Yang Gao | 8d7ce53 | 2015-04-13 09:34:53 -0700 | [diff] [blame] | 56 | greeter_client: helloworld.pb.o helloworld.grpc.pb.o greeter_client.o |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 57 | $(CXX) $^ $(LDFLAGS) -o $@ |
Yang Gao | 72bc564 | 2015-02-19 14:45:41 -0800 | [diff] [blame] | 58 | |
Yang Gao | 8d7ce53 | 2015-04-13 09:34:53 -0700 | [diff] [blame] | 59 | greeter_server: helloworld.pb.o helloworld.grpc.pb.o greeter_server.o |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 60 | $(CXX) $^ $(LDFLAGS) -o $@ |
| 61 | |
Yang Gao | be8ac56 | 2015-04-14 00:15:10 -0700 | [diff] [blame] | 62 | greeter_async_client: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client.o |
| 63 | $(CXX) $^ $(LDFLAGS) -o $@ |
| 64 | |
Michael Yeh | 470cbd1 | 2016-05-04 12:39:20 -0700 | [diff] [blame] | 65 | greeter_async_client2: helloworld.pb.o helloworld.grpc.pb.o greeter_async_client2.o |
| 66 | $(CXX) $^ $(LDFLAGS) -o $@ |
| 67 | |
Yang Gao | be8ac56 | 2015-04-14 00:15:10 -0700 | [diff] [blame] | 68 | greeter_async_server: helloworld.pb.o helloworld.grpc.pb.o greeter_async_server.o |
| 69 | $(CXX) $^ $(LDFLAGS) -o $@ |
| 70 | |
David Garcia Quintas | 6bd7b97 | 2016-01-27 19:21:12 -0800 | [diff] [blame] | 71 | .PRECIOUS: %.grpc.pb.cc |
Nicolas "Pixel" Noble | 9efc083 | 2015-04-10 00:15:08 +0200 | [diff] [blame] | 72 | %.grpc.pb.cc: %.proto |
| 73 | $(PROTOC) -I $(PROTOS_PATH) --grpc_out=. --plugin=protoc-gen-grpc=$(GRPC_CPP_PLUGIN_PATH) $< |
| 74 | |
David Garcia Quintas | 6bd7b97 | 2016-01-27 19:21:12 -0800 | [diff] [blame] | 75 | .PRECIOUS: %.pb.cc |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 76 | %.pb.cc: %.proto |
Nicolas "Pixel" Noble | 9efc083 | 2015-04-10 00:15:08 +0200 | [diff] [blame] | 77 | $(PROTOC) -I $(PROTOS_PATH) --cpp_out=. $< |
Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 78 | |
| 79 | clean: |
Michael Yeh | 470cbd1 | 2016-05-04 12:39:20 -0700 | [diff] [blame] | 80 | rm -f *.o *.pb.cc *.pb.h greeter_client greeter_server greeter_async_client greeter_async_client2 greeter_async_server |
Yang Gao | d956937 | 2015-02-19 14:22:52 -0800 | [diff] [blame] | 81 | |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 82 | |
| 83 | # The following is to test your system and ensure a smoother experience. |
| 84 | # They are by no means necessary to actually compile a grpc-enabled software. |
| 85 | |
| 86 | PROTOC_CMD = which $(PROTOC) |
| 87 | PROTOC_CHECK_CMD = $(PROTOC) --version | grep -q libprotoc.3 |
| 88 | PLUGIN_CHECK_CMD = which $(GRPC_CPP_PLUGIN) |
| 89 | HAS_PROTOC = $(shell $(PROTOC_CMD) > /dev/null && echo true || echo false) |
| 90 | ifeq ($(HAS_PROTOC),true) |
| 91 | HAS_VALID_PROTOC = $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) |
| 92 | endif |
| 93 | HAS_PLUGIN = $(shell $(PLUGIN_CHECK_CMD) > /dev/null && echo true || echo false) |
| 94 | |
| 95 | SYSTEM_OK = false |
| 96 | ifeq ($(HAS_VALID_PROTOC),true) |
| 97 | ifeq ($(HAS_PLUGIN),true) |
| 98 | SYSTEM_OK = true |
| 99 | endif |
| 100 | endif |
| 101 | |
| 102 | system-check: |
| 103 | ifneq ($(HAS_VALID_PROTOC),true) |
| 104 | @echo " DEPENDENCY ERROR" |
| 105 | @echo |
| 106 | @echo "You don't have protoc 3.0.0 installed in your path." |
| 107 | @echo "Please install Google protocol buffers 3.0.0 and its compiler." |
| 108 | @echo "You can find it here:" |
| 109 | @echo |
Jorge Canizales | f29e364 | 2016-07-01 15:56:57 -0700 | [diff] [blame] | 110 | @echo " https://github.com/google/protobuf/releases/tag/v3.0.0-beta-3.3" |
Nicolas "Pixel" Noble | b7538ee | 2015-02-20 22:56:43 +0100 | [diff] [blame] | 111 | @echo |
| 112 | @echo "Here is what I get when trying to evaluate your version of protoc:" |
| 113 | @echo |
| 114 | -$(PROTOC) --version |
| 115 | @echo |
| 116 | @echo |
| 117 | endif |
| 118 | ifneq ($(HAS_PLUGIN),true) |
| 119 | @echo " DEPENDENCY ERROR" |
| 120 | @echo |
| 121 | @echo "You don't have the grpc c++ protobuf plugin installed in your path." |
| 122 | @echo "Please install grpc. You can find it here:" |
| 123 | @echo |
| 124 | @echo " https://github.com/grpc/grpc" |
| 125 | @echo |
| 126 | @echo "Here is what I get when trying to detect if you have the plugin:" |
| 127 | @echo |
| 128 | -which $(GRPC_CPP_PLUGIN) |
| 129 | @echo |
| 130 | @echo |
| 131 | endif |
| 132 | ifneq ($(SYSTEM_OK),true) |
| 133 | @false |
| 134 | endif |