Makefile 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. NEED_GPERFTOOLS=1
  18. BRPC_PATH=../..
  19. include $(BRPC_PATH)/config.mk
  20. # Notes on the flags:
  21. # 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
  22. # 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
  23. CXXFLAGS+=$(CPPFLAGS) -std=c++0x -DNDEBUG -O2 -D__const__= -pipe -W -Wall -Wno-unused-parameter -fPIC -fno-omit-frame-pointer
  24. ifeq ($(NEED_GPERFTOOLS), 1)
  25. CXXFLAGS+=-DBRPC_ENABLE_CPU_PROFILER
  26. endif
  27. HDRS+=$(BRPC_PATH)/output/include
  28. LIBS+=$(BRPC_PATH)/output/lib
  29. HDRPATHS=$(addprefix -I, $(HDRS))
  30. LIBPATHS=$(addprefix -L, $(LIBS))
  31. COMMA=,
  32. SOPATHS=$(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS))
  33. CLIENT_SOURCES = client.cpp
  34. SERVER_SOURCES = server.cpp
  35. PROTOS = $(wildcard *.proto)
  36. PROTO_OBJS = $(PROTOS:.proto=.pb.o)
  37. PROTO_GENS = $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc)
  38. CLIENT_OBJS = $(addsuffix .o, $(basename $(CLIENT_SOURCES)))
  39. SERVER_OBJS = $(addsuffix .o, $(basename $(SERVER_SOURCES)))
  40. ifeq ($(SYSTEM),Darwin)
  41. ifneq ("$(LINK_SO)", "")
  42. STATIC_LINKINGS += -lbrpc
  43. else
  44. # *.a must be explicitly specified in clang
  45. STATIC_LINKINGS += $(BRPC_PATH)/output/lib/libbrpc.a
  46. endif
  47. LINK_OPTIONS_SO = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  48. LINK_OPTIONS = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  49. else ifeq ($(SYSTEM),Linux)
  50. STATIC_LINKINGS += -lbrpc
  51. LINK_OPTIONS_SO = -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  52. LINK_OPTIONS = -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS)
  53. endif
  54. .PHONY:all
  55. all: echo_client echo_server
  56. .PHONY:clean
  57. clean:
  58. @echo "> Cleaning"
  59. rm -rf echo_client echo_server $(PROTO_GENS) $(PROTO_OBJS) $(CLIENT_OBJS) $(SERVER_OBJS)
  60. echo_client:$(PROTO_OBJS) $(CLIENT_OBJS)
  61. @echo "> Linking $@"
  62. ifneq ("$(LINK_SO)", "")
  63. $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@
  64. else
  65. $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@
  66. endif
  67. echo_server:$(PROTO_OBJS) $(SERVER_OBJS)
  68. @echo "> Linking $@"
  69. ifneq ("$(LINK_SO)", "")
  70. $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@
  71. else
  72. $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@
  73. endif
  74. %.pb.cc %.pb.h:%.proto
  75. @echo "> Generating $@"
  76. $(PROTOC) --cpp_out=. --proto_path=. $(PROTOC_EXTRA_ARGS) $<
  77. %.o:%.cpp
  78. @echo "> Compiling $@"
  79. $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
  80. %.o:%.cc
  81. @echo "> Compiling $@"
  82. $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@