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
main
Tudor Bosman 8 years ago committed by Facebook Github Bot
parent 0716527341
commit 7d5f5aa977
  1. 11
      Makefile

@ -523,9 +523,14 @@ $(SHARED3): $(SHARED4)
ln -fs $(SHARED4) $(SHARED3) ln -fs $(SHARED4) $(SHARED3)
endif endif
$(SHARED4): shared_libobjects = $(patsubst %,shared-objects/%,$(LIBOBJECTS))
$(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED3) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(LIB_SOURCES) $(TOOL_LIB_SOURCES) \ CLEAN_FILES += shared-objects
$(LDFLAGS) -o $@
$(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 endif # PLATFORM_SHARED_EXT

Loading…
Cancel
Save