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) 20 21CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_ 22CFLAGS ?= -O3 23DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 24 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ 25 -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \ 26 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \ 27 -Wredundant-decls 28CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 29FLAGS = $(CPPFLAGS) $(CFLAGS) 30 31 32ZSTD_FILES := $(sort $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)) 33 34ZSTD_LEGACY_SUPPORT ?= 4 35 36ifneq ($(ZSTD_LEGACY_SUPPORT), 0) 37ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) 38 ZSTD_FILES += $(shell ls legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]') 39endif 40 CPPFLAGS += -I./legacy 41endif 42CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) 43 44ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES)) 45 46# OS X linker doesn't support -soname, and use different extension 47# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 48ifeq ($(shell uname), Darwin) 49 SHARED_EXT = dylib 50 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 51 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 52 SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 53else 54 SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR) 55 SHARED_EXT = so 56 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 57 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 58endif 59 60LIBZSTD = libzstd.$(SHARED_EXT_VER) 61 62 63.PHONY: default all clean install uninstall 64 65default: lib-release 66 67all: lib 68 69libzstd.a: ARFLAGS = rcs 70libzstd.a: $(ZSTD_OBJ) 71 @echo compiling static library 72 @$(AR) $(ARFLAGS) $@ $^ 73 74libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD 75libzstd.a-mt: libzstd.a 76 77$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden 78$(LIBZSTD): $(ZSTD_FILES) 79 @echo compiling dynamic library $(LIBVER) 80ifneq (,$(filter Windows%,$(OS))) 81 @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll 82 dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib 83else 84 @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ 85 @echo creating versioned links 86 @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR) 87 @ln -sf $@ libzstd.$(SHARED_EXT) 88endif 89 90libzstd : $(LIBZSTD) 91 92libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD 93libzstd-mt : libzstd 94 95lib: libzstd.a libzstd 96 97lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD 98lib-mt: lib 99 100lib-release lib-release-mt: DEBUGFLAGS := 101lib-release: lib 102lib-release-mt: lib-mt 103 104# Special case : building library in single-thread mode _and_ without zstdmt_compress.c 105ZSTDMT_FILES = compress/zstdmt_compress.c 106ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES)) 107libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden 108libzstd-nomt: $(ZSTD_NOMT_FILES) 109 @echo compiling single-thread dynamic library $(LIBVER) 110 @echo files : $(ZSTD_NOMT_FILES) 111 @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@ 112 113clean: 114 @$(RM) -r *.dSYM # Mac OS-X specific 115 @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc 116 @$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt* 117 @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o 118 @echo Cleaning library completed 119 120#----------------------------------------------------------------------------- 121# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 122#----------------------------------------------------------------------------- 123ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 124 125DESTDIR ?= 126# directory variables : GNU conventions prefer lowercase 127# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 128# support both lower and uppercase (BSD), use uppercase in script 129prefix ?= /usr/local 130PREFIX ?= $(prefix) 131exec_prefix ?= $(PREFIX) 132libdir ?= $(exec_prefix)/lib 133LIBDIR ?= $(libdir) 134includedir ?= $(PREFIX)/include 135INCLUDEDIR ?= $(includedir) 136 137ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly)) 138PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig 139else 140PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig 141endif 142 143ifneq (,$(filter $(shell uname),SunOS)) 144INSTALL ?= ginstall 145else 146INSTALL ?= install 147endif 148 149INSTALL_PROGRAM ?= $(INSTALL) 150INSTALL_DATA ?= $(INSTALL) -m 644 151 152 153libzstd.pc: 154libzstd.pc: libzstd.pc.in 155 @echo creating pkgconfig 156 @sed -e 's|@PREFIX@|$(PREFIX)|' \ 157 -e 's|@LIBDIR@|$(LIBDIR)|' \ 158 -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ 159 -e 's|@VERSION@|$(VERSION)|' \ 160 $< >$@ 161 162install: libzstd.a libzstd libzstd.pc 163 @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/ 164 @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/ 165 @echo Installing libraries 166 @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR) 167 @$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR) 168 @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) 169 @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT) 170 @echo Installing includes 171 @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR) 172 @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR) 173 @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings 174 @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR) 175 @echo zstd static and shared library installed 176 177uninstall: 178 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a 179 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT) 180 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) 181 @$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD) 182 @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc 183 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h 184 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h 185 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions 186 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h 187 @echo zstd libraries successfully uninstalled 188 189endif 190