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 DEBUGFLAGS=-g -DZSTD_DEBUG=1
30 CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
31 -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) \
34 CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
35 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
36 -Wstrict-prototypes -Wundef -Wformat-security
37 CFLAGS += $(MOREFLAGS)
38 FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
41 ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
42 ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c
43 ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
44 ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
45 ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c
46 ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
48 ZSTD_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZSTD_FILES)) )
49 ZBUFF_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZBUFF_FILES)) )
50 ZDICT_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZDICT_FILES)) )
53 # Define *.exe as extension for Windows systems
54 ifneq (,$(filter Windows%,$(OS)))
56 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
60 MULTITHREAD_CPP = -DZSTD_MULTITHREAD
61 MULTITHREAD_LD = -pthread
63 MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD)
66 ZSTREAM_TESTTIME ?= -T2mn
68 ZSTDRTTEST = --test-large-data
69 DECODECORPUS_TESTTIME ?= -T30
71 .PHONY: default all all32 allnothread dll clean test test32 test-all namespaceTest versionsTest
75 all: fullbench fuzzer zstreamtest paramgrill datagen zbufftest decodecorpus
77 all32: fullbench32 fuzzer32 zstreamtest32 zbufftest32
79 allnothread: fullbench fuzzer paramgrill datagen zbufftest decodecorpus
81 dll: fuzzer-dll zstreamtest-dll zbufftest-dll
84 $(MAKE) -C $(PRGDIR) $@
87 $(MAKE) -C $(PRGDIR) $@
90 $(MAKE) -C $(PRGDIR) $@
93 $(MAKE) -C $(PRGDIR) $@
95 fullbench : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
96 $(CC) $(FLAGS) $^ -o $@$(EXT)
98 fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c
99 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
101 fullbench-lib: $(PRGDIR)/datagen.c fullbench.c
102 $(MAKE) -C $(ZSTDDIR) libzstd.a
103 $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a
105 fullbench-dll: $(PRGDIR)/datagen.c fullbench.c
106 $(MAKE) -C $(ZSTDDIR) libzstd
107 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll
109 fuzzer : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
110 $(CC) $(FLAGS) $^ -o $@$(EXT)
112 fuzzer32 : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c
113 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
115 fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
116 fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c fuzzer.c
117 $(MAKE) -C $(ZSTDDIR) libzstd
118 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
120 zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated
121 zbufftest : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings
122 zbufftest : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
123 $(CC) $(FLAGS) $^ -o $@$(EXT)
125 zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated
126 zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32
127 zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c
128 $(CC) $(FLAGS) $^ -o $@$(EXT)
130 zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated
131 zbufftest-dll : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings
132 zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
133 zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zbufftest.c
134 $(MAKE) -C $(ZSTDDIR) libzstd
135 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
137 ZSTREAMFILES := $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c zstreamtest.c
138 zstreamtest : CPPFLAGS += $(MULTITHREAD_CPP)
139 zstreamtest : LDFLAGS += $(MULTITHREAD_LD)
140 zstreamtest : $(ZSTREAMFILES)
141 $(CC) $(FLAGS) $^ -o $@$(EXT)
143 zstreamtest32 : CFLAGS += -m32
144 zstreamtest32 : $(ZSTREAMFILES)
145 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
147 zstreamtest_asan : CFLAGS += -fsanitize=address
148 zstreamtest_asan : $(ZSTREAMFILES)
149 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
151 zstreamtest_tsan : CFLAGS += -fsanitize=thread
152 zstreamtest_tsan : $(ZSTREAMFILES)
153 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
155 zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
156 zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zstreamtest.c
157 $(MAKE) -C $(ZSTDDIR) libzstd
158 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT)
160 paramgrill : DEBUGFLAG =
161 paramgrill : $(ZSTD_FILES) $(PRGDIR)/datagen.c paramgrill.c
162 $(CC) $(FLAGS) $^ -lm -o $@$(EXT)
164 datagen : $(PRGDIR)/datagen.c datagencli.c
165 $(CC) $(FLAGS) $^ -o $@$(EXT)
167 roundTripCrash : $(ZSTD_FILES) roundTripCrash.c
168 $(CC) $(FLAGS) $^ -o $@$(EXT)
170 longmatch : $(ZSTD_FILES) longmatch.c
171 $(CC) $(FLAGS) $^ -o $@$(EXT)
173 invalidDictionaries : $(ZSTD_FILES) invalidDictionaries.c
174 $(CC) $(FLAGS) $^ -o $@$(EXT)
176 legacy : CFLAGS+= -DZSTD_LEGACY_SUPPORT=4
177 legacy : CPPFLAGS+= -I$(ZSTDDIR)/legacy
178 legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c
179 $(CC) $(FLAGS) $^ -o $@$(EXT)
181 decodecorpus : $(filter-out $(ZSTDDIR)/compress/zstd_compress.c, $(wildcard $(ZSTD_FILES))) decodecorpus.c
182 $(CC) $(FLAGS) $^ -o $@$(EXT) -lm
185 $(MAKE) -C $(ZSTDDIR) libzstd
186 ifneq (,$(filter Windows%,$(OS)))
187 cp $(ZSTDDIR)/dll/libzstd.dll .
188 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll
190 $(CC) $(FLAGS) $^ -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so
193 pool : pool.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c
194 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT)
197 if $(CC) namespaceTest.c ../lib/common/xxhash.c -o $@ ; then echo compilation should fail; exit 1 ; fi
201 $(PYTHON) test-zstd-versions.py
204 $(MAKE) -C $(ZSTDDIR) clean
205 @$(RM) -fR $(TESTARTEFACT)
206 @$(RM) -f core *.o tmp* result* *.gcda dictionary *.zst \
207 $(PRGDIR)/zstd$(EXT) $(PRGDIR)/zstd32$(EXT) \
208 fullbench$(EXT) fullbench32$(EXT) \
209 fullbench-lib$(EXT) fullbench-dll$(EXT) \
210 fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \
211 fuzzer-dll$(EXT) zstreamtest-dll$(EXT) zbufftest-dll$(EXT)\
212 zstreamtest$(EXT) zstreamtest32$(EXT) \
213 datagen$(EXT) paramgrill$(EXT) roundTripCrash$(EXT) longmatch$(EXT) \
214 symbols$(EXT) invalidDictionaries$(EXT) legacy$(EXT) pool$(EXT) \
216 @echo Cleaning completed
219 #----------------------------------------------------------------------------------
220 #make valgrindTest is validated only for Linux, OSX, BSD, Hurd and Solaris targets
221 #----------------------------------------------------------------------------------
222 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
225 valgrindTest: VALGRIND = valgrind --leak-check=full --error-exitcode=1
226 valgrindTest: zstd datagen fuzzer fullbench
227 @echo "\n ---- valgrind tests : memory analyzer ----"
228 $(VALGRIND) ./datagen -g50M > $(VOID)
229 $(VALGRIND) $(PRGDIR)/zstd ; if [ $$? -eq 0 ] ; then echo "zstd without argument should have failed"; false; fi
230 ./datagen -g80 | $(VALGRIND) $(PRGDIR)/zstd - -c > $(VOID)
231 ./datagen -g16KB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
232 ./datagen -g2930KB | $(VALGRIND) $(PRGDIR)/zstd -5 -vf - -o tmp
233 $(VALGRIND) $(PRGDIR)/zstd -vdf tmp -c > $(VOID)
234 ./datagen -g64MB | $(VALGRIND) $(PRGDIR)/zstd -vf - -c > $(VOID)
236 $(VALGRIND) ./fuzzer -T1mn -t1
237 $(VALGRIND) ./fullbench -i1
242 ifneq (,$(filter MSYS%,$(shell uname)))
247 #-----------------------------------------------------------------------------
248 #make tests validated only for MSYS, Linux, OSX, BSD, Hurd and Solaris targets
249 #-----------------------------------------------------------------------------
250 ifneq (,$(filter $(HOST_OS),MSYS POSIX))
253 ifneq (,$(filter $(shell uname),SunOS))
257 zstd-playTests: datagen
259 ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST)
261 shortest: ZSTDRTTEST=
264 fuzztest: test-fuzzer test-zstream test-decodecorpus
266 test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus
271 test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32
273 test-all: test test32 valgrindTest
275 test-zstd: ZSTD = $(PRGDIR)/zstd
276 test-zstd: zstd zstd-playTests
278 test-zstd32: ZSTD = $(PRGDIR)/zstd32
279 test-zstd32: zstd32 zstd-playTests
281 test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd
282 test-zstd-nolegacy: zstd-nolegacy zstd-playTests
285 $(PRGDIR)/zstd README.md test-zstd-speed.py
286 gzip README.md test-zstd-speed.py
287 cat README.md.zst test-zstd-speed.py.gz >zstd_gz.zst
288 cat README.md.gz test-zstd-speed.py.zst >gz_zstd.gz
289 $(PRGDIR)/zstd -d README.md.gz -o README2.md
290 $(PRGDIR)/zstd -d README.md.gz test-zstd-speed.py.gz
291 $(PRGDIR)/zstd -d zstd_gz.zst gz_zstd.gz
292 $(DIFF) -q zstd_gz gz_zstd
293 echo Hello World ZSTD | $(PRGDIR)/zstd -c - >hello.zst
294 echo Hello World GZIP | gzip -c - >hello.gz
295 echo Hello World TEXT >hello.txt
296 cat hello.zst hello.gz hello.txt >hello_zst_gz_txt.gz
297 $(PRGDIR)/zstd -dcf hello.*
298 $(PRGDIR)/zstd -dcf - <hello_zst_gz_txt.gz
300 test-fullbench: fullbench datagen
301 $(QEMU_SYS) ./fullbench -i1
302 $(QEMU_SYS) ./fullbench -i1 -P0
304 test-fullbench32: fullbench32 datagen
305 $(QEMU_SYS) ./fullbench32 -i1
306 $(QEMU_SYS) ./fullbench32 -i1 -P0
309 $(QEMU_SYS) ./fuzzer $(FUZZERTEST) $(FUZZER_FLAGS)
311 test-fuzzer32: fuzzer32
312 $(QEMU_SYS) ./fuzzer32 $(FUZZERTEST) $(FUZZER_FLAGS)
314 test-zbuff: zbufftest
315 $(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME)
317 test-zbuff32: zbufftest32
318 $(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME)
320 test-zstream: zstreamtest
321 $(QEMU_SYS) ./zstreamtest $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
323 test-zstream32: zstreamtest32
324 $(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME) $(FUZZER_FLAGS)
326 test-longmatch: longmatch
327 $(QEMU_SYS) ./longmatch
329 test-invalidDictionaries: invalidDictionaries
330 $(QEMU_SYS) ./invalidDictionaries
332 test-symbols: symbols
333 $(QEMU_SYS) ./symbols
338 test-decodecorpus: decodecorpus
339 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME)