1*0c16b537SWarner Losh# ################################################################
2*0c16b537SWarner Losh# Copyright (c) Yann Collet, Facebook, Inc.
3*0c16b537SWarner Losh# All rights reserved.
4*0c16b537SWarner Losh#
5*0c16b537SWarner Losh# This source code is licensed under both the BSD-style license (found in the
6*0c16b537SWarner Losh# LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*0c16b537SWarner Losh# in the COPYING file in the root directory of this source tree).
8*0c16b537SWarner Losh# You may select, at your option, one of the above-listed licenses.
9*0c16b537SWarner Losh# ################################################################
10*0c16b537SWarner Losh
11*0c16b537SWarner LoshZSTD ?= zstd   # note: requires zstd installation on local system
12*0c16b537SWarner Losh
13*0c16b537SWarner LoshUNAME?= $(shell uname)
14*0c16b537SWarner Loshifeq ($(UNAME), SunOS)
15*0c16b537SWarner LoshDIFF ?= gdiff
16*0c16b537SWarner Loshelse
17*0c16b537SWarner LoshDIFF ?= diff
18*0c16b537SWarner Loshendif
19*0c16b537SWarner Losh
20*0c16b537SWarner LoshHARNESS_FILES=*.c
21*0c16b537SWarner Losh
22*0c16b537SWarner LoshMULTITHREAD_LDFLAGS = -pthread
23*0c16b537SWarner LoshDEBUGFLAGS= -g -DZSTD_DEBUG=1
24*0c16b537SWarner LoshCPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
25*0c16b537SWarner Losh            -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
26*0c16b537SWarner LoshCFLAGS   ?= -O2
27*0c16b537SWarner LoshCFLAGS   += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow                 \
28*0c16b537SWarner Losh            -Wstrict-aliasing=1 -Wswitch-enum                               \
29*0c16b537SWarner Losh            -Wredundant-decls -Wstrict-prototypes -Wundef                   \
30*0c16b537SWarner Losh            -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings      \
31*0c16b537SWarner Losh            -std=c99
32*0c16b537SWarner LoshCFLAGS   += $(DEBUGFLAGS)
33*0c16b537SWarner LoshCFLAGS   += $(MOREFLAGS)
34*0c16b537SWarner LoshFLAGS     = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MULTITHREAD_LDFLAGS)
35
36harness: $(HARNESS_FILES)
37	$(CC) $(FLAGS) $^ -o $@
38
39clean:
40	@$(RM) harness *.o
41	@$(RM) -rf harness.dSYM  # MacOS specific
42
43test: harness
44	#
45	# Testing single-file decompression with educational decoder
46	#
47	@$(ZSTD) -f README.md -o tmp.zst
48	@./harness tmp.zst tmp
49	@$(DIFF) -s tmp README.md
50	@$(RM) tmp*
51	#
52	# Testing dictionary decompression with education decoder
53	#
54	# note : files are presented multiple for training, to reach minimum threshold
55	@$(ZSTD) --train harness.c zstd_decompress.c zstd_decompress.h README.md \
56                  harness.c zstd_decompress.c zstd_decompress.h README.md \
57                  harness.c zstd_decompress.c zstd_decompress.h README.md \
58                  -o dictionary
59	@$(ZSTD) -f README.md -D dictionary -o tmp.zst
60	@./harness tmp.zst tmp dictionary
61	@$(DIFF) -s tmp README.md
62	@$(RM) tmp* dictionary
63