88# You may select, at your option, one of the above-listed licenses.
99# ################################################################
1010
11- # Note: by default, the static library is built single-threaded and dynamic library is built
12- # multi-threaded. It is possible to force multi or single threaded builds by appending
13- # -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
14- .PHONY : default
15- default : lib-release
16-
17- # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
18- $(V )$(VERBOSE ) .SILENT :
19-
20- # When cross-compiling from linux to windows,
21- # one might need to specify TARGET_SYSTEM as "Windows."
22- # Building from Fedora fails without it.
23- # (but Ubuntu and Debian don't need to set anything)
24- TARGET_SYSTEM ?= $(OS )
25-
26- # Version numbers
27- LIBVER_MAJOR_SCRIPT: =` sed -n ' /define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h `
28- LIBVER_MINOR_SCRIPT: =` sed -n ' /define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h `
29- LIBVER_PATCH_SCRIPT: =` sed -n ' /define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h `
30- LIBVER_SCRIPT: = $(LIBVER_MAJOR_SCRIPT ) .$(LIBVER_MINOR_SCRIPT ) .$(LIBVER_PATCH_SCRIPT )
31- LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT ) )
32- LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT ) )
33- LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT ) )
34- LIBVER := $(shell echo $(LIBVER_SCRIPT ) )
35- VERSION? = $(LIBVER )
36- CCVER := $(shell $(CC ) --version)
37-
38- # ZSTD_LIB_MINIFY is a helper variable that
39- # configures a bunch of other variables to space-optimized defaults.
40- ZSTD_LIB_MINIFY ?= 0
41- ifneq ($(ZSTD_LIB_MINIFY ) , 0)
42- HAVE_CC_OZ ?= $(shell echo "" | $(CC ) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
43- ZSTD_LEGACY_SUPPORT ?= 0
44- ZSTD_LIB_DEPRECATED ?= 0
45- HUF_FORCE_DECOMPRESS_X1 ?= 1
46- ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 1
47- ZSTD_NO_INLINE ?= 1
48- ZSTD_STRIP_ERROR_STRINGS ?= 1
49- ifneq ($(HAVE_CC_OZ ) , 0)
50- # Some compilers (clang) support an even more space-optimized setting.
51- CFLAGS += -Oz
52- else
53- CFLAGS += -Os
54- endif
55- CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
56- -DDYNAMIC_BMI2=0 -DNDEBUG
57- else
58- CFLAGS += -O3
59- endif
60-
61- DEBUGLEVEL ?= 0
62- CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL )
63- ifeq ($(TARGET_SYSTEM ) ,Windows_NT) # MinGW assumed
64- CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
65- endif
66- DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
67- -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
68- -Wstrict-prototypes -Wundef -Wpointer-arith \
69- -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
70- -Wredundant-decls -Wmissing-prototypes -Wc++-compat
71- CFLAGS += $(DEBUGFLAGS ) $(MOREFLAGS )
72- FLAGS = $(CPPFLAGS ) $(CFLAGS )
73-
74- CPPFLAGS_DYNLIB = -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
75- LDFLAGS_DYNLIB = -pthread
76- CPPFLAGS_STATLIB = # static library build defaults to single-threaded
77-
78- HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
79- GREP_OPTIONS ?=
80- ifeq ($HAVE_COLORNEVER, 1)
81- GREP_OPTIONS += --color=never
82- endif
83- GREP = grep $(GREP_OPTIONS )
84- SED_ERE_OPT ?= -E
85-
86- ZSTDCOMMON_FILES := $(sort $(wildcard common/* .c) )
87- ZSTDCOMP_FILES := $(sort $(wildcard compress/* .c) )
88- ZSTDDECOMP_FILES := $(sort $(wildcard decompress/* .c) )
89- ZDICT_FILES := $(sort $(wildcard dictBuilder/* .c) )
90- ZDEPR_FILES := $(sort $(wildcard deprecated/* .c) )
91- ZSTD_FILES := $(ZSTDCOMMON_FILES )
92-
93- ifeq ($(findstring GCC,$(CCVER ) ) ,GCC)
94- decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
95- endif
96-
9711# Modules
9812ZSTD_LIB_COMPRESSION ?= 1
9913ZSTD_LIB_DECOMPRESSION ?= 1
10014ZSTD_LIB_DICTBUILDER ?= 1
10115ZSTD_LIB_DEPRECATED ?= 0
10216
103- # Legacy support
104- ZSTD_LEGACY_SUPPORT ?= 5
105- ZSTD_LEGACY_MULTITHREADED_API ?= 0
106-
107- # Build size optimizations
108- HUF_FORCE_DECOMPRESS_X1 ?= 0
109- HUF_FORCE_DECOMPRESS_X2 ?= 0
110- ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ?= 0
111- ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ?= 0
112- ZSTD_NO_INLINE ?= 0
113- ZSTD_STRIP_ERROR_STRINGS ?= 0
114-
17+ # Input variables for libzstd.mk
11518ifeq ($(ZSTD_LIB_COMPRESSION ) , 0)
11619 ZSTD_LIB_DICTBUILDER = 0
11720 ZSTD_LIB_DEPRECATED = 0
@@ -122,86 +25,46 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
12225 ZSTD_LIB_DEPRECATED = 0
12326endif
12427
28+ include libzstd.mk
29+
30+ ZSTD_FILES := $(ZSTD_COMMON_FILES ) $(ZSTD_LEGACY_FILES )
31+
12532ifneq ($(ZSTD_LIB_COMPRESSION ) , 0)
126- ZSTD_FILES += $(ZSTDCOMP_FILES )
33+ ZSTD_FILES += $(ZSTD_COMPRESS_FILES )
12734endif
12835
12936ifneq ($(ZSTD_LIB_DECOMPRESSION ) , 0)
130- ZSTD_FILES += $(ZSTDDECOMP_FILES )
37+ ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES )
13138endif
13239
13340ifneq ($(ZSTD_LIB_DEPRECATED ) , 0)
134- ZSTD_FILES += $(ZDEPR_FILES )
41+ ZSTD_FILES += $(ZSTD_DEPRECATED_FILES )
13542endif
13643
13744ifneq ($(ZSTD_LIB_DICTBUILDER ) , 0)
138- ZSTD_FILES += $(ZDICT_FILES )
139- endif
140-
141- ifneq ($(HUF_FORCE_DECOMPRESS_X1 ) , 0)
142- CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
143- endif
144-
145- ifneq ($(HUF_FORCE_DECOMPRESS_X2 ) , 0)
146- CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
147- endif
148-
149- ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT ) , 0)
150- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT
151- endif
152-
153- ifneq ($(ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG ) , 0)
154- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG
155- endif
156-
157- ifneq ($(ZSTD_NO_INLINE ) , 0)
158- CFLAGS += -DZSTD_NO_INLINE
45+ ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES )
15946endif
16047
161- ifneq ($(ZSTD_STRIP_ERROR_STRINGS ) , 0)
162- CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
163- endif
164-
165- ifneq ($(ZSTD_LEGACY_MULTITHREADED_API ) , 0)
166- CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
167- endif
168-
169- ifneq ($(ZSTD_LEGACY_SUPPORT ) , 0)
170- ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT ) -lt 8; echo $$? ) , 0)
171- ZSTD_FILES += $(shell ls legacy/* .c | $(GREP ) 'v0[$(ZSTD_LEGACY_SUPPORT ) -7]')
172- endif
173- endif
174- CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT )
175-
17648ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES ) )
177- ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o )
49+ ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o )
50+ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o )
17851
179- ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
180- vpath % .c $(ZSTD_SUBDIR )
52+ VERSION := $(ZSTD_VERSION )
18153
182- UNAME := $(shell uname)
54+ # Note: by default, the static library is built single-threaded and dynamic library is built
55+ # multi-threaded. It is possible to force multi or single threaded builds by appending
56+ # -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
57+ .PHONY : default
58+ default : lib-release
59+
60+ CPPFLAGS_DYNLIB = -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
61+ LDFLAGS_DYNLIB = -pthread
62+ CPPFLAGS_STATLIB = # static library build defaults to single-threaded
18363
184- ifndef BUILD_DIR
185- ifeq ($(UNAME ) , Darwin)
186- ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
187- HASH ?= md5
188- endif
189- else ifeq ($(UNAME), FreeBSD)
190- HASH ?= gmd5sum
191- else ifeq ($(UNAME), NetBSD)
192- HASH ?= md5 -n
193- else ifeq ($(UNAME), OpenBSD)
194- HASH ?= md5
195- endif
196- HASH ?= md5sum
19764
198- HASH_DIR = conf_$(shell echo $(CC ) $(CPPFLAGS ) $(CFLAGS ) $(LDFLAGS ) $(ZSTD_FILES ) | $(HASH ) | cut -f 1 -d " " )
199- HAVE_HASH :=$(shell echo 1 | $(HASH ) > /dev/null && echo 1 || echo 0)
200- ifeq ($(HAVE_HASH ) ,0)
201- $(info warning : could not find HASH ($(HASH ) ), needed to differentiate builds using different flags)
202- BUILD_DIR := obj/generic_noconf
65+ ifeq ($(findstring GCC,$(CCVER ) ) ,GCC)
66+ decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
20367endif
204- endif # BUILD_DIR
20568
20669
20770# macOS linker doesn't support -soname, and use different extension
21881 SHARED_EXT_VER = $(SHARED_EXT ) .$(LIBVER )
21982endif
22083
221- SET_CACHE_DIRECTORY = \
222- +$(MAKE ) --no-print-directory $@ \
223- BUILD_DIR=obj/$(HASH_DIR ) \
224- CPPFLAGS="$(CPPFLAGS ) " \
225- CFLAGS="$(CFLAGS ) " \
226- LDFLAGS="$(LDFLAGS ) "
227-
22884
22985.PHONY : all
23086all : lib
@@ -233,6 +89,13 @@ all: lib
23389.PHONY : libzstd.a # must be run every time
23490libzstd.a : CPPFLAGS += $(CPPFLAGS_STATLIB )
23591
92+ SET_CACHE_DIRECTORY = \
93+ +$(MAKE ) --no-print-directory $@ \
94+ BUILD_DIR=obj/$(HASH_DIR ) \
95+ CPPFLAGS="$(CPPFLAGS ) " \
96+ CFLAGS="$(CFLAGS ) " \
97+ LDFLAGS="$(LDFLAGS ) "
98+
23699ifndef BUILD_DIR
237100# determine BUILD_DIR from compilation flags
238101
@@ -343,6 +206,14 @@ $(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
343206 @echo CC $@
344207 $(COMPILE.c ) $(DEPFLAGS ) $(ZSTD_STATLIB_DIR ) /$* .d $(OUTPUT_OPTION ) $<
345208
209+ $(ZSTD_DYNLIB_DIR ) /% .o : % .S | $(ZSTD_DYNLIB_DIR )
210+ @echo AS $@
211+ $(COMPILE.c ) $(OUTPUT_OPTION ) $<
212+
213+ $(ZSTD_STATLIB_DIR ) /% .o : % .S | $(ZSTD_STATLIB_DIR )
214+ @echo AS $@
215+ $(COMPILE.c ) $(OUTPUT_OPTION ) $<
216+
346217MKDIR ?= mkdir
347218$(BUILD_DIR ) $(ZSTD_DYNLIB_DIR ) $(ZSTD_STATLIB_DIR ) :
348219 $(MKDIR ) -p $@
0 commit comments