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