xref: /freebsd/sys/contrib/zstd/examples/Makefile (revision fe815331bb40604ba31312acf7e4619674631777)
1# ################################################################
2# Copyright (c) 2016-2020, 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# You may select, at your option, one of the above-listed licenses.
9# ################################################################
10
11# This Makefile presumes libzstd is installed, using `sudo make install`
12
13CPPFLAGS += -I../lib
14LIB = ../lib/libzstd.a
15
16.PHONY: default all clean test
17
18default: all
19
20all: simple_compression simple_decompression \
21	multiple_simple_compression\
22	dictionary_compression dictionary_decompression \
23	streaming_compression streaming_decompression \
24	multiple_streaming_compression streaming_memory_usage
25
26$(LIB) :
27	$(MAKE) -C ../lib libzstd.a
28
29simple_compression : simple_compression.c common.h $(LIB)
30	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
31
32simple_decompression : simple_decompression.c common.h $(LIB)
33	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
34
35multiple_simple_compression : multiple_simple_compression.c common.h $(LIB)
36	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
37
38dictionary_compression : dictionary_compression.c common.h $(LIB)
39	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
40
41dictionary_decompression : dictionary_decompression.c common.h $(LIB)
42	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
43
44streaming_compression : streaming_compression.c common.h $(LIB)
45	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
46
47multiple_streaming_compression : multiple_streaming_compression.c common.h $(LIB)
48	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
49
50streaming_decompression : streaming_decompression.c common.h $(LIB)
51	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
52
53streaming_memory_usage : streaming_memory_usage.c $(LIB)
54	$(CC) $(CPPFLAGS) $(CFLAGS) $< $(LIB) $(LDFLAGS) -o $@
55
56clean:
57	@rm -f core *.o tmp* result* *.zst \
58        simple_compression simple_decompression \
59        multiple_simple_compression \
60        dictionary_compression dictionary_decompression \
61        streaming_compression streaming_decompression \
62        multiple_streaming_compression streaming_memory_usage
63	@echo Cleaning completed
64
65test: all
66	cp README.md tmp
67	cp Makefile tmp2
68	@echo -- Simple compression tests
69	./simple_compression tmp
70	./simple_decompression tmp.zst
71	./multiple_simple_compression *.c
72	./streaming_decompression tmp.zst > /dev/null
73	@echo -- Streaming memory usage
74	./streaming_memory_usage
75	@echo -- Streaming compression tests
76	./streaming_compression tmp
77	./streaming_decompression tmp.zst > /dev/null
78	@echo -- Edge cases detection
79	! ./streaming_decompression tmp    # invalid input, must fail
80	! ./simple_decompression tmp       # invalid input, must fail
81	touch tmpNull                      # create 0-size file
82	./simple_compression tmpNull
83	./simple_decompression tmpNull.zst # 0-size frame : must work
84	@echo -- Multiple streaming tests
85	./multiple_streaming_compression *.c
86	@echo -- Dictionary compression tests
87	./dictionary_compression tmp2 tmp README.md
88	./dictionary_decompression tmp2.zst tmp.zst README.md
89	$(RM) tmp* *.zst
90	@echo tests completed
91