1# ########################################################################## 2# Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3# All rights reserved. 4# 5# This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets 6# 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# ########################################################################## 22 23ZSTDDIR = ../lib 24PRGDIR = ../programs 25PYTHON ?= python3 26TESTARTEFACT := versionsTest namespaceTest 27 28 29CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR) 30CFLAGS ?= -O3 31CFLAGS += -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 32 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 33 -Wstrict-prototypes -Wundef -Wformat-security 34CFLAGS += $(MOREFLAGS) 35FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) 36 37 38ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c 39ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c 40ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c 41ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) 42ZBUFF_FILES := $(ZSTDDIR)/deprecated/*.c 43ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c 44 45ZSTD_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZSTD_FILES)) ) 46ZBUFF_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZBUFF_FILES)) ) 47ZDICT_OBJ := $(patsubst %.c,%.o, $(wildcard $(ZDICT_FILES)) ) 48 49 50# Define *.exe as extension for Windows systems 51ifneq (,$(filter Windows%,$(OS))) 52EXT =.exe 53MULTITHREAD_CPP = -DZSTD_MULTITHREAD 54MULTITHREAD_LD = 55else 56EXT = 57MULTITHREAD_CPP = -DZSTD_MULTITHREAD 58MULTITHREAD_LD = -pthread 59endif 60MULTITHREAD = $(MULTITHREAD_CPP) $(MULTITHREAD_LD) 61 62VOID = /dev/null 63ZSTREAM_TESTTIME ?= -T2mn 64FUZZERTEST ?= -T5mn 65ZSTDRTTEST = --test-large-data 66DECODECORPUS_TESTTIME ?= -T30 67 68.PHONY: default all all32 dll clean test test32 test-all namespaceTest versionsTest 69 70default: fullbench 71 72all: fullbench fuzzer zstreamtest paramgrill datagen zbufftest 73 74all32: fullbench32 fuzzer32 zstreamtest32 zbufftest32 75 76dll: fuzzer-dll zstreamtest-dll zbufftest-dll 77 78zstd: 79 $(MAKE) -C $(PRGDIR) $@ 80 81zstd32: 82 $(MAKE) -C $(PRGDIR) $@ 83 84zstd-nolegacy: 85 $(MAKE) -C $(PRGDIR) $@ 86 87gzstd: 88 $(MAKE) -C $(PRGDIR) $@ 89 90fullbench : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c 91 $(CC) $(FLAGS) $^ -o $@$(EXT) 92 93fullbench32 : $(ZSTD_FILES) $(PRGDIR)/datagen.c fullbench.c 94 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT) 95 96fullbench-lib: $(PRGDIR)/datagen.c fullbench.c 97 $(MAKE) -C $(ZSTDDIR) libzstd.a 98 $(CC) $(FLAGS) $^ -o $@$(EXT) $(ZSTDDIR)/libzstd.a 99 100fullbench-dll: $(PRGDIR)/datagen.c fullbench.c 101 $(MAKE) -C $(ZSTDDIR) libzstd 102 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 $(ZSTDDIR)/dll/libzstd.dll 103 104fuzzer : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c 105 $(CC) $(FLAGS) $^ -o $@$(EXT) 106 107fuzzer32 : $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c fuzzer.c 108 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT) 109 110fuzzer-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 111fuzzer-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c fuzzer.c 112 $(MAKE) -C $(ZSTDDIR) libzstd 113 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 114 115zbufftest : CPPFLAGS += -I$(ZSTDDIR)/deprecated 116zbufftest : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings 117zbufftest : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c 118 $(CC) $(FLAGS) $^ -o $@$(EXT) 119 120zbufftest32 : CPPFLAGS += -I$(ZSTDDIR)/deprecated 121zbufftest32 : CFLAGS += -Wno-deprecated-declarations -m32 122zbufftest32 : $(ZSTD_FILES) $(ZBUFF_FILES) $(PRGDIR)/datagen.c zbufftest.c 123 $(CC) $(FLAGS) $^ -o $@$(EXT) 124 125zbufftest-dll : CPPFLAGS += -I$(ZSTDDIR)/deprecated 126zbufftest-dll : CFLAGS += -Wno-deprecated-declarations # required to silence deprecation warnings 127zbufftest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 128zbufftest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zbufftest.c 129 $(MAKE) -C $(ZSTDDIR) libzstd 130 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 131 132ZSTREAMFILES := $(ZSTD_FILES) $(ZDICT_FILES) $(PRGDIR)/datagen.c zstreamtest.c 133zstreamtest : CPPFLAGS += $(MULTITHREAD_CPP) 134zstreamtest : LDFLAGS += $(MULTITHREAD_LD) 135zstreamtest : $(ZSTREAMFILES) 136 $(CC) $(FLAGS) $^ -o $@$(EXT) 137 138zstreamtest32 : CFLAGS += -m32 139zstreamtest32 : $(ZSTREAMFILES) 140 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 141 142zstreamtest_asan : CFLAGS += -fsanitize=address 143zstreamtest_asan : $(ZSTREAMFILES) 144 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 145 146zstreamtest_tsan : CFLAGS += -fsanitize=thread 147zstreamtest_tsan : $(ZSTREAMFILES) 148 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 149 150zstreamtest-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd 151zstreamtest-dll : $(ZSTDDIR)/common/xxhash.c $(PRGDIR)/datagen.c zstreamtest.c 152 $(MAKE) -C $(ZSTDDIR) libzstd 153 $(CC) $(CPPFLAGS) $(CFLAGS) $^ $(LDFLAGS) -o $@$(EXT) 154 155paramgrill : $(ZSTD_FILES) $(PRGDIR)/datagen.c paramgrill.c 156 $(CC) $(FLAGS) $^ -lm -o $@$(EXT) 157 158datagen : $(PRGDIR)/datagen.c datagencli.c 159 $(CC) $(FLAGS) $^ -o $@$(EXT) 160 161roundTripCrash : $(ZSTD_FILES) roundTripCrash.c 162 $(CC) $(FLAGS) $^ -o $@$(EXT) 163 164longmatch : $(ZSTD_FILES) longmatch.c 165 $(CC) $(FLAGS) $^ -o $@$(EXT) 166 167invalidDictionaries : $(ZSTD_FILES) invalidDictionaries.c 168 $(CC) $(FLAGS) $^ -o $@$(EXT) 169 170legacy : CFLAGS+= -DZSTD_LEGACY_SUPPORT=4 171legacy : CPPFLAGS+= -I$(ZSTDDIR)/legacy 172legacy : $(ZSTD_FILES) $(wildcard $(ZSTDDIR)/legacy/*.c) legacy.c 173 $(CC) $(FLAGS) $^ -o $@$(EXT) 174 175decodecorpus : $(filter-out $(ZSTDDIR)/compress/zstd_compress.c, $(wildcard $(ZSTD_FILES))) decodecorpus.c 176 $(CC) $(FLAGS) $^ -o $@$(EXT) -lm 177 178symbols : symbols.c 179 $(MAKE) -C $(ZSTDDIR) libzstd 180ifneq (,$(filter Windows%,$(OS))) 181 cp $(ZSTDDIR)/dll/libzstd.dll . 182 $(CC) $(FLAGS) $^ -o $@$(EXT) -DZSTD_DLL_IMPORT=1 libzstd.dll 183else 184 $(CC) $(FLAGS) $^ -o $@$(EXT) -Wl,-rpath=$(ZSTDDIR) $(ZSTDDIR)/libzstd.so 185endif 186 187pool : pool.c $(ZSTDDIR)/common/pool.c $(ZSTDDIR)/common/threading.c 188 $(CC) $(FLAGS) $(MULTITHREAD) $^ -o $@$(EXT) 189 190namespaceTest: 191 if $(CC) namespaceTest.c ../lib/common/xxhash.c -o $@ ; then echo compilation should fail; exit 1 ; fi 192 $(RM) $@ 193 194versionsTest: clean 195 $(PYTHON) test-zstd-versions.py 196 197clean: 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) \ 209 decodecorpus$(EXT) 210 @echo Cleaning completed 211 212 213#---------------------------------------------------------------------------------- 214#make valgrindTest is validated only for Linux, OSX, BSD, Hurd and Solaris targets 215#---------------------------------------------------------------------------------- 216ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 217HOST_OS = POSIX 218 219valgrindTest: VALGRIND = valgrind --leak-check=full --error-exitcode=1 220valgrindTest: 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) 229 @rm tmp 230 $(VALGRIND) ./fuzzer -T1mn -t1 231 $(VALGRIND) ./fullbench -i1 232 233endif 234 235 236ifneq (,$(filter MSYS%,$(shell uname))) 237HOST_OS = MSYS 238endif 239 240 241#----------------------------------------------------------------------------- 242#make tests validated only for MSYS, Linux, OSX, BSD, Hurd and Solaris targets 243#----------------------------------------------------------------------------- 244ifneq (,$(filter $(HOST_OS),MSYS POSIX)) 245 246DIFF:=diff 247ifneq (,$(filter $(shell uname),SunOS)) 248DIFF:=gdiff 249endif 250 251zstd-playTests: datagen 252 file $(ZSTD) 253 ZSTD="$(QEMU_SYS) $(ZSTD)" ./playTests.sh $(ZSTDRTTEST) 254 255shortest: ZSTDRTTEST= 256shortest: test-zstd 257 258fuzztest: test-fuzzer test-zstream test-decodecorpus 259 260test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus 261ifeq ($(QEMU_SYS),) 262test: test-pool 263endif 264 265test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32 266 267test-all: test test32 valgrindTest 268 269test-zstd: ZSTD = $(PRGDIR)/zstd 270test-zstd: zstd zstd-playTests 271 272test-zstd32: ZSTD = $(PRGDIR)/zstd32 273test-zstd32: zstd32 zstd-playTests 274 275test-zstd-nolegacy: ZSTD = $(PRGDIR)/zstd 276test-zstd-nolegacy: zstd-nolegacy zstd-playTests 277 278test-gzstd: gzstd 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 293 294test-fullbench: fullbench datagen 295 $(QEMU_SYS) ./fullbench -i1 296 $(QEMU_SYS) ./fullbench -i1 -P0 297 298test-fullbench32: fullbench32 datagen 299 $(QEMU_SYS) ./fullbench32 -i1 300 $(QEMU_SYS) ./fullbench32 -i1 -P0 301 302test-fuzzer: fuzzer 303 $(QEMU_SYS) ./fuzzer $(FUZZERTEST) 304 305test-fuzzer32: fuzzer32 306 $(QEMU_SYS) ./fuzzer32 $(FUZZERTEST) 307 308test-zbuff: zbufftest 309 $(QEMU_SYS) ./zbufftest $(ZSTREAM_TESTTIME) 310 311test-zbuff32: zbufftest32 312 $(QEMU_SYS) ./zbufftest32 $(ZSTREAM_TESTTIME) 313 314test-zstream: zstreamtest 315 $(QEMU_SYS) ./zstreamtest $(ZSTREAM_TESTTIME) 316 317test-zstream32: zstreamtest32 318 $(QEMU_SYS) ./zstreamtest32 $(ZSTREAM_TESTTIME) 319 320test-longmatch: longmatch 321 $(QEMU_SYS) ./longmatch 322 323test-invalidDictionaries: invalidDictionaries 324 $(QEMU_SYS) ./invalidDictionaries 325 326test-symbols: symbols 327 $(QEMU_SYS) ./symbols 328 329test-legacy: legacy 330 $(QEMU_SYS) ./legacy 331 332test-decodecorpus: decodecorpus 333 $(QEMU_SYS) ./decodecorpus -t $(DECODECORPUS_TESTTIME) 334 335test-pool: pool 336 $(QEMU_SYS) ./pool 337 338endif 339