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) 23CFLAGS ?= $(MOREFLAGS) -O3 -std=gnu99 24CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum \ 25 -Wdeclaration-after-statement -Wstrict-prototypes -Wundef \ 26 -Wstrict-aliasing=1 27 28 29# Define *.exe as extension for Windows systems 30ifneq (,$(filter Windows%,$(OS))) 31EXT =.exe 32else 33EXT = 34endif 35 36 37all: fitblk example zwrapbench minigzip 38 39test: example fitblk example_zstd fitblk_zstd zwrapbench minigzip minigzip_zstd 40 ./example 41 ./example_zstd 42 ./fitblk 10240 <$(TEST_FILE) 43 ./fitblk 40960 <$(TEST_FILE) 44 ./fitblk_zstd 10240 <$(TEST_FILE) 45 ./fitblk_zstd 40960 <$(TEST_FILE) 46 @echo ---- minigzip start ---- 47 ./minigzip_zstd example$(EXT) 48 #cp example$(EXT).gz example$(EXT)_zstd.gz 49 ./minigzip_zstd -d example$(EXT).gz 50 ./minigzip example$(EXT) 51 #cp example$(EXT).gz example$(EXT)_gz.gz 52 ./minigzip_zstd -d example$(EXT).gz 53 @echo ---- minigzip end ---- 54 ./zwrapbench -qi1b3B1K $(TEST_FILE) 55 ./zwrapbench -rqi1b1e5 ../lib ../programs ../tests 56 57#valgrindTest: ZSTDLIBRARY = $(ZSTDLIBDIR)/libzstd.so 58valgrindTest: VALGRIND = LD_LIBRARY_PATH=$(ZSTDLIBDIR) valgrind --track-origins=yes --leak-check=full --error-exitcode=1 59valgrindTest: clean example fitblk example_zstd fitblk_zstd zwrapbench 60 @echo "\n ---- valgrind tests ----" 61 $(VALGRIND) ./example 62 $(VALGRIND) ./example_zstd 63 $(VALGRIND) ./fitblk 10240 <$(TEST_FILE) 64 $(VALGRIND) ./fitblk 40960 <$(TEST_FILE) 65 $(VALGRIND) ./fitblk_zstd 10240 <$(TEST_FILE) 66 $(VALGRIND) ./fitblk_zstd 40960 <$(TEST_FILE) 67 $(VALGRIND) ./zwrapbench -qi1b3B1K $(TEST_FILE) 68 $(VALGRIND) ./zwrapbench -rqi1b1e5 ../lib ../programs ../tests 69 70#.c.o: 71# $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< 72 73minigzip: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 74 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ 75 76minigzip_zstd: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 77 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ 78 79example: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 80 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 81 82example_zstd: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) 83 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 84 85fitblk: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(ZSTDLIBRARY) 86 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 87 88fitblk_zstd: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(ZSTDLIBRARY) 89 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 90 91zwrapbench: $(EXAMPLE_PATH)/zwrapbench.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(PROGRAMS_PATH)/util.o $(PROGRAMS_PATH)/timefn.o $(PROGRAMS_PATH)/datagen.o $(ZSTDLIBRARY) 92 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ 93 94 95$(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h 96 $(CC) $(CFLAGS) $(CPPFLAGS) -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c 97 98$(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h 99 $(CC) $(CFLAGS) $(CPPFLAGS) -DZWRAP_USE_ZSTD=1 -I. -c -o $@ $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c 100 101$(ZSTDLIBDIR)/libzstd.a: 102 $(MAKE) -C $(ZSTDLIBDIR) libzstd.a 103 104$(ZSTDLIBDIR)/libzstd.so: 105 $(MAKE) -C $(ZSTDLIBDIR) libzstd 106 107 108clean: 109 -$(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) 110 @echo Cleaning completed 111