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