1 # ##########################################################################
2 # Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
5 # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
7 # This source code is licensed under the BSD-style license found in the
8 # LICENSE file in the root directory of this source tree. An additional grant
9 # of patent rights can be found in the PATENTS file in the same directory.
10 # ##########################################################################
11 # zstd : Command Line Utility, supporting gzip-like arguments
12 # zstd32 : Same as zstd, but forced to compile in 32-bits mode
13 # zstd_nolegacy : zstd without support of decompression of legacy versions
14 # zstd-small : minimal zstd without dictionary builder and benchmark
15 # zstd-compress : compressor-only version of zstd
16 # zstd-decompress : decompressor-only version of zstd
17 # ##########################################################################
21 ifeq ($(shell $(CC) -v 2>&1 | grep -c "gcc version "), 1)
22 ALIGN_LOOP = -falign-loops=32
27 CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \
28 -I$(ZSTDDIR)/dictBuilder \
29 -DXXH_NAMESPACE=ZSTD_ # because xxhash.o already compiled with this macro from library
31 DEBUGFLAGS = -g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
32 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
33 -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security
34 CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
35 FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
38 ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
39 ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c
40 ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
41 ZSTD_FILES := $(ZSTDDECOMP_FILES) $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES)
42 ZDICT_FILES := $(ZSTDDIR)/dictBuilder/*.c
43 ZSTDDECOMP_O = $(ZSTDDIR)/decompress/zstd_decompress.o
45 ZSTD_LEGACY_SUPPORT ?= 4
47 ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
48 ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
49 ZSTDLEGACY_FILES += $(shell ls $(ZSTDDIR)/legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
51 CPPFLAGS += -I$(ZSTDDIR)/legacy
55 ZSTDLIB_FILES := $(wildcard $(ZSTD_FILES)) $(wildcard $(ZSTDLEGACY_FILES)) $(wildcard $(ZDICT_FILES))
56 ZSTDLIB_OBJ := $(patsubst %.c,%.o,$(ZSTDLIB_FILES))
58 # Define *.exe as extension for Windows systems
59 ifneq (,$(filter Windows%,$(OS)))
61 RES64_FILE = windres/zstd64.res
62 RES32_FILE = windres/zstd32.res
63 ifneq (,$(filter x86_64%,$(shell $(CC) -dumpmachine)))
64 RES_FILE = $(RES64_FILE)
66 RES_FILE = $(RES32_FILE)
73 NO_ZLIB_MSG := ==> no zlib, building zstd without .gz support
75 HAVE_ZLIB := $(shell printf '\#include <zlib.h>\nint main(){}' | $(CC) -o have_zlib -x c - -lz 2> $(VOID) && rm have_zlib$(EXT) && echo 1 || echo 0)
76 ifeq ($(HAVE_ZLIB), 1)
77 ZLIB_MSG := ==> building zstd with .gz compression support
78 ZLIBCPP = -DZSTD_GZCOMPRESS -DZSTD_GZDECOMPRESS
81 ZLIB_MSG := $(NO_ZLIB_MSG)
84 NO_LZMA_MSG := ==> no liblzma, building zstd without .xz/.lzma support
85 HAVE_LZMA := $(shell printf '\#include <lzma.h>\nint main(){}' | $(CC) -o have_lzma -x c - -llzma 2> $(VOID) && rm have_lzma$(EXT) && echo 1 || echo 0)
86 ifeq ($(HAVE_LZMA), 1)
87 LZMA_MSG := ==> building zstd with .xz/.lzma compression support
88 LZMACPP = -DZSTD_LZMACOMPRESS -DZSTD_LZMADECOMPRESS
91 LZMA_MSG := $(NO_LZMA_MSG)
95 .PHONY: default all clean clean_decomp_o install uninstall generate_res
101 $(ZSTDDECOMP_O): CFLAGS += $(ALIGN_LOOP)
103 zstd : CPPFLAGS += $(ZLIBCPP)
104 zstd : LDFLAGS += $(ZLIBLD)
105 zstd : LZMA_MSG := $(NO_LZMA_MSG)
106 zstd-nogz : ZLIB_MSG := $(NO_ZLIB_MSG)
107 zstd-nogz : LZMA_MSG := $(NO_LZMA_MSG)
108 xzstd : CPPFLAGS += $(ZLIBCPP) $(LZMACPP)
109 xzstd : LDFLAGS += $(ZLIBLD) $(LZMALD)
110 zstd zstd-nogz xzstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
111 zstd zstd-nogz xzstd : $(ZSTDLIB_OBJ) zstdcli.o fileio.o bench.o datagen.o dibio.o
114 ifneq (,$(filter Windows%,$(OS)))
115 windres/generate_res.bat
117 $(CC) $(FLAGS) $^ $(RES_FILE) -o zstd$(EXT) $(LDFLAGS)
119 zstd-release: DEBUGFLAGS :=
122 zstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
123 zstd32 : $(ZSTDLIB_FILES) zstdcli.c fileio.c bench.c datagen.c dibio.c
124 ifneq (,$(filter Windows%,$(OS)))
125 windres/generate_res.bat
127 $(CC) -m32 $(FLAGS) $^ $(RES32_FILE) -o $@$(EXT)
130 zstd-nolegacy : clean_decomp_o
131 $(MAKE) zstd ZSTD_LEGACY_SUPPORT=0
133 zstd-pgo : MOREFLAGS = -fprofile-generate
134 zstd-pgo : clean zstd
135 ./zstd -b19i1 $(PROFILE_WITH)
136 ./zstd -b16i1 $(PROFILE_WITH)
137 ./zstd -b9i2 $(PROFILE_WITH)
138 ./zstd -b $(PROFILE_WITH)
139 ./zstd -b7i2 $(PROFILE_WITH)
140 ./zstd -b5 $(PROFILE_WITH)
142 $(RM) $(ZSTDDECOMP_O)
143 $(MAKE) zstd MOREFLAGS=-fprofile-use
145 zstd-frugal: $(ZSTD_FILES) zstdcli.c fileio.c
146 $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT $^ -o zstd$(EXT)
149 CFLAGS="-Os -s" $(MAKE) zstd-frugal
151 zstd-decompress: $(ZSTDCOMMON_FILES) $(ZSTDDECOMP_FILES) zstdcli.c fileio.c
152 $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS $^ -o $@$(EXT)
154 zstd-compress: $(ZSTDCOMMON_FILES) $(ZSTDCOMP_FILES) zstdcli.c fileio.c
155 $(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS $^ -o $@$(EXT)
157 zstdmt: CPPFLAGS += -DZSTD_MULTITHREAD
158 ifeq (,$(filter Windows%,$(OS)))
159 zstdmt: LDFLAGS += -lpthread
164 windres/generate_res.bat
167 $(MAKE) -C $(ZSTDDIR) clean
168 @$(RM) $(ZSTDDIR)/decompress/*.o $(ZSTDDIR)/decompress/zstd_decompress.gcda
169 @$(RM) core *.o tmp* result* *.gcda dictionary *.zst \
170 zstd$(EXT) zstd32$(EXT) zstd-compress$(EXT) zstd-decompress$(EXT) \
171 *.gcda default.profraw have_zlib$(EXT)
172 @echo Cleaning completed
175 @$(RM) $(ZSTDDECOMP_O)
178 #-----------------------------------------------------------------------------
179 # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
180 #-----------------------------------------------------------------------------
181 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
183 ifneq (,$(filter $(shell uname),SunOS))
191 BINDIR ?= $(PREFIX)/bin
193 ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS))
194 MANDIR ?= $(PREFIX)/man/man1
196 MANDIR ?= $(PREFIX)/share/man/man1
199 INSTALL_PROGRAM ?= $(INSTALL) -m 755
200 INSTALL_SCRIPT ?= $(INSTALL) -m 755
201 INSTALL_MAN ?= $(INSTALL) -m 644
204 @echo Installing binaries
205 @$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
206 @$(INSTALL_PROGRAM) zstd $(DESTDIR)$(BINDIR)/zstd
207 @ln -sf zstd $(DESTDIR)$(BINDIR)/zstdcat
208 @ln -sf zstd $(DESTDIR)$(BINDIR)/unzstd
209 @$(INSTALL_SCRIPT) zstdless $(DESTDIR)$(BINDIR)/zstdless
210 @$(INSTALL_SCRIPT) zstdgrep $(DESTDIR)$(BINDIR)/zstdgrep
211 @echo Installing man pages
212 @$(INSTALL_MAN) zstd.1 $(DESTDIR)$(MANDIR)/zstd.1
213 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/zstdcat.1
214 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/unzstd.1
215 @echo zstd installation completed
218 @$(RM) $(DESTDIR)$(BINDIR)/zstdgrep
219 @$(RM) $(DESTDIR)$(BINDIR)/zstdless
220 @$(RM) $(DESTDIR)$(BINDIR)/zstdcat
221 @$(RM) $(DESTDIR)$(BINDIR)/unzstd
222 @$(RM) $(DESTDIR)$(BINDIR)/zstd
223 @$(RM) $(DESTDIR)$(MANDIR)/zstdcat.1
224 @$(RM) $(DESTDIR)$(MANDIR)/unzstd.1
225 @$(RM) $(DESTDIR)$(MANDIR)/zstd.1
226 @echo zstd programs successfully uninstalled