]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
automatically detect configuration changes
authorYann Collet <yann.collet.73@gmail.com>
Thu, 22 Oct 2020 02:22:45 +0000 (19:22 -0700)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 22 Oct 2020 02:22:45 +0000 (19:22 -0700)
Makefile now automatically detects modifications of compilation flags,
and produce object files in directories dedicated to this compilation flags.
This makes it possible, for example, to compile libzstd with different DEBUGLEVEL.
Object files sharing the same configration will be generated into their dedicated directories.

Also : new compilation variables
- DEBUGLEVEL : select the debug level (assert & traces) inserted during compilation (default == 0 == release)
- HASH : select a hash function to differentiate configuration (default == md5sum)
- BUILD_DIR : skip the hash stage, store object files into manually specified directory

lib/Makefile

index 58e80e473760e1e1c2eebfaa8d7f771ea501b113..1911bc64fe20778b6882ebb152791e43c12b1f94 100644 (file)
@@ -54,17 +54,18 @@ else
   CFLAGS += -O3
 endif
 
-CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_
+DEBUGLEVEL ?= 0
+CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
 ifeq ($(TARGET_SYSTEM),Windows_NT)   # MinGW assumed
-  CPPFLAGS   += -D__USE_MINGW_ANSI_STDIO   # compatibility with %zu formatting
+  CPPFLAGS += -D__USE_MINGW_ANSI_STDIO   # compatibility with %zu formatting
 endif
 DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
             -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
             -Wstrict-prototypes -Wundef -Wpointer-arith \
             -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
             -Wredundant-decls -Wmissing-prototypes -Wc++-compat
-CFLAGS  += $(DEBUGFLAGS) $(MOREFLAGS)
-FLAGS    = $(CPPFLAGS) $(CFLAGS)
+CFLAGS   += $(DEBUGFLAGS) $(MOREFLAGS)
+FLAGS     = $(CPPFLAGS) $(CFLAGS)
 
 HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
 GREP_OPTIONS ?=
@@ -170,7 +171,29 @@ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
 ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
 vpath %.c $(ZSTD_SUBDIR)
 
-BUILD_DIR ?= obj
+UNAME := $(shell uname)
+ifeq ($(UNAME), Darwin)
+  HASH ?= md5
+endif
+ifeq ($(UNAME), FreeBSD)
+  HASH ?= gmd5sum
+endif
+ifeq ($(UNAME), OpenBSD)
+  HASH ?= md5
+endif
+HASH ?= md5sum
+
+HAVE_HASH := $(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
+ifeq ($(HAVE_HASH), 1)
+  HASH_VALUE := $(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) | $(HASH) | head -c 16)
+  HASH_DIR := conf_$(HASH_VALUE)
+else
+  $(info warning : could not find hash function to differentiate builds with different flags)
+  HASH_DIR := 0
+endif
+
+
+BUILD_DIR ?= obj/$(HASH_DIR)
 ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynlib
 ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/, $(ZSTD_LOCAL_OBJ))
 ZSTD_STATLIB_DIR := $(BUILD_DIR)/statlib
@@ -200,24 +223,28 @@ lib-all: all
 
 all: lib
 
-libzstd.a: ARFLAGS = rcs
-libzstd.a: $(ZSTD_STATLIB_OBJ)
+$(ZSTD_STATLIB_DIR)/libzstd.a: ARFLAGS = rcs
+$(ZSTD_STATLIB_DIR)/libzstd.a: $(ZSTD_STATLIB_OBJ)
        @echo compiling static library
        $(Q)$(AR) $(ARFLAGS) $@ $^
 
+.PHONY: libzstd.a  # must be run every time
+libzstd.a: $(ZSTD_STATLIB_DIR)/libzstd.a
+       $(Q)ln -sf $< $@
+
 ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
 
 LIBZSTD = dll\libzstd.dll
-$(LIBZSTD): $(ZSTD_FILES)
+$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): $(ZSTD_FILES)
        @echo compiling dynamic library $(LIBVER)
        $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
 
 else
 
 LIBZSTD = libzstd.$(SHARED_EXT_VER)
-$(LIBZSTD): CFLAGS += -fPIC
-$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
-$(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
+$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): CFLAGS += -fPIC
+$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
+$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
        @echo compiling dynamic library $(LIBVER)
        $(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
        @echo creating versioned links
@@ -226,6 +253,10 @@ $(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
 
 endif
 
+.PHONY: $(LIBZSTD)  # must be run every time
+$(LIBZSTD): $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
+       $(Q)ln -sf $< $@
+
 .PHONY: libzstd
 libzstd : $(LIBZSTD)
 
@@ -281,8 +312,7 @@ clean:
        $(Q)$(RM) -r *.dSYM   # macOS-specific
        $(Q)$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
        $(Q)$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
-       $(Q)$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
-       $(Q)$(RM) -r $(ZSTD_STATLIB_DIR)/* $(ZSTD_DYNLIB_DIR)/*
+       $(Q)$(RM) -r obj/*
        @echo Cleaning library completed
 
 #-----------------------------------------------------------------------------