Makefile 3.2 KB

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