Separate compile and link for shared library

Summary:
Previously, the shared library (make shared_lib) was built with only one
compile line, compiling all .cc files and linking the shared library in
one step. That step would often take 10+ minutes on one machine, and
could not take advantage of multiple CPUs (it's only one invocation of
the compiler).

This commit changes the shared_lib build to compile .o files
individually (placing the resulting .o files in the directory
shared-objects) and then link them into the shared library at the end,
similarly to how the java static build (jls) does it.

Tested by making sure that both static and shared libraries work, and by
making sure that "make clean" cleans up the shared-objects directory.
Closes https://github.com/facebook/rocksdb/pull/2165

Differential Revision: D4897121

Pulled By: yiwu-arbug

fbshipit-source-id: 9811e043d1c01e10503593f3489d186c786ee7d7
This commit is contained in:
Tudor Bosman 2017-04-16 10:37:07 -07:00 committed by Facebook Github Bot
parent 0716527341
commit 7d5f5aa977
1 changed files with 8 additions and 3 deletions

View File

@ -523,9 +523,14 @@ $(SHARED3): $(SHARED4)
ln -fs $(SHARED4) $(SHARED3)
endif
$(SHARED4):
$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(LIB_SOURCES) $(TOOL_LIB_SOURCES) \
$(LDFLAGS) -o $@
shared_libobjects = $(patsubst %,shared-objects/%,$(LIBOBJECTS))
CLEAN_FILES += shared-objects
$(shared_libobjects): shared-objects/%.o: %.cc
$(AM_V_CC)mkdir -p $(@D) && $(CXX) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) -c $< -o $@
$(SHARED4): $(shared_libobjects)
$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(shared_libobjects) $(LDFLAGS) -o $@
endif # PLATFORM_SHARED_EXT