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