Makefile 4.0 KB

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