1
2ZSTDDIR = ../../lib
3PRGDIR  = ../../programs
4ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
5ZSTDCOMP_FILES   := $(ZSTDDIR)/compress/*.c
6ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
7ZSTD_FILES  := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
8
9MULTITHREAD_LDFLAGS = -pthread
10DEBUGFLAGS= -g -DZSTD_DEBUG=1
11CPPFLAGS += -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
12            -I$(ZSTDDIR)/dictBuilder -I$(ZSTDDIR)/deprecated -I$(PRGDIR)
13CFLAGS   ?= -O3
14CFLAGS   += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow                 \
15            -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
16            -Wstrict-prototypes -Wundef                                     \
17            -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings      \
18            -Wredundant-decls
19CFLAGS   += $(DEBUGFLAGS)
20CFLAGS   += $(MOREFLAGS)
21FLAGS     = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MULTITHREAD_LDFLAGS)
22
23all: adapt datagen
24
25adapt: $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c adapt.c
26	$(CC) $(FLAGS) $^ -o $@
27
28adapt-debug: $(ZSTD_FILES) $(PRGDIR)/util.c $(PRGDIR)/timefn.c adapt.c
29	$(CC) $(FLAGS) -DDEBUG_MODE=2 $^ -o adapt
30
31datagen : $(PRGDIR)/datagen.c datagencli.c
32	$(CC)      $(FLAGS) $^ -o $@
33
34test-adapt-correctness: datagen adapt
35	@./test-correctness.sh
36	@echo "test correctness complete"
37
38test-adapt-performance: datagen adapt
39	@./test-performance.sh
40	@echo "test performance complete"
41
42clean:
43	@$(RM) -f adapt datagen
44	@$(RM) -rf *.dSYM
45	@$(RM) -f tmp*
46	@$(RM) -f tests/*.zst
47	@$(RM) -f tests/tmp*
48	@echo "finished cleaning"
49
50#-----------------------------------------------------------------------------
51# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
52#-----------------------------------------------------------------------------
53ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
54
55ifneq (,$(filter $(shell uname),SunOS))
56INSTALL ?= ginstall
57else
58INSTALL ?= install
59endif
60
61PREFIX  ?= /usr/local
62DESTDIR ?=
63BINDIR  ?= $(PREFIX)/bin
64
65INSTALL_PROGRAM ?= $(INSTALL) -m 755
66
67install: adapt
68	@echo Installing binaries
69	@$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/
70	@$(INSTALL_PROGRAM) adapt $(DESTDIR)$(BINDIR)/zstd-adaptive
71	@echo zstd-adaptive installation completed
72
73uninstall:
74	@$(RM) $(DESTDIR)$(BINDIR)/zstd-adaptive
75	@echo zstd-adaptive programs successfully uninstalled
76endif
77