Commit 255a653c authored by gejun's avatar gejun

Link shared libbrpc in UTs built by the Makefile

parent 25812b9b
...@@ -17,9 +17,9 @@ COMMA = , ...@@ -17,9 +17,9 @@ COMMA = ,
SOPATHS = $(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS)) SOPATHS = $(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS))
SRCEXTS = .c .cc .cpp .proto SRCEXTS = .c .cc .cpp .proto
TARGET_LIB_DY = libbrpc.so SOEXT = so
ifeq ($(SYSTEM),Darwin) ifeq ($(SYSTEM),Darwin)
TARGET_LIB_DY = libbrpc.dylib SOEXT = dylib
endif endif
#required by butil/crc32.cc to boost performance for 10x #required by butil/crc32.cc to boost performance for 10x
...@@ -205,19 +205,19 @@ DEBUG_OBJS = $(OBJS:.o=.dbg.o) ...@@ -205,19 +205,19 @@ DEBUG_OBJS = $(OBJS:.o=.dbg.o)
PROTOS=$(BRPC_PROTOS) src/idl_options.proto PROTOS=$(BRPC_PROTOS) src/idl_options.proto
.PHONY:all .PHONY:all
all: protoc-gen-mcpack libbrpc.a $(TARGET_LIB_DY) output/include output/lib output/bin all: protoc-gen-mcpack libbrpc.a libbrpc.$(SOEXT) output/include output/lib output/bin
.PHONY:debug .PHONY:debug
debug: test/libbrpc.dbg.a test/libbvar.dbg.a debug: test/libbrpc.dbg.$(SOEXT) test/libbvar.dbg.a
.PHONY:clean .PHONY:clean
clean: clean:
@echo "Cleaning" @echo "Cleaning"
@rm -rf src/mcpack2pb/generator.o protoc-gen-mcpack libbrpc.a $(TARGET_LIB_DY) $(OBJS) output/include output/lib output/bin $(PROTOS:.proto=.pb.h) $(PROTOS:.proto=.pb.cc) @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)
.PHONY:clean_debug .PHONY:clean_debug
clean_debug: clean_debug:
@rm -rf test/libbrpc.dbg.a test/libbvar.dbg.a $(DEBUG_OBJS) @rm -rf test/libbrpc.dbg.$(SOEXT) test/libbvar.dbg.a $(DEBUG_OBJS)
.PRECIOUS: %.o .PRECIOUS: %.o
...@@ -234,7 +234,7 @@ libbrpc.a:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS) ...@@ -234,7 +234,7 @@ libbrpc.a:$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
@echo "Packing $@" @echo "Packing $@"
@ar crs $@ $(filter %.o,$^) @ar crs $@ $(filter %.o,$^)
$(TARGET_LIB_DY):$(BRPC_PROTOS:.proto=.pb.h) $(OBJS) libbrpc.$(SOEXT):$(BRPC_PROTOS:.proto=.pb.h) $(OBJS)
@echo "Linking $@" @echo "Linking $@"
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
@$(CXX) -shared -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(filter %.o,$^) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) @$(CXX) -shared -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(filter %.o,$^) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
...@@ -246,9 +246,13 @@ test/libbvar.dbg.a:$(BVAR_DEBUG_OBJS) ...@@ -246,9 +246,13 @@ test/libbvar.dbg.a:$(BVAR_DEBUG_OBJS)
@echo "Packing $@" @echo "Packing $@"
@ar crs $@ $^ @ar crs $@ $^
test/libbrpc.dbg.a:$(BRPC_PROTOS:.proto=.pb.h) $(DEBUG_OBJS) test/libbrpc.dbg.$(SOEXT):$(BRPC_PROTOS:.proto=.pb.h) $(DEBUG_OBJS)
@echo "Packing $@" @echo "Linking $@"
@ar crs $@ $(filter %.o,$^) ifeq ($(SYSTEM),Linux)
@$(CXX) -shared -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $(filter %.o,$^) -Xlinker "-)" $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
else ifeq ($(SYSTEM),Darwin)
@$(CXX) -dynamiclib -Wl,-headerpad_max_install_names -o $@ -install_name @rpath/$@ $(LIBPATHS) $(SOPATHS) $(filter %.o,$^) $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
endif
.PHONY:output/include .PHONY:output/include
output/include: output/include:
...@@ -258,7 +262,7 @@ output/include: ...@@ -258,7 +262,7 @@ output/include:
@cp src/idl_options.proto src/idl_options.pb.h $@ @cp src/idl_options.proto src/idl_options.pb.h $@
.PHONY:output/lib .PHONY:output/lib
output/lib:libbrpc.a $(TARGET_LIB_DY) output/lib:libbrpc.a libbrpc.$(SOEXT)
@echo "Copying to $@" @echo "Copying to $@"
@mkdir -p $@ @mkdir -p $@
@cp $^ $@ @cp $^ $@
......
...@@ -15,9 +15,18 @@ ifeq ($(CC),gcc) ...@@ -15,9 +15,18 @@ ifeq ($(CC),gcc)
endif endif
endif endif
LIBS += .
HDRPATHS=-I. -I../src $(addprefix -I, $(HDRS)) HDRPATHS=-I. -I../src $(addprefix -I, $(HDRS))
LIBPATHS=$(addprefix -L, $(LIBS)) LIBPATHS=$(addprefix -L, $(LIBS))
COMMA = ,
SOPATHS = $(addprefix -Wl$(COMMA)-rpath$(COMMA), $(LIBS))
SOEXT = so
ifeq ($(SYSTEM),Darwin)
SOEXT = dylib
endif
TEST_BUTIL_SOURCES = \ TEST_BUTIL_SOURCES = \
at_exit_unittest.cc \ at_exit_unittest.cc \
atomicops_unittest.cc \ atomicops_unittest.cc \
...@@ -129,6 +138,8 @@ ifeq ($(SYSTEM), Darwin) ...@@ -129,6 +138,8 @@ ifeq ($(SYSTEM), Darwin)
DYNAMIC_LINKINGS+=-Wl,-U,_bthread_key_create DYNAMIC_LINKINGS+=-Wl,-U,_bthread_key_create
endif endif
UT_DYNAMIC_LINKINGS = $(DYNAMIC_LINKINGS) -lbrpc.dbg
TEST_BUTIL_OBJS = iobuf.pb.o $(addsuffix .o, $(basename $(TEST_BUTIL_SOURCES))) TEST_BUTIL_OBJS = iobuf.pb.o $(addsuffix .o, $(basename $(TEST_BUTIL_SOURCES)))
TEST_BVAR_SOURCES = $(wildcard bvar_*_unittest.cpp) TEST_BVAR_SOURCES = $(wildcard bvar_*_unittest.cpp)
...@@ -158,62 +169,65 @@ clean:clean_bins ...@@ -158,62 +169,65 @@ clean:clean_bins
clean_bins: clean_bins:
@rm -rf $(TEST_BINS) @rm -rf $(TEST_BINS)
libbrpc.dbg.a:FORCE libbrpc.dbg.$(SOEXT):FORCE
@$(MAKE) -C.. debug @$(MAKE) -C.. test/libbrpc.dbg.$(SOEXT)
libbvar.dbg.a:FORCE
@$(MAKE) -C.. test/libbvar.dbg.a
FORCE: FORCE:
.PRECIOUS: %.o .PRECIOUS: %.o
test_butil:libbrpc.dbg.a $(TEST_BUTIL_OBJS) test_butil:$(TEST_BUTIL_OBJS) | libbrpc.dbg.$(SOEXT)
@echo "Linking $@" @echo "Linking $@"
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
@$(CXX) -o $@ $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(UT_DYNAMIC_LINKINGS)
else ifeq ($(SYSTEM),Darwin) else ifeq ($(SYSTEM),Darwin)
@$(CXX) -o $@ $(LIBPATHS) $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
endif endif
test_bvar:libbrpc.dbg.a $(TEST_BVAR_OBJS) test_bvar:libbvar.dbg.a $(TEST_BVAR_OBJS)
@echo "Linking $@" @echo "Linking $@"
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
@$(CXX) -o $@ $(LIBPATHS) -Xlinker "-(" $(TEST_BVAR_OBJS) libbvar.dbg.a -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS)
else ifeq ($(SYSTEM),Darwin) else ifeq ($(SYSTEM),Darwin)
@$(CXX) -o $@ $(LIBPATHS) $(TEST_BVAR_OBJS) libbvar.dbg.a $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS)
endif endif
bthread%unittest:libbrpc.dbg.a bthread%unittest.o bthread%unittest:bthread%unittest.o | libbrpc.dbg.$(SOEXT)
@echo "Linking $@" @echo "Linking $@"
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
@$(CXX) -o $@ $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(UT_DYNAMIC_LINKINGS)
else ifeq ($(SYSTEM),Darwin) else ifeq ($(SYSTEM),Darwin)
@$(CXX) -o $@ $(LIBPATHS) $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
endif endif
brpc_%_unittest:libbrpc.dbg.a $(TEST_PROTO_OBJS) brpc_%_unittest.o brpc_%_unittest:$(TEST_PROTO_OBJS) brpc_%_unittest.o | libbrpc.dbg.$(SOEXT)
@echo "Linking $@" @echo "Linking $@"
ifeq ($(SYSTEM),Linux) ifeq ($(SYSTEM),Linux)
@$(CXX) -o $@ $(LIBPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Wl,-Bstatic $(STATIC_LINKINGS) -Wl,-Bdynamic -Xlinker "-)" $(UT_DYNAMIC_LINKINGS)
else ifeq ($(SYSTEM),Darwin) else ifeq ($(SYSTEM),Darwin)
@$(CXX) -o $@ $(LIBPATHS) $^ $(STATIC_LINKINGS) $(DYNAMIC_LINKINGS) @$(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS)
endif endif
%.pb.cc %.pb.h:%.proto %.pb.cc %.pb.h:%.proto
@echo "Generating $@" @echo "Generating $@"
@$(PROTOC) --cpp_out=. --proto_path=. --proto_path=../src --proto_path=$(PROTOBUF_HDR) $< @$(PROTOC) --cpp_out=. --proto_path=. --proto_path=../src --proto_path=$(PROTOBUF_HDR) $<
baidu_time_unittest.o:baidu_time_unittest.cpp | libbrpc.dbg.a baidu_time_unittest.o:baidu_time_unittest.cpp | libbrpc.dbg.$(SOEXT)
@echo "Compiling $@" @echo "Compiling $@"
@$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@ @$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@
brpc_h2_unsent_message_unittest.o:brpc_h2_unsent_message_unittest.cpp | libbrpc.dbg.a brpc_h2_unsent_message_unittest.o:brpc_h2_unsent_message_unittest.cpp | libbrpc.dbg.$(SOEXT)
@echo "Compiling $@" @echo "Compiling $@"
@$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@ @$(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@
%.o:%.cpp | libbrpc.dbg.a %.o:%.cpp | libbrpc.dbg.$(SOEXT)
@echo "Compiling $@" @echo "Compiling $@"
@$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ @$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
%.o:%.cc | libbrpc.dbg.a %.o:%.cc | libbrpc.dbg.$(SOEXT)
@echo "Compiling $@" @echo "Compiling $@"
@$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ @$(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment