Makefile 8.12 KB
Newer Older
zhujiashun's avatar
zhujiashun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 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
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

18 19 20
NEED_GPERFTOOLS=1
NEED_GTEST=1
include ../config.mk
21
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 -DUNIT_TEST -Dprivate=public -Dprotected=public -DBVAR_NOT_LINK_DEFAULT_VARIABLES --include sstream_workaround.h
22
CXXFLAGS=$(CPPFLAGS) -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -std=c++0x
gejun's avatar
gejun committed
23

24
#required by butil/crc32.cc to boost performance for 10x
25 26 27 28
ifeq ($(shell test $(GCC_VERSION) -ge 40400; echo $$?),0)
	CXXFLAGS+=-msse4 -msse4.2
endif
#not solved yet
29 30
ifeq ($(CC),gcc)
 ifeq ($(shell test $(GCC_VERSION) -ge 70000; echo $$?),0)
31
	CXXFLAGS+=-Wno-aligned-new
32
 endif
33
endif
34

35
LIBS += .
36
HDRPATHS=-I. -I../src $(addprefix -I, $(HDRS))
37
LIBPATHS=$(addprefix -L, $(LIBS))
38

39 40 41 42 43 44 45 46
COMMA = ,
SOPATHS = $(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS))

SOEXT = so
ifeq ($(SYSTEM),Darwin)
    SOEXT = dylib
endif

47
TEST_BUTIL_SOURCES = \
48 49 50 51 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 106 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
    at_exit_unittest.cc \
    atomicops_unittest.cc \
    base64_unittest.cc \
    big_endian_unittest.cc \
    bits_unittest.cc \
    hash_tables_unittest.cc \
    linked_list_unittest.cc \
    mru_cache_unittest.cc \
    small_map_unittest.cc \
    stack_container_unittest.cc \
    cpu_unittest.cc \
    crash_logging_unittest.cc \
    leak_tracker_unittest.cc \
    stack_trace_unittest.cc \
    environment_unittest.cc \
    file_util_unittest.cc \
    dir_reader_posix_unittest.cc \
    file_path_unittest.cc \
    file_unittest.cc \
    scoped_temp_dir_unittest.cc \
    guid_unittest.cc \
    hash_unittest.cc \
    lazy_instance_unittest.cc \
    aligned_memory_unittest.cc \
    linked_ptr_unittest.cc \
    ref_counted_memory_unittest.cc \
    ref_counted_unittest.cc \
    scoped_ptr_unittest.cc \
    scoped_vector_unittest.cc \
    singleton_unittest.cc \
    weak_ptr_unittest.cc \
    observer_list_unittest.cc \
    file_descriptor_shuffle_unittest.cc \
    rand_util_unittest.cc \
    safe_numerics_unittest.cc \
    scoped_clear_errno_unittest.cc \
    scoped_generic_unittest.cc \
    security_unittest.cc \
    sha1_unittest.cc \
    stl_util_unittest.cc \
    nullable_string16_unittest.cc \
    safe_sprintf_unittest.cc \
    string16_unittest.cc \
    stringprintf_unittest.cc \
    string_number_conversions_unittest.cc \
    string_piece_unittest.cc \
    string_split_unittest.cc \
    string_tokenizer_unittest.cc \
    string_util_unittest.cc \
    stringize_macros_unittest.cc \
    sys_string_conversions_unittest.cc \
    utf_offset_string_conversions_unittest.cc \
    utf_string_conversions_unittest.cc \
    cancellation_flag_unittest.cc \
    condition_variable_unittest.cc \
    lock_unittest.cc \
    waitable_event_unittest.cc \
    type_traits_unittest.cc \
    non_thread_safe_unittest.cc \
    platform_thread_unittest.cc \
    simple_thread_unittest.cc \
    thread_checker_unittest.cc \
    thread_collision_warner_unittest.cc \
    thread_id_name_manager_unittest.cc \
    thread_local_storage_unittest.cc \
    thread_local_unittest.cc \
    watchdog_unittest.cc \
    time_unittest.cc \
    version_unittest.cc \
    logging_unittest.cc \
    cacheline_unittest.cpp \
    class_name_unittest.cpp \
    endpoint_unittest.cpp \
    unique_ptr_unittest.cpp \
    errno_unittest.cpp \
    fd_guard_unittest.cpp \
    file_watcher_unittest.cpp \
    find_cstr_unittest.cpp \
    scoped_lock_unittest.cpp \
    status_unittest.cpp \
    string_printf_unittest.cpp \
    string_splitter_unittest.cpp \
    synchronous_event_unittest.cpp \
    temp_file_unittest.cpp \
    baidu_thread_local_unittest.cpp \
    baidu_time_unittest.cpp \
    flat_map_unittest.cpp \
    crc32c_unittest.cc \
136
    iobuf_unittest.cpp \
137
    object_pool_unittest.cpp \
138
    recordio_unittest.cpp \
139 140
    test_switches.cc \
    scoped_locale.cc \
141
    popen_unittest.cpp \
jamesge's avatar
jamesge committed
142
    bounded_queue_unittest.cc \
143
    butil_unittest_main.cpp
144

gejun's avatar
gejun committed
145 146 147 148
ifeq ($(SYSTEM), Linux)
    TEST_BUTIL_SOURCES += test_file_util_linux.cc \
						  proc_maps_linux_unittest.cc
endif
zhujiashun's avatar
zhujiashun committed
149

150 151 152 153 154 155 156 157
# bthread_* functions are used in logging.cc, and they need to be marked as
# weak symbols explicitly in Darwin system.
ifeq ($(SYSTEM), Darwin)
	DYNAMIC_LINKINGS+=-Wl,-U,_bthread_getspecific
	DYNAMIC_LINKINGS+=-Wl,-U,_bthread_setspecific
	DYNAMIC_LINKINGS+=-Wl,-U,_bthread_key_create
endif

158 159
UT_DYNAMIC_LINKINGS = $(DYNAMIC_LINKINGS) -lbrpc.dbg

160
TEST_BUTIL_OBJS = iobuf.pb.o $(addsuffix .o, $(basename $(TEST_BUTIL_SOURCES))) 
161 162 163 164 165

TEST_BVAR_SOURCES = $(wildcard bvar_*_unittest.cpp)
TEST_BVAR_OBJS = $(addsuffix .o, $(basename $(TEST_BVAR_SOURCES))) 

TEST_BTHREAD_SOURCES = $(wildcard bthread_*unittest.cpp)
166
TEST_BTHREAD_OBJS = $(addsuffix .o, $(basename $(TEST_BTHREAD_SOURCES))) 
167 168

TEST_BRPC_SOURCES = $(wildcard brpc_*unittest.cpp)
169
TEST_BRPC_OBJS = $(addsuffix .o, $(basename $(TEST_BRPC_SOURCES))) 
170 171

TEST_PROTO_SOURCES = $(wildcard *.proto)
172
TEST_PROTO_OBJS = $(TEST_PROTO_SOURCES:.proto=.pb.o)
173

174
TEST_BINS = test_butil test_bvar $(TEST_BTHREAD_SOURCES:.cpp=) $(TEST_BRPC_SOURCES:.cpp=)
175 176 177 178 179

.PHONY:all
all: $(TEST_BINS)

.PHONY:clean
180
clean:clean_bins
181 182 183
	@echo "> Cleaning"
	rm -rf $(TEST_BUTIL_OBJS) $(TEST_BVAR_OBJS) $(TEST_BTHREAD_OBJS) $(TEST_BRPC_OBJS) $(TEST_PROTO_OBJS) $(TEST_PROTO_SOURCES:.proto=.pb.h) $(TEST_PROTO_SOURCES:.proto=.pb.cc)
	$(MAKE) -C.. clean_debug
184 185 186

.PHONY:clean_bins
clean_bins:
187
	rm -rf $(TEST_BINS)
188

189
libbrpc.dbg.$(SOEXT):FORCE
190
	$(MAKE) -C.. test/libbrpc.dbg.$(SOEXT)
191 192

libbvar.dbg.a:FORCE
193
	$(MAKE) -C.. test/libbvar.dbg.a
194

195 196 197 198
FORCE:

.PRECIOUS: %.o

199
test_butil:$(TEST_BUTIL_OBJS) | libbrpc.dbg.$(SOEXT)
200
	@echo "> Linking $@"
201
ifeq ($(SYSTEM),Linux)
202
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
203
else ifeq ($(SYSTEM),Darwin)
204
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
205
endif
206

207
test_bvar:libbvar.dbg.a $(TEST_BVAR_OBJS)
208
	@echo "> Linking $@"
209
ifeq ($(SYSTEM),Linux)
210
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS)
211
else ifeq ($(SYSTEM),Darwin)
212
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
213
endif
214

215
bthread%unittest:bthread%unittest.o | libbrpc.dbg.$(SOEXT)
216
	@echo "> Linking $@"
217
ifeq ($(SYSTEM),Linux)
218
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
219
else ifeq ($(SYSTEM),Darwin)
220
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
221
endif
222

223
brpc_%_unittest:$(TEST_PROTO_OBJS) brpc_%_unittest.o | libbrpc.dbg.$(SOEXT)
224
	@echo "> Linking $@"
225
ifeq ($(SYSTEM),Linux)
226
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
227
else ifeq ($(SYSTEM),Darwin)
228
	$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
229
endif
230

231
%.pb.cc %.pb.h:%.proto
232 233
	@echo "> Generating $@"
	$(PROTOC) --cpp_out=. --proto_path=. --proto_path=../src --proto_path=$(PROTOBUF_HDR) $<
234

235
baidu_time_unittest.o:baidu_time_unittest.cpp | libbrpc.dbg.$(SOEXT)
236 237
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@
238

239
brpc_h2_unsent_message_unittest.o:brpc_h2_unsent_message_unittest.cpp | libbrpc.dbg.$(SOEXT)
240 241
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@
242

243
%.o:%.cpp | libbrpc.dbg.$(SOEXT)
244 245
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
246

247
%.o:%.cc | libbrpc.dbg.$(SOEXT)
248 249
	@echo "> Compiling $@"
	$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
250