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
10ZSTD ?= zstd   # note: requires zstd installation on local system
11
12UNAME?= $(shell uname)
13ifeq ($(UNAME), SunOS)
14DIFF ?= gdiff
15else
16DIFF ?= diff
17endif
18
19HARNESS_FILES=*.c
20
21MULTITHREAD_LDFLAGS = -pthread
22DEBUGFLAGS= -g -DZSTD_DEBUG=1
23CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
24            -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
25CFLAGS   ?= -O2
26CFLAGS   += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow                 \
27            -Wstrict-aliasing=1 -Wswitch-enum                               \
28            -Wredundant-decls -Wstrict-prototypes -Wundef                   \
29            -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings      \
30            -std=c99
31CFLAGS   += $(DEBUGFLAGS)
32CFLAGS   += $(MOREFLAGS)
33FLAGS     = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MULTITHREAD_LDFLAGS)
34
35harness: $(HARNESS_FILES)
36	$(CC) $(FLAGS) $^ -o $@
37
38clean:
39	@$(RM) harness
40	@$(RM) -rf harness.dSYM  # MacOS specific
41
42test: harness
43	#
44	# Testing single-file decompression with educational decoder
45	#
46	@$(ZSTD) -f README.md -o tmp.zst
47	@./harness tmp.zst tmp
48	@$(DIFF) -s tmp README.md
49	@$(RM) tmp*
50	#
51	# Testing dictionary decompression with education decoder
52	#
53	# note : files are presented multiple for training, to reach minimum threshold
54	@$(ZSTD) --train harness.c zstd_decompress.c zstd_decompress.h README.md \
55                  harness.c zstd_decompress.c zstd_decompress.h README.md \
56                  harness.c zstd_decompress.c zstd_decompress.h README.md \
57                  -o dictionary
58	@$(ZSTD) -f README.md -D dictionary -o tmp.zst
59	@./harness tmp.zst tmp dictionary
60	@$(DIFF) -s tmp README.md
61	@$(RM) tmp* dictionary
62	@$(MAKE) clean
63