1# Makefile for example of using zstd wrapper for zlib 2# 3# make - compiles examples 4# make MOREFLAGS=-DZWRAP_USE_ZSTD=1 - compiles examples with zstd compression turned on 5# make test - runs examples 6 7 8# Paths to static and dynamic zlib and zstd libraries 9# Use "make ZLIB_PATH=path/to/zlib ZLIB_LIBRARY=path/to/libz.a" to select a path to library 10ZLIB_LIBRARY ?= -lz 11ZLIB_PATH ?= . 12 13ZSTDLIBDIR = ../lib 14ZSTDLIBRARY = $(ZSTDLIBDIR)/libzstd.a 15ZLIBWRAPPER_PATH = . 16GZFILES = gzclose.o gzlib.o gzread.o gzwrite.o 17EXAMPLE_PATH = examples 18PROGRAMS_PATH = ../programs 19TEST_FILE = ../doc/zstd_compression_format.md 20 21CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -I$(ZLIB_PATH) -I$(PROGRAMS_PATH) \ 22 -I$(ZSTDLIBDIR) -I$(ZSTDLIBDIR)/common -I$(ZLIBWRAPPER_PATH) 23STDFLAGS = -std=c90 -pedantic -Wno-long-long -Wno-variadic-macros -Wc++-compat \ 24 -DNO_snprintf -DNO_vsnprintf # strict ISO C90 is missing these prototypes 25DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \ 26 -Wdeclaration-after-statement -Wstrict-prototypes -Wundef \ 27 -Wstrict-aliasing=1 28CFLAGS ?= -O3 29CFLAGS += $(STDFLAGS) $(DEBUGFLAGS) $(MOREFLAGS) 30 31# Define *.exe as extension for Windows systems 32ifneq (,$(filter Windows%,$(OS))) 33EXT =.exe 34else 35EXT = 36endif 37 38default : release 39 40release : STDFLAGS = 41release : DEBUGFLAGS = 42release : all 43 44all: fitblk example zwrapbench minigzip 45 46test: example fitblk example_zstd fitblk_zstd zwrapbench minigzip minigzip_zstd 47 ./example 48 ./example_zstd 49 ./fitblk 10240 <$(TEST_FILE) 50 ./fitblk 40960 <$(TEST_FILE) 51 ./fitblk_zstd 10240 <$(TEST_FILE) 52 ./fitblk_zstd 40960 <$(TEST_FILE) 53 @echo ---- minigzip start ---- 54 ./minigzip_zstd example$(EXT) 55 #cp example$(EXT).gz example$(EXT)_zstd.gz 56 ./minigzip_zstd -d example$(EXT).gz 57 ./minigzip example$(EXT) 58 #cp example$(EXT).gz example$(EXT)_gz.gz 59 ./minigzip_zstd -d example$(EXT).gz 60 @echo ---- minigzip end ---- 61 ./zwrapbench -qi1b3B1K $(TEST_FILE) 62 ./zwrapbench -rqi1b1e5 ../lib ../programs ../tests 63 64#valgrindTest: ZSTDLIBRARY = $(ZSTDLIBDIR)/libzstd.so 65valgrindTest: VALGRIND = LD_LIBRARY_PATH=$(ZSTDLIBDIR) valgrind --track-origins=yes --leak-check=full --error-exitcode=1 66valgrindTest: clean example fitblk example_zstd fitblk_zstd zwrapbench 67 @echo "\n ---- valgrind tests ----" 68 $(VALGRIND) ./example 69 $(VALGRIND) ./example_zstd 70 $(VALGRIND) ./fitblk 10240 <$(TEST_FILE) 71 $(VALGRIND) ./fitblk 40960 <$(TEST_FILE) 72 $(VALGRIND) ./fitblk_zstd 10240 <$(TEST_FILE) 73 $(VALGRIND) ./fitblk_zstd 40960 <$(TEST_FILE) 74 $(VALGRIND) ./zwrapbench -qi1b3B1K $(TEST_FILE) 75 $(VALGRIND) ./zwrapbench -rqi1b1e5 ../lib ../programs ../tests 76 77#.c.o: 78# $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ 79 80minigzip: $(EXAMPLE_PATH)/minigzip.o zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 81 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ 82 83minigzip_zstd: $(EXAMPLE_PATH)/minigzip.o zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 84 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ 85 86example: $(EXAMPLE_PATH)/example.o zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 87 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 88 89example_zstd: $(EXAMPLE_PATH)/example.o zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 90 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 91 92fitblk: $(EXAMPLE_PATH)/fitblk.o zstd_zlibwrapper.o $(ZSTDLIBRARY) 93 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 94 95fitblk_zstd: $(EXAMPLE_PATH)/fitblk.o zstdTurnedOn_zlibwrapper.o $(ZSTDLIBRARY) 96 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 97 98zwrapbench: $(EXAMPLE_PATH)/zwrapbench.o zstd_zlibwrapper.o $(PROGRAMS_PATH)/util.o $(PROGRAMS_PATH)/timefn.o $(PROGRAMS_PATH)/datagen.o $(ZSTDLIBRARY) 99 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 100 101 102zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h 103 104zstdTurnedOn_zlibwrapper.o: CPPFLAGS += -DZWRAP_USE_ZSTD=1 105zstdTurnedOn_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h 106 $(CC) $(CPPFLAGS) $(CFLAGS) $< -c -o $@ 107 108$(ZSTDLIBDIR)/libzstd.a: 109 $(MAKE) -C $(ZSTDLIBDIR) libzstd.a 110 111$(ZSTDLIBDIR)/libzstd.so: 112 $(MAKE) -C $(ZSTDLIBDIR) libzstd 113 114 115clean: 116 -$(RM) $(ZLIBWRAPPER_PATH)/*.o $(EXAMPLE_PATH)/*.o *.o foo.gz example$(EXT) example_zstd$(EXT) fitblk$(EXT) fitblk_zstd$(EXT) zwrapbench$(EXT) minigzip$(EXT) minigzip_zstd$(EXT) 117 @echo Cleaning completed 118