Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = http_client.cpp
  34. BENCHMARK_SOURCES = benchmark_http.cpp
  35. SERVER_SOURCES = http_server.cpp
  36. PROTOS = http.proto
  37. PROTO_OBJS = $(PROTOS:.proto=.pb.o)
  38. PROTO_GENS = $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc)
  39. CLIENT_OBJS = $(addsuffix .o, $(basename $(CLIENT_SOURCES)))
  40. BENCHMARK_OBJS = $(addsuffix .o, $(basename $(BENCHMARK_SOURCES)))
  41. SERVER_OBJS = $(addsuffix .o, $(basename $(SERVER_SOURCES)))
  42. ifeq ($(SYSTEM),Darwin)
  43. ifneq ("$(LINK_SO)", "")
  44. STATIC_LINKINGS += -lbrpc
  45. else
  46. # *.a must be explicitly specified in clang
  47. STATIC_LINKINGS += $(BRPC_PATH)/output/lib/libbrpc.a
  48. endif
  49. LINK_OPTIONS_SO = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  50. LINK_OPTIONS = $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  51. else ifeq ($(SYSTEM),Linux)
  52. STATIC_LINKINGS += -lbrpc
  53. LINK_OPTIONS_SO = -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
  54. LINK_OPTIONS = -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS)
  55. endif
  56. .PHONY:all
  57. all: http_client benchmark_http http_server
  58. .PHONY:clean
  59. clean:
  60. @echo "> Cleaning"
  61. rm -rf http_client benchmark_http http_server $(PROTO_GENS) $(PROTO_OBJS) $(CLIENT_OBJS) $(BENCHMARK_OBJS) $(SERVER_OBJS)
  62. http_client:$(CLIENT_OBJS)
  63. @echo "> Linking $@"
  64. ifneq ("$(LINK_SO)", "")
  65. $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@
  66. else
  67. $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@
  68. endif
  69. benchmark_http:$(BENCHMARK_OBJS)
  70. @echo "> Linking $@"
  71. ifneq ("$(LINK_SO)", "")
  72. $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@
  73. else
  74. $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@
  75. endif
  76. http_server:$(PROTO_OBJS) $(SERVER_OBJS)
  77. @echo "> Linking $@"
  78. ifneq ("$(LINK_SO)", "")
  79. $(CXX) $(LIBPATHS) $(SOPATHS) $(LINK_OPTIONS_SO) -o $@
  80. else
  81. $(CXX) $(LIBPATHS) $(LINK_OPTIONS) -o $@
  82. endif
  83. %.pb.cc %.pb.h:%.proto
  84. @echo "> Generating $@"
  85. $(PROTOC) --cpp_out=. --proto_path=. $<
  86. %.o:%.cpp
  87. @echo "> Compiling $@"
  88. $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
  89. %.o:%.cc
  90. @echo "> Compiling $@"
  91. $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@