1 # ##########################################################################
2 # Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
7 # This source code is licensed under the BSD-style license found in the
8 # LICENSE file in the root directory of this source tree. An additional grant
9 # of patent rights can be found in the PATENTS file in the same directory.
10 # ##########################################################################
11 # datagen : Synthetic and parametrable data generator, for tests
12 # fullbench : Precisely measure speed for each zstd inner functions
13 # fullbench32: Same as fullbench, but forced to compile in 32-bits mode
14 # fuzzer : Test tool, to check zstd integrity on target platform
15 # fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
16 # paramgrill : parameter tester for zstd
17 # test-zstd-speed.py : script for testing zstd speed difference between commits
18 # versionsTest : compatibility test between zstd versions stored on Github (v0.1+)
19 # zstreamtest : Fuzzer test tool for zstd streaming API
20 # zstreamtest32: Same as zstreamtest, but forced to compile in 32-bits mode
21 # ##########################################################################
26 TESTARTEFACT := versionsTest namespaceTest
29 CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
31 CFLAGS += -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
32 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
33 -Wstrict-prototypes -Wundef -Wformat-security
34 CFLAGS += $(MOREFLAGS)
35 FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
38 ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
39 ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c
40 ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
41 ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
42 ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c
43 ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
45 ZSTD_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZSTD_FILES)) )
46 ZBUFF_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZBUFF_FILES)) )
47 ZDICT_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZDICT_FILES)) )
50 # Define *.exe as extension for Windows systems
51 ifneq (,$(filter Windows%,$(OS)))
53 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
57 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
58 MULTITHREAD_LD = -pthread
60 MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
63 ZSTREAM_TESTTIME ?= -T2mn
65 ZSTDRTTEST = --test-large-data
66 DECODECORPUS_TESTTIME ?= -T30
68 .PHONY: default all all32 dll clean test test32 test-all namespaceTest versionsTest
72 all: fullbench fuzzer zstreamtest paramgrill datagen zbufftest
74 all32: fullbench32 fuzzer32 zstreamtest32 zbufftest32
76 dll: fuzzer-dll zstreamtest-dll zbufftest-dll
79 $(MAKE) -C $(PRGDIR) $@
82 $(MAKE) -C $(PRGDIR) $@
85 $(MAKE) -C $(PRGDIR) $@
88 $(MAKE) -C $(PRGDIR) $@
90 fullbench : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
91 $(CC) $(FLAGS) $^ -o $@$(EXT)
93 fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
94 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
96 fullbench-lib: $(PRGDIR)/datagen.c fullbench.c
97 $(MAKE) -C $(ZSTDDIR) libzstd.a
98 $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a
100 fullbench-dll: $(PRGDIR)/datagen.c fullbench.c
101 $(MAKE) -C $(ZSTDDIR) libzstd
102 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
104 fuzzer : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
105 $(CC) $(FLAGS) $^ -o $@$(EXT)
107 fuzzer32 : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
108 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
110 fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
111 fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c fuzzer.c
112 $(MAKE) -C $(ZSTDDIR) libzstd
113 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
115 zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated
116 zbufftest : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings
117 zbufftest : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
118 $(CC) $(FLAGS) $^ -o $@$(EXT)
120 zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated
121 zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32
122 zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
123 $(CC) $(FLAGS) $^ -o $@$(EXT)
125 zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated
126 zbufftest-dll : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings
127 zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
128 zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zbufftest.c
129 $(MAKE) -C $(ZSTDDIR) libzstd
130 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
132 ZSTREAMFILES := $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c zstreamtest.c
133 zstreamtest : CPPFLAGS += $(MULTITHREAD_CPP)
134 zstreamtest : LDFLAGS += $(MULTITHREAD_LD)
135 zstreamtest : $(ZSTREAMFILES)
136 $(CC) $(FLAGS) $^ -o $@$(EXT)
138 zstreamtest32 : CFLAGS += -m32
139 zstreamtest32 : $(ZSTREAMFILES)
140 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
142 zstreamtest_asan : CFLAGS += -fsanitize=address
143 zstreamtest_asan : $(ZSTREAMFILES)
144 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
146 zstreamtest_tsan : CFLAGS += -fsanitize=thread
147 zstreamtest_tsan : $(ZSTREAMFILES)
148 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
150 zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
151 zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zstreamtest.c
152 $(MAKE) -C $(ZSTDDIR) libzstd
153 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
155 paramgrill : $(ZSTD_FILES) $(PRGDIR)/datagen.c paramgrill.c
156 $(CC) $(FLAGS) $^ -lm -o $@$(EXT)
158 datagen : $(PRGDIR)/datagen.c datagencli.c
159 $(CC) $(FLAGS) $^ -o $@$(EXT)
161 roundTripCrash : $(ZSTD_FILES) roundTripCrash.c
162 $(CC) $(FLAGS) $^ -o $@$(EXT)
164 longmatch : $(ZSTD_FILES) longmatch.c
165 $(CC) $(FLAGS) $^ -o $@$(EXT)
167 invalidDictionaries : $(ZSTD_FILES) invalidDictionaries.c
168 $(CC) $(FLAGS) $^ -o $@$(EXT)
170 legacy : CFLAGS+= -DZSTD_LEGACY_SUPPORT=4
171 legacy : CPPFLAGS+= -I$(ZSTDDIR)/legacy
172 legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c
173 $(CC) $(FLAGS) $^ -o $@$(EXT)
175 decodecorpus : $(filter-out $(ZSTDDIR)/compress/zstd_compress.c, $(wildcard $(ZSTD_FILES))) decodecorpus.c
176 $(CC) $(FLAGS) $^ -o $@$(EXT) -lm
179 $(MAKE) -C $(ZSTDDIR) libzstd
180 ifneq (,$(filter Windows%,$(OS)))
181 cp $(ZSTDDIR)/dll/libzstd.dll .
182 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll
184 $(CC) $(FLAGS) $^ -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so
187 pool : pool.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c
188 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
191 if $(CC) namespaceTest.c ../lib/common/xxhash.c -o $@ ; then echo compilation should fail; exit 1 ; fi
195 $(PYTHON) test-zstd-versions.py
198 $(MAKE) -C $(ZSTDDIR) clean
199 @$(RM) -fR $(TESTARTEFACT)
200 @$(RM) -f core *.o tmp* result* *.gcda dictionary *.zst \
201 $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
202 fullbench$(EXT) fullbench32$(EXT) \
203 fullbench-lib$(EXT) fullbench-dll$(EXT) \
204 fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \
205 fuzzer-dll$(EXT) zstreamtest-dll$(EXT) zbufftest-dll$(EXT)\
206 zstreamtest$(EXT) zstreamtest32$(EXT) \
207 datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
208 symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) pool$(EXT) \
210 @echo Cleaning completed
213 #----------------------------------------------------------------------------------
214 #make valgrindTest is validated only for Linux, OSX, BSD, Hurd and Solaris targets
215 #----------------------------------------------------------------------------------
216 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
219 valgrindTest: VALGRIND = valgrind --leak-check=full --error-exitcode=1
220 valgrindTest: zstd datagen fuzzer fullbench
221 @echo "\n ---- valgrind tests : memory analyzer ----"
222 $(VALGRIND) ./datagen -g50M > $(VOID)
223 $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
224 ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
225 ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
226 ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
227 $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
228 ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
230 $(VALGRIND) ./fuzzer -T1mn -t1
231 $(VALGRIND) ./fullbench -i1
236 ifneq (,$(filter MSYS%,$(shell uname)))
241 #-----------------------------------------------------------------------------
242 #make tests validated only for MSYS, Linux, OSX, BSD, Hurd and Solaris targets
243 #-----------------------------------------------------------------------------
244 ifneq (,$(filter $(HOST_OS),MSYS POSIX))
247 ifneq (,$(filter $(shell uname),SunOS))
251 zstd-playTests: datagen
253 ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST)
255 shortest: ZSTDRTTEST=
258 fuzztest: test-fuzzer test-zstream test-decodecorpus
260 test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus
265 test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
267 test-all: test test32 valgrindTest
269 test-zstd: ZSTD = $(PRGDIR)/zstd
270 test-zstd: zstd zstd-playTests
272 test-zstd32: ZSTD = $(PRGDIR)/zstd32
273 test-zstd32: zstd32 zstd-playTests
275 test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd
276 test-zstd-nolegacy: zstd-nolegacy zstd-playTests
279 $(PRGDIR)/zstd README.md test-zstd-speed.py
280 gzip README.md test-zstd-speed.py
281 cat README.md.zst test-zstd-speed.py.gz >zstd_gz.zst
282 cat README.md.gz test-zstd-speed.py.zst >gz_zstd.gz
283 $(PRGDIR)/zstd -d README.md.gz -o README2.md
284 $(PRGDIR)/zstd -d README.md.gz test-zstd-speed.py.gz
285 $(PRGDIR)/zstd -d zstd_gz.zst gz_zstd.gz
286 $(DIFF) -q zstd_gz gz_zstd
287 echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst
288 echo Hello World GZIP | gzip -c - >hello.gz
289 echo Hello World TEXT >hello.txt
290 cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz
291 $(PRGDIR)/zstd -dcf hello.*
292 $(PRGDIR)/zstd -dcf - <hello_zst_gz_txt.gz
294 test-fullbench: fullbench datagen
295 $(QEMU_SYS) ./fullbench -i1
296 $(QEMU_SYS) ./fullbench -i1 -P0
298 test-fullbench32: fullbench32 datagen
299 $(QEMU_SYS) ./fullbench32 -i1
300 $(QEMU_SYS) ./fullbench32 -i1 -P0
303 $(QEMU_SYS) ./fuzzer $(FUZZERTEST)
305 test-fuzzer32: fuzzer32
306 $(QEMU_SYS) ./fuzzer32 $(FUZZERTEST)
308 test-zbuff: zbufftest
309 $(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME)
311 test-zbuff32: zbufftest32
312 $(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME)
314 test-zstream: zstreamtest
315 $(QEMU_SYS) ./zstreamtest $(ZSTREAM_TESTTIME)
317 test-zstream32: zstreamtest32
318 $(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME)
320 test-longmatch: longmatch
321 $(QEMU_SYS) ./longmatch
323 test-invalidDictionaries: invalidDictionaries
324 $(QEMU_SYS) ./invalidDictionaries
326 test-symbols: symbols
327 $(QEMU_SYS) ./symbols
332 test-decodecorpus: decodecorpus
333 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)