Makefile 12.6 KB
Newer Older
zhujiashun's avatar
zhujiashun committed
1 2 3 4 5 6 7
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
8
#
zhujiashun's avatar
zhujiashun committed
9
#   http://www.apache.org/licenses/LICENSE-2.0
10
#
zhujiashun's avatar
zhujiashun committed
11 12 13 14 15 16
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
17

18
NEED_LIBPROTOC=1
19
include config.mk
20 21

# Notes on the flags:
22 23 24 25
# 1. Added -fno-omit-frame-pointer: perf/tcmalloc-profiler use frame pointers by default
# 2. Added -D__const__= : Avoid over-optimizations of TLS variables by GCC>=4.8
# 3. Removed -Werror: Not block compilation for non-vital warnings, especially when the
#    code is tested on newer systems. If the code is used in production, add -Werror back
zhujiashun's avatar
zhujiashun committed
26
CPPFLAGS+=-DBTHREAD_USE_FAST_PTHREAD_MUTEX -D__const__= -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DNDEBUG -DBRPC_REVISION=\"$(shell ./tools/get_brpc_revision.sh .)\"
27 28
CXXFLAGS=$(CPPFLAGS) -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x
CFLAGS=$(CPPFLAGS) -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-unused-parameter -fno-omit-frame-pointer
29 30
DEBUG_CXXFLAGS = $(filter-out -DNDEBUG,$(CXXFLAGS)) -DUNIT_TEST -DBVAR_NOT_LINK_DEFAULT_VARIABLES
DEBUG_CFLAGS = $(filter-out -DNDEBUG,$(CFLAGS)) -DUNIT_TEST
gejun's avatar
gejun committed
31
HDRPATHS=-I./src $(addprefix -I, $(HDRS))
32
LIBPATHS = $(addprefix -L, $(LIBS))
33
COMMA = ,
34
SOPATHS = $(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS))
gejun's avatar
gejun committed
35
SRCEXTS = .c .cc .cpp .proto
36

37
SOEXT = so
38
ifeq ($(SYSTEM),Darwin)
39
    SOEXT = dylib
40 41
endif

42
#required by butil/crc32.cc to boost performance for 10x
43 44 45 46
ifeq ($(shell test $(GCC_VERSION) -ge 40400; echo $$?),0)
	CXXFLAGS+=-msse4 -msse4.2
endif
#not solved yet
47 48
ifeq ($(CC),gcc)
 ifeq ($(shell test $(GCC_VERSION) -ge 70000; echo $$?),0)
gejun's avatar
gejun committed
49
	CXXFLAGS+=-Wno-aligned-new
50
 endif
51
endif
gejun's avatar
gejun committed
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
BUTIL_SOURCES = \
    src/butil/third_party/dmg_fp/g_fmt.cc \
    src/butil/third_party/dmg_fp/dtoa_wrapper.cc \
    src/butil/third_party/dynamic_annotations/dynamic_annotations.c \
    src/butil/third_party/icu/icu_utf.cc \
    src/butil/third_party/superfasthash/superfasthash.c \
    src/butil/third_party/modp_b64/modp_b64.cc \
    src/butil/third_party/symbolize/demangle.cc \
    src/butil/third_party/symbolize/symbolize.cc \
    src/butil/third_party/snappy/snappy-sinksource.cc \
    src/butil/third_party/snappy/snappy-stubs-internal.cc \
    src/butil/third_party/snappy/snappy.cc \
    src/butil/third_party/murmurhash3/murmurhash3.cpp \
    src/butil/arena.cpp \
    src/butil/at_exit.cc \
    src/butil/atomicops_internals_x86_gcc.cc \
    src/butil/base64.cc \
    src/butil/big_endian.cc \
    src/butil/cpu.cc \
    src/butil/debug/alias.cc \
    src/butil/debug/asan_invalid_access.cc \
    src/butil/debug/crash_logging.cc \
    src/butil/debug/debugger.cc \
    src/butil/debug/debugger_posix.cc \
    src/butil/debug/dump_without_crashing.cc \
    src/butil/debug/proc_maps_linux.cc \
    src/butil/debug/stack_trace.cc \
    src/butil/debug/stack_trace_posix.cc \
    src/butil/environment.cc \
    src/butil/files/file.cc \
    src/butil/files/file_posix.cc \
    src/butil/files/file_enumerator.cc \
    src/butil/files/file_enumerator_posix.cc \
    src/butil/files/file_path.cc \
    src/butil/files/file_path_constants.cc \
    src/butil/files/memory_mapped_file.cc \
    src/butil/files/memory_mapped_file_posix.cc \
    src/butil/files/scoped_file.cc \
    src/butil/files/scoped_temp_dir.cc \
    src/butil/file_util.cc \
    src/butil/file_util_posix.cc \
    src/butil/guid.cc \
    src/butil/guid_posix.cc \
    src/butil/hash.cc \
    src/butil/lazy_instance.cc \
    src/butil/location.cc \
    src/butil/memory/aligned_memory.cc \
    src/butil/memory/ref_counted.cc \
    src/butil/memory/ref_counted_memory.cc \
    src/butil/memory/singleton.cc \
    src/butil/memory/weak_ptr.cc \
    src/butil/posix/file_descriptor_shuffle.cc \
    src/butil/posix/global_descriptors.cc \
106
    src/butil/process_util.cc \
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
    src/butil/rand_util.cc \
    src/butil/rand_util_posix.cc \
    src/butil/fast_rand.cpp \
    src/butil/safe_strerror_posix.cc \
    src/butil/sha1_portable.cc \
    src/butil/strings/latin1_string_conversions.cc \
    src/butil/strings/nullable_string16.cc \
    src/butil/strings/safe_sprintf.cc \
    src/butil/strings/string16.cc \
    src/butil/strings/string_number_conversions.cc \
    src/butil/strings/string_split.cc \
    src/butil/strings/string_piece.cc \
    src/butil/strings/string_util.cc \
    src/butil/strings/string_util_constants.cc \
    src/butil/strings/stringprintf.cc \
    src/butil/strings/utf_offset_string_conversions.cc \
    src/butil/strings/utf_string_conversion_utils.cc \
    src/butil/strings/utf_string_conversions.cc \
    src/butil/synchronization/cancellation_flag.cc \
    src/butil/synchronization/condition_variable_posix.cc \
    src/butil/synchronization/waitable_event_posix.cc \
    src/butil/threading/non_thread_safe_impl.cc \
    src/butil/threading/platform_thread_posix.cc \
    src/butil/threading/simple_thread.cc \
    src/butil/threading/thread_checker_impl.cc \
    src/butil/threading/thread_collision_warner.cc \
    src/butil/threading/thread_id_name_manager.cc \
    src/butil/threading/thread_local_posix.cc \
    src/butil/threading/thread_local_storage.cc \
    src/butil/threading/thread_local_storage_posix.cc \
    src/butil/threading/thread_restrictions.cc \
    src/butil/threading/watchdog.cc \
    src/butil/time/clock.cc \
    src/butil/time/default_clock.cc \
    src/butil/time/default_tick_clock.cc \
    src/butil/time/tick_clock.cc \
    src/butil/time/time.cc \
    src/butil/time/time_posix.cc \
    src/butil/version.cc \
    src/butil/logging.cc \
    src/butil/class_name.cpp \
    src/butil/errno.cpp \
    src/butil/find_cstr.cpp \
    src/butil/status.cpp \
    src/butil/string_printf.cpp \
    src/butil/thread_local.cpp \
    src/butil/unix_socket.cpp \
    src/butil/endpoint.cpp \
    src/butil/fd_utility.cpp \
    src/butil/files/temp_file.cpp \
    src/butil/files/file_watcher.cpp \
    src/butil/time.cpp \
    src/butil/zero_copy_stream_as_streambuf.cpp \
    src/butil/crc32c.cc \
    src/butil/containers/case_ignored_flat_map.cpp \
162
    src/butil/iobuf.cpp \
163
    src/butil/binary_printer.cpp \
164
    src/butil/recordio.cc \
165
    src/butil/popen.cpp
gejun's avatar
gejun committed
166

gejun's avatar
gejun committed
167 168
ifeq ($(SYSTEM), Linux)
    BUTIL_SOURCES += src/butil/file_util_linux.cc \
169 170
        src/butil/threading/platform_thread_linux.cc \
        src/butil/strings/sys_string_conversions_posix.cc
gejun's avatar
gejun committed
171 172 173
endif
ifeq ($(SYSTEM), Darwin)
    BUTIL_SOURCES += src/butil/mac/bundle_locations.mm \
174 175 176 177 178 179
		src/butil/mac/foundation_util.mm \
		src/butil/file_util_mac.mm \
		src/butil/threading/platform_thread_mac.mm \
		src/butil/strings/sys_string_conversions_mac.mm \
		src/butil/time/time_mac.cc \
		src/butil/mac/scoped_mach_port.cc
gejun's avatar
gejun committed
180 181
endif

182
BUTIL_OBJS = $(addsuffix .o, $(basename $(BUTIL_SOURCES)))
gejun's avatar
gejun committed
183

gejun's avatar
gejun committed
184
BVAR_DIRS = src/bvar src/bvar/detail
gejun's avatar
gejun committed
185 186 187
BVAR_SOURCES = $(foreach d,$(BVAR_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
BVAR_OBJS = $(addsuffix .o, $(basename $(BVAR_SOURCES))) 

gejun's avatar
gejun committed
188
BTHREAD_DIRS = src/bthread
gejun's avatar
gejun committed
189 190 191
BTHREAD_SOURCES = $(foreach d,$(BTHREAD_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
BTHREAD_OBJS = $(addsuffix .o, $(basename $(BTHREAD_SOURCES))) 

gejun's avatar
gejun committed
192
JSON2PB_DIRS = src/json2pb
gejun's avatar
gejun committed
193 194 195
JSON2PB_SOURCES = $(foreach d,$(JSON2PB_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
JSON2PB_OBJS = $(addsuffix .o, $(basename $(JSON2PB_SOURCES))) 

gejun's avatar
gejun committed
196
BRPC_DIRS = src/brpc src/brpc/details src/brpc/builtin src/brpc/policy
197 198 199
THRIFT_SOURCES = $(foreach d,$(BRPC_DIRS),$(wildcard $(addprefix $(d)/thrift*,$(SRCEXTS))))
BRPC_SOURCES_ALL = $(foreach d,$(BRPC_DIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
BRPC_SOURCES = $(filter-out $(THRIFT_SOURCES), $(BRPC_SOURCES_ALL))
gejun's avatar
gejun committed
200
BRPC_PROTOS = $(filter %.proto,$(BRPC_SOURCES))
201
BRPC_CFAMILIES = $(filter-out %.proto %.pb.cc,$(BRPC_SOURCES))
202
BRPC_OBJS = $(BRPC_PROTOS:.proto=.pb.o) $(addsuffix .o, $(basename $(BRPC_CFAMILIES)))
gejun's avatar
gejun committed
203 204

MCPACK2PB_SOURCES = \
gejun's avatar
gejun committed
205 206 207 208 209
	src/mcpack2pb/field_type.cpp \
	src/mcpack2pb/mcpack2pb.cpp \
	src/mcpack2pb/parser.cpp \
	src/mcpack2pb/serializer.cpp
MCPACK2PB_OBJS = src/idl_options.pb.o $(addsuffix .o, $(basename $(MCPACK2PB_SOURCES)))
gejun's avatar
gejun committed
210

211 212 213 214
ifeq (ENABLE_THRIFT_FRAMED_PROTOCOL, $(findstring ENABLE_THRIFT_FRAMED_PROTOCOL, $(CPPFLAGS)))
    THRIFT_OBJS = $(addsuffix .o, $(basename $(THRIFT_SOURCES)))
endif

215
OBJS=$(BUTIL_OBJS) $(BVAR_OBJS) $(BTHREAD_OBJS) $(JSON2PB_OBJS) $(MCPACK2PB_OBJS) $(BRPC_OBJS) $(THRIFT_OBJS)
216 217

BVAR_DEBUG_OBJS=$(BUTIL_OBJS:.o=.dbg.o) $(BVAR_OBJS:.o=.dbg.o)
gejun's avatar
gejun committed
218
DEBUG_OBJS = $(OBJS:.o=.dbg.o)
gejun's avatar
gejun committed
219

220 221
PROTOS=$(BRPC_PROTOS) src/idl_options.proto

gejun's avatar
gejun committed
222
.PHONY:all
223
all:  protoc-gen-mcpack libbrpc.a libbrpc.$(SOEXT) output/include output/lib output/bin
gejun's avatar
gejun committed
224

225
.PHONY:debug
226
debug: test/libbrpc.dbg.$(SOEXT) test/libbvar.dbg.a
227

gejun's avatar
gejun committed
228
.PHONY:clean
229
clean:
230 231
	@echo "> Cleaning"
	rm -rf src/mcpack2pb/generator.o protoc-gen-mcpack libbrpc.a libbrpc.$(SOEXT) $(OBJS) output/include output/lib output/bin $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc)
gejun's avatar
gejun committed
232

233 234
.PHONY:clean_debug
clean_debug:
235
	rm -rf test/libbrpc.dbg.$(SOEXT) test/libbvar.dbg.a $(DEBUG_OBJS)
236 237

.PRECIOUS: %.o
238

chenzhangyi01's avatar
chenzhangyi01 committed
239
protoc-gen-mcpack: src/idl_options.pb.cc src/mcpack2pb/generator.o libbrpc.a
240
	@echo "> Linking $@"
241
ifeq ($(SYSTEM),Linux)
242
	$(CXX) -o $@ $(HDRPATHS) $(LIBPATHS) -std=c++0x -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS)
243
else ifeq ($(SYSTEM),Darwin)
244
	$(CXX) -o $@ $(HDRPATHS) $(LIBPATHS) -std=c++0x $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
245
endif
gejun's avatar
gejun committed
246

247
# force generation of pb headers before compiling to avoid fail-to-import issues in compiling pb.cc
gejun's avatar
gejun committed
248
libbrpc.a:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
249 250
	@echo "> Packing $@"
	ar crs $@ $(filter %.o,$^)
251

252
libbrpc.$(SOEXT):$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
253
	@echo "> Linking $@"
254
ifeq ($(SYSTEM),Linux)
255
	$(CXX) -shared -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(filter %.o,$^) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
256
else ifeq ($(SYSTEM),Darwin)
257
	$(CXX) -dynamiclib -Wl,-headerpad_max_install_names -o $@ -install_name @rpath/$@ $(LIBPATHS) $(SOPATHS) $(filter %.o,$^) $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
258
endif
259

260
test/libbvar.dbg.a:$(BVAR_DEBUG_OBJS)
261
	@echo "> Packing $@"
262
	@ar crs $@ $^
263

264
test/libbrpc.dbg.$(SOEXT):$(BRPC_PROTOS:.proto=.pb.h) $(DEBUG_OBJS)
265
	@echo "> Linking $@"
266
ifeq ($(SYSTEM),Linux)
267
	$(CXX) -shared -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(filter %.o,$^) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
268
else ifeq ($(SYSTEM),Darwin)
269
	$(CXX) -dynamiclib -Wl,-headerpad_max_install_names -o $@ -install_name @rpath/libbrpc.dbg.$(SOEXT) $(LIBPATHS) $(SOPATHS) $(filter %.o,$^) $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
270
endif
gejun's avatar
gejun committed
271

gejun's avatar
gejun committed
272 273
.PHONY:output/include
output/include:
274
	@echo "> Copying to $@"
gejun's avatar
gejun committed
275 276 277
	@for dir in `find src -type f -name "*.h" -exec dirname {} \\; | sed -e 's/^src\///g' -e '/^src$$/d' | sort | uniq`; do mkdir -p $@/$$dir && cp src/$$dir/*.h $@/$$dir/; done
	@for dir in `find src -type f -name "*.hpp" -exec dirname {} \\; | sed -e 's/^src\///g' -e '/^src$$/d' | sort | uniq`; do mkdir -p $@/$$dir && cp src/$$dir/*.hpp $@/$$dir/; done
	@cp src/idl_options.proto src/idl_options.pb.h $@
gejun's avatar
gejun committed
278 279

.PHONY:output/lib
280
output/lib:libbrpc.a libbrpc.$(SOEXT)
281
	@echo "> Copying to $@"
gejun's avatar
gejun committed
282 283 284 285 286
	@mkdir -p $@
	@cp $^ $@

.PHONY:output/bin
output/bin:protoc-gen-mcpack
287
	@echo "> Copying to $@"
gejun's avatar
gejun committed
288 289 290
	@mkdir -p $@
	@cp $^ $@

291
%.pb.cc %.pb.h:%.proto
292 293
	@echo "> Generating $@"
	$(PROTOC) --cpp_out=./src --proto_path=./src --proto_path=$(PROTOBUF_HDR) $<
gejun's avatar
gejun committed
294 295

%.o:%.cpp
296 297
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
298

zhujiashun's avatar
zhujiashun committed
299
%http2_rpc_protocol.dbg.o:%http2_rpc_protocol.cpp
300 301
	@echo "> Compiling $@ with O2"
	$(CXX) -c $(HDRPATHS) -O2 $(DEBUG_CXXFLAGS) $< -o $@
zhujiashun's avatar
zhujiashun committed
302 303

%hpack.dbg.o:%hpack.cpp
304 305
	@echo "> Compiling $@ with O2"
	$(CXX) -c $(HDRPATHS) -O2 $(DEBUG_CXXFLAGS) $< -o $@
zhujiashun's avatar
zhujiashun committed
306

307
%.dbg.o:%.cpp
308 309
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(DEBUG_CXXFLAGS) $< -o $@
gejun's avatar
gejun committed
310 311

%.o:%.cc
312 313
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
314 315

%.dbg.o:%.cc
316 317
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(DEBUG_CXXFLAGS) $< -o $@
gejun's avatar
gejun committed
318

gejun's avatar
gejun committed
319
%.o:%.mm
320 321
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
gejun's avatar
gejun committed
322 323

%.dbg.o:%.mm
324 325
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(DEBUG_CXXFLAGS) $< -o $@
gejun's avatar
gejun committed
326

gejun's avatar
gejun committed
327
%.o:%.c
328 329
	@echo "> Compiling $@"
	$(CC) -c $(HDRPATHS) $(CFLAGS) $< -o $@
330 331

%.dbg.o:%.c
332 333
	@echo "> Compiling $@"
	$(CC) -c $(HDRPATHS) $(DEBUG_CFLAGS) $< -o $@