automatically detect configuration changes
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
This commit is contained in:
parent
8a453a34c5
commit
d0436b2a45
56
lib/Makefile
56
lib/Makefile
@ -54,17 +54,18 @@ else
|
|||||||
CFLAGS += -O3
|
CFLAGS += -O3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_
|
DEBUGLEVEL ?= 0
|
||||||
|
CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
|
||||||
ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
|
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
|
endif
|
||||||
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
|
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
|
||||||
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
|
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
|
||||||
-Wstrict-prototypes -Wundef -Wpointer-arith \
|
-Wstrict-prototypes -Wundef -Wpointer-arith \
|
||||||
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
|
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
|
||||||
-Wredundant-decls -Wmissing-prototypes -Wc++-compat
|
-Wredundant-decls -Wmissing-prototypes -Wc++-compat
|
||||||
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
|
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
|
||||||
FLAGS = $(CPPFLAGS) $(CFLAGS)
|
FLAGS = $(CPPFLAGS) $(CFLAGS)
|
||||||
|
|
||||||
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
|
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
|
||||||
GREP_OPTIONS ?=
|
GREP_OPTIONS ?=
|
||||||
@ -170,7 +171,29 @@ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
|
|||||||
ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
|
ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
|
||||||
vpath %.c $(ZSTD_SUBDIR)
|
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_DIR := $(BUILD_DIR)/dynlib
|
||||||
ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/, $(ZSTD_LOCAL_OBJ))
|
ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/, $(ZSTD_LOCAL_OBJ))
|
||||||
ZSTD_STATLIB_DIR := $(BUILD_DIR)/statlib
|
ZSTD_STATLIB_DIR := $(BUILD_DIR)/statlib
|
||||||
@ -200,24 +223,28 @@ lib-all: all
|
|||||||
|
|
||||||
all: lib
|
all: lib
|
||||||
|
|
||||||
libzstd.a: ARFLAGS = rcs
|
$(ZSTD_STATLIB_DIR)/libzstd.a: ARFLAGS = rcs
|
||||||
libzstd.a: $(ZSTD_STATLIB_OBJ)
|
$(ZSTD_STATLIB_DIR)/libzstd.a: $(ZSTD_STATLIB_OBJ)
|
||||||
@echo compiling static library
|
@echo compiling static library
|
||||||
$(Q)$(AR) $(ARFLAGS) $@ $^
|
$(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)))
|
ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
|
||||||
|
|
||||||
LIBZSTD = dll\libzstd.dll
|
LIBZSTD = dll\libzstd.dll
|
||||||
$(LIBZSTD): $(ZSTD_FILES)
|
$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): $(ZSTD_FILES)
|
||||||
@echo compiling dynamic library $(LIBVER)
|
@echo compiling dynamic library $(LIBVER)
|
||||||
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
|
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
||||||
$(LIBZSTD): CFLAGS += -fPIC
|
$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): CFLAGS += -fPIC
|
||||||
$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
|
$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): LDFLAGS += -shared -fvisibility=hidden
|
||||||
$(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
|
$(ZSTD_DYNLIB_DIR)/$(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
|
||||||
@echo compiling dynamic library $(LIBVER)
|
@echo compiling dynamic library $(LIBVER)
|
||||||
$(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
$(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
||||||
@echo creating versioned links
|
@echo creating versioned links
|
||||||
@ -226,6 +253,10 @@ $(LIBZSTD): $(ZSTD_DYNLIB_OBJ)
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
.PHONY: $(LIBZSTD) # must be run every time
|
||||||
|
$(LIBZSTD): $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
|
||||||
|
$(Q)ln -sf $< $@
|
||||||
|
|
||||||
.PHONY: libzstd
|
.PHONY: libzstd
|
||||||
libzstd : $(LIBZSTD)
|
libzstd : $(LIBZSTD)
|
||||||
|
|
||||||
@ -281,8 +312,7 @@ clean:
|
|||||||
$(Q)$(RM) -r *.dSYM # macOS-specific
|
$(Q)$(RM) -r *.dSYM # macOS-specific
|
||||||
$(Q)$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
|
$(Q)$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
|
||||||
$(Q)$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
|
$(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 obj/*
|
||||||
$(Q)$(RM) -r $(ZSTD_STATLIB_DIR)/* $(ZSTD_DYNLIB_DIR)/*
|
|
||||||
@echo Cleaning library completed
|
@echo Cleaning library completed
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user