1# ################################################################ 2# Copyright (c) 2015-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 10# Version numbers 11LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h` 12LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h` 13LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h` 14LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 15LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 16LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 17LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 18LIBVER := $(shell echo $(LIBVER_SCRIPT)) 19VERSION?= $(LIBVER) 20CCVER := $(shell $(CC) --version) 21 22CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_ 23ifeq ($(OS),Windows_NT) # MinGW assumed 24CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting 25endif 26CFLAGS ?= -O3 27DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 28 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 29 -Wstrict-prototypes -Wundef -Wpointer-arith \ 30 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 31 -Wredundant-decls -Wmissing-prototypes -Wc++-compat 32CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 33FLAGS = $(CPPFLAGS) $(CFLAGS) 34 35HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0) 36GREP_OPTIONS ?= 37ifeq ($HAVE_COLORNEVER, 1) 38GREP_OPTIONS += --color=never 39endif 40GREP = grep $(GREP_OPTIONS) 41 42ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c)) 43ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c)) 44ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c)) 45ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c)) 46ZDEPR_FILES := $(sort $(wildcard deprecated/*.c)) 47ZSTD_FILES := $(ZSTDCOMMON_FILES) 48 49ifeq ($(findstring GCC,$(CCVER)),GCC) 50decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize 51endif 52 53ZSTD_LEGACY_SUPPORT ?= 5 54ZSTD_LIB_COMPRESSION ?= 1 55ZSTD_LIB_DECOMPRESSION ?= 1 56ZSTD_LIB_DICTBUILDER ?= 1 57ZSTD_LIB_DEPRECATED ?= 1 58HUF_FORCE_DECOMPRESS_X1 ?= 0 59HUF_FORCE_DECOMPRESS_X2 ?= 0 60ZSTD_FORCE_DECOMPRESS_SHORT ?= 0 61ZSTD_FORCE_DECOMPRESS_LONG ?= 0 62ZSTD_NO_INLINE ?= 0 63ZSTD_STRIP_ERROR_STRINGS ?= 0 64ZSTD_LEGACY_MULTITHREADED_API ?= 0 65 66ifeq ($(ZSTD_LIB_COMPRESSION), 0) 67 ZSTD_LIB_DICTBUILDER = 0 68 ZSTD_LIB_DEPRECATED = 0 69endif 70 71ifeq ($(ZSTD_LIB_DECOMPRESSION), 0) 72 ZSTD_LEGACY_SUPPORT = 0 73 ZSTD_LIB_DEPRECATED = 0 74endif 75 76ifneq ($(ZSTD_LIB_COMPRESSION), 0) 77 ZSTD_FILES += $(ZSTDCOMP_FILES) 78endif 79 80ifneq ($(ZSTD_LIB_DECOMPRESSION), 0) 81 ZSTD_FILES += $(ZSTDDECOMP_FILES) 82endif 83 84ifneq ($(ZSTD_LIB_DEPRECATED), 0) 85 ZSTD_FILES += $(ZDEPR_FILES) 86endif 87 88ifneq ($(ZSTD_LIB_DICTBUILDER), 0) 89 ZSTD_FILES += $(ZDICT_FILES) 90endif 91 92ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0) 93 CFLAGS += -DHUF_FORCE_DECOMPRESS_X1 94endif 95 96ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0) 97 CFLAGS += -DHUF_FORCE_DECOMPRESS_X2 98endif 99 100ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0) 101 CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT 102endif 103 104ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0) 105 CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG 106endif 107 108ifneq ($(ZSTD_NO_INLINE), 0) 109 CFLAGS += -DZSTD_NO_INLINE 110endif 111 112ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0) 113 CFLAGS += -DZSTD_STRIP_ERROR_STRINGS 114endif 115 116ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0) 117 CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API 118endif 119 120ifneq ($(ZSTD_LEGACY_SUPPORT), 0) 121ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) 122 ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]') 123endif 124 CPPFLAGS += -I./legacy 125endif 126CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 127 128ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES)) 129 130# macOS linker doesn't support -soname, and use different extension 131# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 132ifeq ($(shell uname), Darwin) 133 SHARED_EXT = dylib 134 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 135 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 136 SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 137else 138 SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR) 139 SHARED_EXT = so 140 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 141 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 142endif 143 144 145.PHONY: default all clean install uninstall 146 147default: lib-release 148 149all: lib 150 151libzstd.a: ARFLAGS = rcs 152libzstd.a: $(ZSTD_OBJ) 153 @echo compiling static library 154 @$(AR) $(ARFLAGS) $@ $^ 155 156libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD 157libzstd.a-mt: libzstd.a 158 159ifneq (,$(filter Windows%,$(OS))) 160 161LIBZSTD = dll\libzstd.dll 162$(LIBZSTD): $(ZSTD_FILES) 163 @echo compiling dynamic library $(LIBVER) 164 $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.lib -shared $^ -o $@ 165 166else 167 168LIBZSTD = libzstd.$(SHARED_EXT_VER) 169$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden 170$(LIBZSTD): $(ZSTD_FILES) 171 @echo compiling dynamic library $(LIBVER) 172 @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ 173 @echo creating versioned links 174 @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR) 175 @ln -sf $@ libzstd.$(SHARED_EXT) 176 177endif 178 179 180libzstd : $(LIBZSTD) 181 182libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD 183libzstd-mt : libzstd 184 185lib: libzstd.a libzstd 186 187lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD 188lib-mt: lib 189 190lib-release lib-release-mt: DEBUGFLAGS := 191lib-release: lib 192lib-release-mt: lib-mt 193 194# Special case : building library in single-thread mode _and_ without zstdmt_compress.c 195ZSTDMT_FILES = compress/zstdmt_compress.c 196ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES)) 197libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden 198libzstd-nomt: $(ZSTD_NOMT_FILES) 199 @echo compiling single-thread dynamic library $(LIBVER) 200 @echo files : $(ZSTD_NOMT_FILES) 201 @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ 202 203clean: 204 @$(RM) -r *.dSYM # macOS-specific 205 @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc 206 @$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt* 207 @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o 208 @echo Cleaning library completed 209 210#----------------------------------------------------------------------------- 211# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets 212#----------------------------------------------------------------------------- 213ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku)) 214 215DESTDIR ?= 216# directory variables : GNU conventions prefer lowercase 217# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 218# support both lower and uppercase (BSD), use uppercase in script 219prefix ?= /usr/local 220PREFIX ?= $(prefix) 221exec_prefix ?= $(PREFIX) 222libdir ?= $(exec_prefix)/lib 223LIBDIR ?= $(libdir) 224includedir ?= $(PREFIX)/include 225INCLUDEDIR ?= $(includedir) 226 227ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly)) 228PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig 229else 230PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig 231endif 232 233ifneq (,$(filter $(shell uname),SunOS)) 234INSTALL ?= ginstall 235else 236INSTALL ?= install 237endif 238 239INSTALL_PROGRAM ?= $(INSTALL) 240INSTALL_DATA ?= $(INSTALL) -m 644 241 242 243libzstd.pc: 244libzstd.pc: libzstd.pc.in 245 @echo creating pkgconfig 246 @sed -e 's|@PREFIX@|$(PREFIX)|' \ 247 -e 's|@VERSION@|$(VERSION)|' \ 248 $< >$@ 249 250install: install-pc install-static install-shared install-includes 251 @echo zstd static and shared library installed 252 253install-pc: libzstd.pc 254 @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ 255 @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/ 256 257install-static: libzstd.a 258 @echo Installing static library 259 @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/ 260 @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR) 261 262install-shared: libzstd 263 @echo Installing shared library 264 @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/ 265 @$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR) 266 @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) 267 @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT) 268 269install-includes: 270 @echo Installing includes 271 @$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/ 272 @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR) 273 @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR) 274 @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings 275 @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR) 276 277uninstall: 278 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a 279 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT) 280 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) 281 @$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD) 282 @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc 283 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h 284 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h 285 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions 286 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h 287 @echo zstd libraries successfully uninstalled 288 289endif 290