xref: /freebsd/sys/contrib/zstd/examples/Makefile (revision 6966ac055c3b7a39266fb982493330df7a097997)
1# ################################################################
2# Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3# All rights reserved.
4#
5# This source code is licensed under both the BSD-style license (found in the
6# LICENSE file in the root directory of this source tree) and the GPLv2 (found
7# in the COPYING file in the root directory of this source tree).
8# ################################################################
9
10# This Makefile presumes libzstd is installed, using `sudo make install`
11
12CPPFLAGS += -I../lib
13LIB = ../lib/libzstd.a
14
15.PHONY: default all clean test
16
17default: all
18
19all: simple_compression simple_decompression \
20	multiple_simple_compression\
21	dictionary_compression dictionary_decompression \
22	streaming_compression streaming_decompression \
23	multiple_streaming_compression streaming_memory_usage
24
25$(LIB) :
26	$(MAKE) -C ../lib libzstd.a
27
28simple_compression : simple_compression.c common.h $(LIB)
29	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
30
31simple_decompression : simple_decompression.c common.h $(LIB)
32	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
33
34multiple_simple_compression : multiple_simple_compression.c common.h $(LIB)
35	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
36
37dictionary_compression : dictionary_compression.c common.h $(LIB)
38	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
39
40dictionary_decompression : dictionary_decompression.c common.h $(LIB)
41	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
42
43streaming_compression : streaming_compression.c common.h $(LIB)
44	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
45
46multiple_streaming_compression : multiple_streaming_compression.c common.h $(LIB)
47	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
48
49streaming_decompression : streaming_decompression.c common.h $(LIB)
50	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
51
52streaming_memory_usage : streaming_memory_usage.c $(LIB)
53	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
54
55clean:
56	@rm -f core *.o tmp* result* *.zst \
57        simple_compression simple_decompression \
58        multiple_simple_compression \
59        dictionary_compression dictionary_decompression \
60        streaming_compression streaming_decompression \
61        multiple_streaming_compression streaming_memory_usage
62	@echo Cleaning completed
63
64test: all
65	cp README.md tmp
66	cp Makefile tmp2
67	@echo -- Simple compression tests
68	./simple_compression tmp
69	./simple_decompression tmp.zst
70	./multiple_simple_compression *.c
71	./streaming_decompression tmp.zst > /dev/null
72	@echo -- Streaming memory usage
73	./streaming_memory_usage
74	@echo -- Streaming compression tests
75	./streaming_compression tmp
76	./streaming_decompression tmp.zst > /dev/null
77	@echo -- Edge cases detection
78	! ./streaming_decompression tmp    # invalid input, must fail
79	! ./simple_decompression tmp       # invalid input, must fail
80	touch tmpNull                      # create 0-size file
81	./simple_compression tmpNull
82	./simple_decompression tmpNull.zst # 0-size frame : must work
83	@echo -- Multiple streaming tests
84	./multiple_streaming_compression *.c
85	@echo -- Dictionary compression tests
86	./dictionary_compression tmp2 tmp README.md
87	./dictionary_decompression tmp2.zst tmp.zst README.md
88	$(RM) tmp* *.zst
89	@echo tests completed
90