From 7d5f5aa977d622e5b0e81d095a9e50648b27b25a Mon Sep 17 00:00:00 2001 From: Tudor Bosman Date: Sun, 16 Apr 2017 10:37:07 -0700 Subject: [PATCH] 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 --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f4615bec2..7f95e0b11 100644 --- a/Makefile +++ b/Makefile @@ -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