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