From 911dbdbb4b1374fcc4c2c8a6199bb15ecb69b24a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 20 Oct 2020 22:19:57 -0700 Subject: [PATCH] build libzstd.so from object files %.o object files generated for dynamic library must be different from those generated for static library. Due to this difference, %.o were so far only generated for the static library. The dynamic library was rebuilt from %.c source. This meant that, for every minor change, the entire dynamic library had to be rebuilt. This is fixed in this PR : only the modified %.c source get rebuilt. --- lib/Makefile | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index aba0c99b..be6fe1d2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -82,7 +82,7 @@ ZDEPR_FILES := $(sort $(wildcard deprecated/*.c)) ZSTD_FILES := $(ZSTDCOMMON_FILES) ifeq ($(findstring GCC,$(CCVER)),GCC) -decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize +decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize endif # Modules @@ -164,20 +164,29 @@ endif endif CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) -ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES)) +ZSTD_OBJ := $(ZSTD_FILES:.c=.o) + +vpath %.c ./common +vpath %.c ./compress +vpath %.c ./decompress +vpath %.c ./dictBuilder +vpath %.c ./legacy +vpath %.c ./deprecated + +ZSTD_DYNLIB_OBJ := $(notdir $(ZSTD_OBJ)) # macOS linker doesn't support -soname, and use different extension # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html ifeq ($(shell uname), Darwin) - SHARED_EXT = dylib - SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) - SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) - SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) + SHARED_EXT = dylib + SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) + SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) + SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) else - SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR) - SHARED_EXT = so - SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) - SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) + SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR) + SHARED_EXT = so + SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) + SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) endif @@ -205,8 +214,9 @@ $(LIBZSTD): $(ZSTD_FILES) else LIBZSTD = libzstd.$(SHARED_EXT_VER) -$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden -$(LIBZSTD): $(ZSTD_FILES) +$(LIBZSTD): CFLAGS += -fPIC +$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden +$(LIBZSTD): $(ZSTD_DYNLIB_OBJ) @echo compiling dynamic library $(LIBVER) $(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ @echo creating versioned links